Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tarilabs/demo20220715contextlabel


https://github.com/tarilabs/demo20220715contextlabel

Last synced: 2 days ago
JSON representation

Awesome Lists containing this project

README

        

# demo20220715contextlabel Project

Technologies used in this demo: [Drools](https://www.drools.org/learn/video.html), [YaRD](https://github.com/kiegroup/yard/), [Kogito](https://kogito.kie.org/), [Quarkus](https://quarkus.io/), [cloudevents](https://cloudevents.io/), Apache Kafka, PostgreSQL, [hibernate-types](https://github.com/vladmihalcea/hibernate-types#readme), [quarkus-quinoa](https://quarkiverse.github.io/quarkiverse-docs/quarkus-quinoa/dev/), [PatternFly](https://www.patternfly.org/v4/).

Goals:
- Demo a Classification of cloudevent generic context based on YaRD rule definition with ad-hoc indexed searching of association of _hierarchical_ labels via PostgreSQL's `ltree` for any given context

Non goals:
- Full complete architectural solution; for example, wired Kafka as demonstrator
- Fully implemented GUI (focusing on backend, and for the frontend [chabuduo](https://youtube.com/clip/UgkxeVe0fr81gBBZXzQ1LG2189Z1QrYspmXt) MVP working-PoC 🚀)

## Requirements

- openjdk 17
- Apache Maven 3.8.6
- Docker (for PostgreSQL and Kafka, Quarkus Dev Services)
- NodeJS v18.6.0
- place [draft GUI](https://github.com/tarilabs/demo20220715contextlabel-ui) as a sibling directory for Quarkus' Quinoa `quarkus:dev`

## Overview

A cloudevent is submitted to this application, for example:

```json
{
"specversion": "1.0",
"id": "matteo-8eb9-43b2-9313-22133f2c747a",
"source": "example",
"type": "demo20220715contextlabel.demotype",
"data": {
"host": "basedidati.milano.local",
"diskPerc": 70,
"memPerc": 50,
"cpuPerc": 20
}
}
```

For once a demo not involving Loan or Insurances ;) The data context of the cloud event pertains to some host which came under supervision due to resource load.
We now want to classify this context/case, using some labels.
We may have more than 1 label.
Each label is hierarchical (`root.branch1.branch2.leaf`).

Ultimately, we might want to setup a labeling rule for who's on call, something ~like a Kie Drools YaRD rule definition of a decision table:

```yaml
type: DecisionTable
inputs: ['.location', '.type']
rules:
- when: ['startswith("location.emea")', '. == "type.db"']
then: '"oncall.EMEA.dbadm"'
- when: ['startswith("location.emea") | not', '. == "type.db"']
then: '"oncall.CORP.dbadm"'
- when: ['true', '. == "type.nas"']
then: '"oncall.CORP.it"'
```

For example, a cloudevent context may be labeled as follows:
- `type.db`
- `location.emea.italy.milan`
- `oncall.EMEA.dbadm`

For the PostgreSQL DDL we currently have:
```
Table "public.cecase"
Column | Type | Collation | Nullable | Default
---------+------------------------+-----------+----------+---------
id | bigint | | not null |
ceuuid | character varying(255) | | |
context | jsonb | | |
mytag | ltree[] | | |
Indexes:
"cecase_pkey" PRIMARY KEY, btree (id)
"mytag_gist_idx" gist (mytag)
"mytag_idx" btree (mytag)
```

Please notice taking advantage of PostgreSQL's `jsonb` for storing the original cloudevent context, and `ltree[]` for searching ad-hoc indexed the hiearachical labels.

This is extremely helpful to setup queries making use of `<@` and `~` operator for PostgreSQL which performs on `ltree`, showcased below.

As the data flows to the application, we can use this provisional GUI which uses the backend REST API(s) made on Quarkus:

![](screenshot.listall.png)

In the screenshot above, you can access all the records from the table, where the labels have been applied by the rule definition.

We can browse by, having at least one label having the specified parent with a query like
```sql
SELECT * FROM cecase WHERE mytag <@ 'oncall.CORP'
```

for example if we want all the records having at least a label for the `oncall.CORP` rooting:

![](screenshot.searchparent.png)

We can browse by, having at least one label having the specified `ltree` query like
```sql
SELECT * FROM cecase WHERE mytag ~ `*.emea.*`
```

for example if we want all the records having at least a label for the `*.emea.*` (a branch named `emea` in any point in the hieararchical label):

![](screenshot.searchmatching.png)

## dev notes

```
docker ps
docker exec -it sh
psql -U hibernate default
\d
```

```
default=# SELECT * FROM cecase WHERE mytag ~ '*.eu.*';
id | ceuuid | context | mytag
----+--------+----------------------------+-----------------------------------
1 | test1 | {"host": "milan.archivio"} | {location.eu.italy.milan,type.db}
(1 row)

default=# SELECT * FROM cecase WHERE mytag <@ 'location.eu';
id | ceuuid | context | mytag
----+--------+----------------------------+-----------------------------------
1 | test1 | {"host": "milan.archivio"} | {location.eu.italy.milan,type.db}
(1 row)
```