Skip to content

Commit fe8c596

Browse files
authored
Merge pull request #2 from opsdis/batch_endpoints
Graph endpoints
2 parents 54fe095 + 0dd2d01 commit fe8c596

6 files changed

Lines changed: 380 additions & 274 deletions

File tree

README.md

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ The schema defines the different fields and the type, string or number, that are
8080

8181
# API endpoints
8282

83+
All endpoint expects the header "Content-Type" set to "application/json"
84+
8385
## Data source API
8486

8587
GET /{graph_schema}/api/graph/data
@@ -98,10 +100,6 @@ The schema defines the different fields and the type, string or number, that are
98100
GET /api/edges/{graph_schema}/{source_id}/{target_id}
99101
PUT /api/edges/{graph_schema}/{source_id}/{target_id}
100102
DELETE /api/edges/{graph_schema}/{source_id}/{target_id}
101-
102-
POST /api/controller/{graph_schema}/delete-all
103-
104-
All endpoint expects the header "Content-Type" set to "application/json"
105103

106104
POST operations expect a json body. The content should only include the field names in the graph schema.
107105

@@ -129,8 +127,56 @@ DELETE and GET do not have any query parameters.
129127
curl -s -i -H "Content-Type: application/json" -X PUT "localhost:9393/api/nodes/micro/lb-01?arc__failed=0.1?arc__passed=0.9"
130128
```
131129

130+
## Manage a complete graph
131+
The api endpoints will operate on a complete graph. The POST will first
132+
delete before create. For a client that have the full "picture" of the graph
133+
model, this is the most effective endpoint to use.
134+
135+
POST /api/graph/{graph_schema}
136+
DELETE /api/graph/{graph_schema}
132137

133-
### Return status
138+
The POST endpoint requiere a body of a list of nodes and edges, e.g.
139+
```json
140+
{
141+
"nodes": [
142+
{
143+
"id": "lb-1",
144+
"title": "lb",
145+
"subTitle": "instance:#01",
146+
"detail__role": "load",
147+
"arc__failed": 0,
148+
"arc__passed": 1,
149+
"mainStat": 0,
150+
"secondaryStat": 0
151+
},
152+
....
153+
154+
],
155+
"edges": [
156+
{
157+
"source": "lb-1",
158+
"target": "cust-svc-1",
159+
"mainStat": 0,
160+
"secondaryStat": 0
161+
},
162+
....
163+
]
164+
}
165+
```
166+
167+
Please see the `examples/graph.json` and `examples/setup_graph.sh` for a
168+
complete example.
169+
170+
## Deprecated API
171+
The following api are deprecated:
172+
173+
POST /api/controller/{graph_schema}/delete-all
174+
175+
176+
177+
178+
179+
## Return status
134180

135181
- 200
136182
- Successful - PUT, DELETE, GET
@@ -172,9 +218,13 @@ Name it to `Micro`.
172218

173219
Create a dashboard and select the "Node Graph" plugin. Select the data source `Micro`.
174220

175-
Load the simple graph model
221+
Load the simple graph model by create nodes and edges:
176222

177223
./examples/setup_test.sh
224+
225+
Or run the example to create a complete graph:
226+
227+
./examples/setup_graph.sh
178228

179229
In Grafana you should now see this.
180230
![Initial Graph](docs/graph_1.png?raw=true "Start graph")

examples/graph.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"nodes": [
3+
{
4+
"id": "lb-1",
5+
"title": "lb",
6+
"subTitle": "instance:#01",
7+
"detail__role": "load",
8+
"arc__failed": 0,
9+
"arc__passed": 1,
10+
"mainStat": 0,
11+
"secondaryStat": 0
12+
},
13+
{
14+
"id": "cust-svc-1",
15+
"title": "cust-svc-1",
16+
"subTitle": "instance:#01",
17+
"detail__role": "load",
18+
"arc__failed": 0,
19+
"arc__passed": 1,
20+
"mainStat": 0,
21+
"secondaryStat": 0
22+
},
23+
{
24+
"id": "cust-svc-2",
25+
"title": "cust-svc-2",
26+
"subTitle": "instance:#02",
27+
"detail__role": "load",
28+
"arc__failed": 0,
29+
"arc__passed": 1,
30+
"mainStat": 0,
31+
"secondaryStat": 0
32+
},
33+
{
34+
"id": "pay-svc-1",
35+
"title": "pay-svc-1",
36+
"subTitle": "instance:#01",
37+
"detail__role": "load",
38+
"arc__failed": 0,
39+
"arc__passed": 1,
40+
"mainStat": 0,
41+
"secondaryStat": 0
42+
},
43+
{
44+
"id": "book-svc-1",
45+
"title": "book-svc-1",
46+
"subTitle": "instance:#01",
47+
"detail__role": "load",
48+
"arc__failed": 0,
49+
"arc__passed": 1,
50+
"mainStat": 0,
51+
"secondaryStat": 0
52+
}
53+
],
54+
"edges": [
55+
{
56+
"source": "lb-1",
57+
"target": "cust-svc-1",
58+
"mainStat": 0,
59+
"secondaryStat": 0
60+
},
61+
{
62+
"source": "lb-1",
63+
"target": "cust-svc-2",
64+
"mainStat": 0,
65+
"secondaryStat": 0
66+
},
67+
{
68+
"source": "cust-svc-1",
69+
"target": "pay-svc-1",
70+
"mainStat": 0,
71+
"secondaryStat": 0
72+
},
73+
{
74+
"source": "cust-svc-1",
75+
"target": "book-svc-1",
76+
"mainStat": 0,
77+
"secondaryStat": 0
78+
},
79+
{
80+
"source": "cust-svc-2",
81+
"target": "pay-svc-1",
82+
"mainStat": 0,
83+
"secondaryStat": 0
84+
},
85+
{
86+
"source": "cust-svc-2",
87+
"target": "book-svc-1",
88+
"mainStat": 0,
89+
"secondaryStat": 0
90+
},
91+
{
92+
"source": "pay-svc-1",
93+
"target": "book-svc-1",
94+
"mainStat": 0,
95+
"secondaryStat": 0
96+
}
97+
]
98+
}

examples/setup_graph.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
URL_BATCH="http://localhost:9393/api/graph/micro"
2+
HEADER="Content-Type: application/json"
3+
# Create nodes
4+
curl -s -i -H $HEADER -X POST $URL_BATCH -d @examples/graph.json

go.mod

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
module github.com/opsdis/nodegraph-provider
22

3-
go 1.14
3+
go 1.18
44

55
require (
66
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f
77
github.com/gomodule/redigo v1.8.8
88
github.com/gorilla/mux v1.8.0
9-
github.com/mattn/go-runewidth v0.0.13 // indirect
109
github.com/mitchellh/mapstructure v1.4.3
11-
github.com/olekukonko/tablewriter v0.0.5 // indirect
1210
github.com/prometheus/client_golang v1.12.1
1311
github.com/prometheus/common v0.32.1
1412
github.com/redislabs/redisgraph-go v2.0.2+incompatible
1513
github.com/segmentio/ksuid v1.0.4
1614
github.com/sirupsen/logrus v1.8.1
17-
github.com/spf13/afero v1.8.0 // indirect
1815
github.com/spf13/viper v1.10.1
16+
)
17+
18+
require (
19+
github.com/beorn7/perks v1.0.1 // indirect
20+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
21+
github.com/fsnotify/fsnotify v1.5.1 // indirect
22+
github.com/golang/protobuf v1.5.2 // indirect
23+
github.com/hashicorp/hcl v1.0.0 // indirect
24+
github.com/json-iterator/go v1.1.12 // indirect
25+
github.com/magiconair/properties v1.8.5 // indirect
26+
github.com/mattn/go-runewidth v0.0.13 // indirect
27+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
28+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
29+
github.com/modern-go/reflect2 v1.0.2 // indirect
30+
github.com/olekukonko/tablewriter v0.0.5 // indirect
31+
github.com/pelletier/go-toml v1.9.4 // indirect
32+
github.com/prometheus/client_model v0.2.0 // indirect
33+
github.com/prometheus/procfs v0.7.3 // indirect
34+
github.com/rivo/uniseg v0.2.0 // indirect
35+
github.com/spf13/afero v1.8.0 // indirect
36+
github.com/spf13/cast v1.4.1 // indirect
37+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
38+
github.com/spf13/pflag v1.0.5 // indirect
39+
github.com/subosito/gotenv v1.2.0 // indirect
1940
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
41+
golang.org/x/text v0.3.7 // indirect
42+
google.golang.org/protobuf v1.27.1 // indirect
2043
gopkg.in/ini.v1 v1.66.3 // indirect
44+
gopkg.in/yaml.v2 v2.4.0 // indirect
2145
)

0 commit comments

Comments
 (0)