Skip to content
Snippets Groups Projects
README.md 3.81 KiB
Newer Older
thijsheijden's avatar
thijsheijden committed
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Pipeline Status](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/badges/develop/coverage.svg)](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/-/commits/main)
[![Coverage](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/badges/main/coverage.svg)](https://git.science.uu.nl/datastrophe/microservices-backbone/query-service/-/commits/main)
[![code style: gofmt](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://golang.org/cmd/gofmt/)
sivan's avatar
sivan committed

thijsheijden's avatar
thijsheijden committed
<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
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.