Newer
Older
[](LICENSE)
[](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/-/pipelines)
[](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/-/pipelines)
[](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/-/commits/develop)
[](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/-/commits/main)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<div align='center'>
<img src="https://git.science.uu.nl/datastrophe/frontend/-/raw/develop/src/presentation/view/navbar/logogp.png" align="center" width="150" alt="Project icon">
</div>
## Query Service
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/datastrophe/query-conversion) and query execution code lives in [this repo](https://git.science.uu.nl/datastrophe/query-execution).
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
Here are the developer dependencies. Coding can be done without these tools, but they sure make your life easier.
- Make
- Docker
### Dependencies
This service depends on quite some other services, as it is essentially just a shell for the query conversion and execution packages.
- RabbitMQ
- Redis
- Minio
- User management service (for database credentials)
### Environment Variables
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/datastrophe/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:
- `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
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.
```
make linux
make windows
make macos
```
To build the service and push it to the Docker registry the `make docker` command can be used.
### Testing and Coverage
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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.
### Service Input
Here is the input message format.
```javascript
{
"databaseName": "test_db",
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "New York",
"dataType": "text",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": 0,
"entityTo": -1,
"constraints": [
{
"attribute": "Month",
"value": "1",
"dataType": "number",
"matchType": "exact"
}
]
}
],
"limit": 1000,
"modifiers": [
{
"type": "COUNT",
"selectedType": "entity",
"id": 0,
"attributeIndex": -1
}
]
}
```
Some additional headers also have to be set in the RabbitMQ message, these should be set by the query orchestrator.
```javascript
{
"sessionID": "12345",
"clientID": "12345",
"queryID": "12345"
}
```
### Service Output
#### Successful Execution
```javascript
{
"type": "query_result",
"value": {
"edges": [
{
"_from": "airports/JFK",
"_id": "flights/286552",
"_key": "286552",
"_rev": "_cLqg0be--U",
"_to": "airports/SFO",
"attributes": {
"ArrTime": 2332,
"ArrTimeUTC": "2008-01-16T07:32:00.000Z",
"Day": 15,
"DayOfWeek": 2,
"DepTime": 2006,
"DepTimeUTC": "2008-01-16T01:06:00.000Z",
"Distance": 2586,
"FlightNum": 649,
"Month": 1,
"TailNum": "N597JB",
"UniqueCarrier": "B6",
"Year": 2008
}
}
],
"nodes": [
{
"_id": "airports/SFO",
"_key": "SFO",
"_rev": "_cLp3eL6-_G",
"attributes": {
"city": "San Francisco",
"country": "USA",
"lat": 37.61900194,
"long": -122.3748433,
"name": "San Francisco International",
"state": "CA",
"vip": true
}
}
]
}
}
```
#### Status Updates
The service will also publish updates regarding certain queries. These follow the following pattern:
```javascript
{
"status": "query_processing_database",
"queryID": "12345"
}
```
#### Errors
If the service encounters an error, a message of the following form will be sent:
```javascript
{
"queryID": "12345",
"type": "query_database_error",
"value": "invalid database credentials"
}
```