Newer
Older
[](LICENSE)
[](https://git.science.uu.nl/GraphPolaris/microservices-backbone/query-service/-/pipelines)
[](https://git.science.uu.nl/GraphPolaris/microservices-backbone/query-service/-/pipelines)
[](https://git.science.uu.nl/GraphPolaris/microservices-backbone/query-service/-/commits/develop)
[](https://git.science.uu.nl/GraphPolaris/microservices-backbone/query-service/-/commits/main)
<img src="https://git.science.uu.nl/GraphPolaris/frontend/-/raw/develop/src/presentation/view/navbar/logogp.png" align="center" width="150" alt="Project icon">
Leonardo Christino
committed
This service handles the conversion and execution of queries sent from the frontend. The conversion and execution code was moved into packages, to be able to re-use this service as the shell. Query conversion code (to convert from our JSON format to AQL or Cypher) lives in [this repo](https://git.science.uu.nl/GraphPolaris/query-conversion) and query execution code lives in [this repo](https://git.science.uu.nl/GraphPolaris/query-execution). For handing queries with Machine Learning algorithms, the [ML service](https://git.science.uu.nl/GravenvanPolaris/machine-learning-service) is used.
The reason the conversion and execution code are seperated is because there can be multiple databases using the same query language, while they each have their own driver.
### Dev Dependencies
Leonardo Christino
committed
Here are the developer dependencies. Coding can be done without these tools, but they sure make your life easier.
Leonardo Christino
committed
Leonardo Christino
committed
This service depends on quite some other services, as it is essentially just a shell for the query conversion and execution packages.
Leonardo Christino
committed
- RabbitMQ
- Redis
- Minio
- User management service (for database credentials)
- Machine Learning service (for handling queries with ML)
Leonardo Christino
committed
To decide which conversion and execution packages will be used the service uses environment variables. The `QUERY_CONVERSION_LANGUAGE` variable determines which query conversion package will be used. Currently only `aql` and `cypher` are supported. The `QUERY_EXECUTION` variable determines the executor that will be used. This variable also changes the queue and routing key the service listens to, as can be seen [here](https://git.science.uu.nl/GraphPolaris/microservices-backbone/query-service/-/blob/develop/internal/usecases/consume/consume.go) on line 41.
There are some more environment variables that are used in this service, which are listed below:
Leonardo Christino
committed
- `RABBIT_HOST` address of the RabbitMQ instance (string)
- `RABBIT_PORT` RabbitMQ port (int)
- `RABBIT_USER` RabbitMQ username (string)
- `RABBIT_PASSWORD` RabbitMQ password (string)
- `REDIS_ADDRESS` Redis address (string)
- `LOG_MESSAGES` Whether to log messages (bool)
- `MINIO_ADDRESS` Minio address (string)
- `MINIO_ACCESSKEYID` Minio username (string)
- `MINIO_ACCESSKEY` Minio password (string)
### Building the Service
Leonardo Christino
committed
To compile the service into a single binary, the following commands can be used. Go can build for many platforms, so we have three build commands, for the three main platforms.
Leonardo Christino
committed
```
make linux
make windows
make macos
```
Leonardo Christino
committed
To build the service and push it to the Docker registry the `make docker` command can be used.
Leonardo Christino
committed
### Docker
To build the docker image with `make docker` or `make rollout` you need to create a ssh key pair inside the keys folder and add the public key to your gitlab instance. This is needed because this package has a private dependency to a package inside the graphpolaris group, which means that it needs to authenticate with gitlab to download the dependencies.
Leonardo Christino
committed
To test the `make test` command can be used. It will run every test in the repo. To get the code coverage the command `make coverage` can be used. This command will run all tests and display total coverage over all files. It will also generate an html file which displays exactly which lines have been covered.
### Kubernetes
Leonardo Christino
committed
All the Kubernetes config files live in the `/deployments` directory. This service has two deployments, which only differ in the environment variables being set for query conversion and execution. This service also has two horizontal pod autoscalers, which will scale the service based on CPU load.
Leonardo Christino
committed
<div align='center'>
<img src="images/query_service.png" align="center" width="75%" alt="Query service flow">
</div>
Leonardo Christino
committed
Leonardo Christino
committed
"entities": [29, 30],
"relations": [28],
"groupBys": []
},
{
"name": "parliament",
"ID": 29,
"constraints": []
},
{
"name": "parties",
"ID": 30,
"constraints": [
{
"attribute": "seats",
"value": "5",
"dataType": "int",
"matchType": "LT"
}
]
}
{
"ID": 28,
"name": "member_of",
"depth": {
"min": 1,
"max": 1
},
"fromType": "entity",
"fromID": 29,
"toType": "entity",
"toID": 30,
"constraints": []
}
],
"groupBys": [],
"machineLearning": [
{
"queuename": "cdt_queue",
"parameters": []
}
],
"limit": 5000,
"databaseName": "Tweede Kamer Dataset"
}
Leonardo Christino
committed
Some additional headers also have to be set in the RabbitMQ message, these should be set by the query orchestrator.
Leonardo Christino
committed
```javascript
{
"sessionID": "12345",
"clientID": "12345",
"queryID": "12345"
}
```
### Service Output
#### Successful Execution
Leonardo Christino
committed
{ "attributes": { "isChairman": false }, "from": "parliament/126", "id": "member_of/126", "to": "parties/SGP" },
{ "attributes": { "isChairman": true }, "from": "parliament/125", "id": "member_of/125", "to": "parties/SGP" },
{ "attributes": { "isChairman": false }, "from": "parliament/122", "id": "member_of/122", "to": "parties/GroepVanHaga" },
{ "attributes": { "isChairman": true }, "from": "parliament/120", "id": "member_of/120", "to": "parties/BIJ1" },
{ "attributes": { "isChairman": false }, "from": "parliament/112", "id": "member_of/112", "to": "parties/JA21" },
{ "attributes": { "isChairman": true }, "from": "parliament/110", "id": "member_of/110", "to": "parties/BBB" },
{ "attributes": { "isChairman": false }, "from": "parliament/84", "id": "member_of/84", "to": "parties/DENK" },
{ "attributes": { "isChairman": false }, "from": "parliament/78", "id": "member_of/78", "to": "parties/Volt" },
{ "attributes": { "isChairman": true }, "from": "parliament/50", "id": "member_of/50", "to": "parties/GroepVanHaga" },
{ "attributes": { "isChairman": true }, "from": "parliament/49", "id": "member_of/49", "to": "parties/FractieDenHaan" },
{ "attributes": { "isChairman": false }, "from": "parliament/48", "id": "member_of/48", "to": "parties/Volt" },
{ "attributes": { "isChairman": false }, "from": "parliament/37", "id": "member_of/37", "to": "parties/JA21" },
{ "attributes": { "isChairman": false }, "from": "parliament/36", "id": "member_of/36", "to": "parties/GroepVanHaga" },
{ "attributes": { "isChairman": true }, "from": "parliament/32", "id": "member_of/32", "to": "parties/JA21" },
{ "attributes": { "isChairman": true }, "from": "parliament/27", "id": "member_of/27", "to": "parties/Volt" },
{ "attributes": { "isChairman": false }, "from": "parliament/17", "id": "member_of/17", "to": "parties/SGP" },
{ "attributes": { "isChairman": false }, "from": "parliament/7", "id": "member_of/7", "to": "parties/DENK" },
{ "attributes": { "isChairman": true }, "from": "parliament/6", "id": "member_of/6", "to": "parties/DENK" }
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
{ "attributes": { "chairman": "Sylvana Simons", "chairmanId": 120, "name": "BIJ1", "seats": 1 }, "id": "parties/BIJ1", "mldata": 0 },
{ "attributes": { "chairman": "Caroline van der Plas", "chairmanId": 110, "name": "BoerBurgerBeweging", "seats": 1 }, "id": "parties/BBB", "mldata": 1 },
{ "attributes": { "chairman": "Liane den Haan", "chairmanId": 49, "name": "Fractie Den Haan", "seats": 1 }, "id": "parties/FractieDenHaan", "mldata": 2 },
{ "attributes": { "chairman": "Wybren van Haga", "chairmanId": 50, "name": "Groep Van Haga", "seats": 3 }, "id": "parties/GroepVanHaga", "mldata": 3 },
{ "attributes": { "chairman": "Joost Eerdmans", "chairmanId": 32, "name": "JA21", "seats": 3 }, "id": "parties/JA21", "mldata": 4 },
{ "attributes": { "chairman": "Laurens Dassen", "chairmanId": 27, "name": "Volt", "seats": 3 }, "id": "parties/Volt", "mldata": 5 },
{ "attributes": { "chairman": "Kees van der Staaij", "chairmanId": 125, "name": "Staatkundig Gereformeerde Partij", "seats": 3 }, "id": "parties/SGP", "mldata": 6 },
{ "attributes": { "chairman": "Farid Azarkan", "chairmanId": 6, "name": "DENK", "seats": 3 }, "id": "parties/DENK", "mldata": 7 },
{
"attributes": {
"age": 46,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/98aa8bde-85b0-49ed-9795-e2eeb206e3b8.jpg?itok=CODn43Bf",
"name": "Chris Stoffer",
"party": "SGP",
"residence": "Elspeet",
"seniority": 1142
},
"id": "parliament/126",
"mldata": 6
},
{
"attributes": {
"age": 52,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/1b59d69d-89a1-42c3-b5bf-52f38c39d88d.jpg?itok=o4nroqLI",
"name": "Kees van der Staaij",
"party": "SGP",
"residence": "Benthuizen",
"seniority": 8409
},
"id": "parliament/125",
"mldata": 6
},
{
"attributes": {
"age": 60,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/eb79af3c-a66d-4374-b9e7-34d7f3e92dc7.jpg?itok=wMZmTmkc",
"name": "Hans Smolders",
"party": "Groep Van Haga",
"residence": "Tilburg",
"seniority": 309
},
"id": "parliament/122",
"mldata": 3
},
{
"attributes": {
"age": 50,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/0ae6735e-4b1b-4302-a20e-bbe5b72155c3.jpg?itok=C1-541cc",
"name": "Sylvana Simons",
"party": "BIJ1",
"residence": "Duivendrecht",
"seniority": 57
},
"id": "parliament/120",
"mldata": 0
},
{
"attributes": {
"age": 30,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/9f0c39d6-4a57-4849-9215-aa1147c7e0f6.jpg?itok=1JWOuIjk",
"name": "Nicki Pouw-Verweij",
"party": "JA21",
"residence": "Maarssen",
"seniority": 57
},
"id": "parliament/112",
"mldata": 4
},
{
"attributes": {
"age": 53,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/b41b2403-9f06-4d55-adc5-b0777373ca7e.jpg?itok=rmudNELC",
"name": "Caroline van der Plas",
"party": "BBB",
"residence": "Deventer",
"seniority": 57
},
"id": "parliament/110",
"mldata": 1
},
{
"attributes": {
"age": 39,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/16596afa-9e56-4d0a-a715-f40592825937.jpg?itok=xVPho7Yp",
"name": "Tunahan Kuzu",
"party": "DENK",
"residence": "Rotterdam",
"seniority": 3171
},
"id": "parliament/84",
"mldata": 7
},
{
"attributes": {
"age": 32,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/d34e1efc-fbba-4ad8-823a-61bc3f25d580.jpg?itok=WXFGv3_8",
"name": "Marieke Koekkoek",
"party": "Volt",
"residence": "Utrecht",
"seniority": 57
},
"id": "parliament/78",
"mldata": 5
},
{
"attributes": {
"age": 54,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/ab15ce32-a527-4526-a5b2-0f2cdb92feeb.jpg?itok=rPcdqouS",
"name": "Wybren van Haga",
"party": "Groep Van Haga",
"residence": "Haarlem",
"seniority": 1305
},
"id": "parliament/50",
"mldata": 3
},
{
"attributes": {
"age": 53,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/3e48d4c9-0d66-4b50-9f9c-969b5e314a42.jpg?itok=0wlX1bse",
"name": "Liane den Haan",
"party": "Fractie Den Haan",
"residence": "Woerden",
"seniority": 58
},
"id": "parliament/49",
"mldata": 2
},
{
"attributes": {
"age": 43,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/f31cabe4-e1f4-46db-88a9-b46ba44dded4.jpg?itok=FfoXTIug",
"name": "Nilfer Gndoan",
"party": "Volt",
"residence": "Amsterdam",
"seniority": 57
},
"id": "parliament/48",
"mldata": 5
},
{
"attributes": {
"age": 62,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/6e4a8d23-9d3b-4565-a3ab-086eb51d6c08.jpg?itok=RSKd0BLe",
"name": "Derk Jan Eppink",
"party": "JA21",
"residence": "'s-Gravenhage",
"seniority": 57
},
"id": "parliament/37",
"mldata": 4
},
{
"attributes": {
"age": 55,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/d59d1492-57b6-482b-88b6-b2b77c45c33d.jpg?itok=g4RdRfw2",
"name": "Olaf Ephraim",
"party": "Groep Van Haga",
"residence": "Amsterdam",
"seniority": 57
},
"id": "parliament/36",
"mldata": 3
},
{
"attributes": {
"age": 50,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/c6e26bd3-724f-45d3-93af-ef431e6fcd42.jpg?itok=k6ziMwhD",
"name": "Joost Eerdmans",
"party": "JA21",
"residence": "Rotterdam",
"seniority": 1709
},
"id": "parliament/32",
"mldata": 4
},
{
"attributes": {
"age": 35,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/a68468b6-51ea-440c-9387-b44ba10ad8b6.jpg?itok=UYMugaP_",
"name": "Laurens Dassen",
"party": "Volt",
"residence": "Amsterdam",
"seniority": 57
},
"id": "parliament/27",
"mldata": 5
},
{
"attributes": {
"age": 64,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/9b13c8c8-eba4-411e-b095-858e352d3178.jpg?itok=qcZcaIXc",
"name": "Roelof Bisschop",
"party": "SGP",
"residence": "Veenendaal",
"seniority": 3171
},
"id": "parliament/17",
"mldata": 6
},
{
"attributes": {
"age": 29,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/859e1824-cc60-4304-9293-dca932ebbed2.jpg?itok=WSmCeVtj",
"name": "Stephan van Baarle",
"party": "DENK",
"residence": "Rotterdam",
"seniority": 57
},
"id": "parliament/7",
"mldata": 7
},
{
"attributes": {
"age": 49,
"img": "https://www.tweedekamer.nl/sites/default/files/styles/member_parlement_profile_square/public/09155809-0b6e-4f9f-a75b-026aa4b35588.jpg?itok=oVDwOcW4",
"name": "Farid Azarkan",
"party": "DENK",
"residence": "Culemborg",
"seniority": 1526
},
"id": "parliament/6",
"mldata": 7
}
```
#### Status Updates
Leonardo Christino
committed
The service will also publish updates regarding certain queries. These follow the following pattern:
Leonardo Christino
committed
```javascript
{
"status": "query_processing_database",
"queryID": "12345"
}
```
#### Errors
Leonardo Christino
committed
If the service encounters an error, a message of the following form will be sent:
Leonardo Christino
committed
Leonardo Christino
committed
"value":
{
"status": "invalid database credentials",
"queryID": "12345"
}
Leonardo Christino
committed
```
## Extra Information
- run `GOPRIVATE=git.science.uu.nl/graphpolaris/* go get <privaterepo>` to add a private repo
- run `git config --global url."git@git.science.uu.nl:".insteadOf "https://git.science.uu.nl/"` to allow go to use ssh instead of https