Custom GraphQL service that enables subscription-based communication with ZKVerify’s data sources.
To run the API:
git clone https://github.com/HorizenLabs/zkverify-explorer-api
cd zkverify-explorer-api
docker-compose up --build
http://127.0.0.1:8000/graphql
-
Copy the seed script to the docker container:
docker cp seed_data.py <container_id_or_name>:/usr/src/seed_data.py
-
Run the seed script:
docker-compose exec api python /usr/src/seed_data.py
To run the API with GraphQL query logging enabled, we should run docker-compose with the following environment variables set:
export API_DOCKER_FILE="./docker/api/Dockerfile.query.logging" API_DOCKER_IMAGE="polkascan/explorer-api-query-logging" API_DOCKER_COMMAND="bash -c '/usr/src/start-api-query-logging.sh'" && docker-compose up --build
This will override the dockerfile used by default for the API. When the api is run in this mode, it will store all raw graphql queries in a csv file called "api_query_log.csv", this log file will be rotated every day to keep it's size manageable. This can be used to monitor API usage without impacting performance too much. In our case, we use these logs to analyse & replay all queries against a dedicated test server.
When we login to our explorer-api docker instance, we can see the generates log file after running http or websocket queries:
docker exec -it explorer-api_api_1 /bin/bash
cat api_query_log.csv
To run the API with telemetry tracing enabled, we first need to install Signoz: https://signoz.io/docs/install/docker/
Note: If you want to remove the sample application, follow these steps to modify the Signoz docker-compose file: https://signoz.io/docs/operate/docker-standalone/#remove-the-sample-application
git clone -b main https://github.com/SigNoz/signoz.git && cd signoz/deploy/
nano docker/clickhouse-setup/docker-compose.yaml
remove or comment sections hotrod & load-hotrod ath the bottom of the file
./install.sh
docker-compose -f docker/clickhouse-setup/docker-compose.yaml up -d
Next in the explorer-api/docker-compose.yml, in the api section, uncomment these lines:
networks:
- default
- clickhouse-setup_default
And in the networks section, uncomment these lines:
networks:
clickhouse-setup_default: # external network (app1)
external: true
Note: By default, start-api-telemetry.sh will be called from the accompanying dockerfile (docker/api/Dockerfile.telemetry), using these environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT='http://clickhouse-setup_default:4317'
OTEL_RESOURCE_ATTRIBUTES='service.name=explorer-api'
OTEL_TRACES_EXPORTER=otlp
Now we can build the explorer-api by using the telemetry specific variables set and run it:
export API_DOCKER_FILE="./docker/api/Dockerfile.telemetry" API_DOCKER_IMAGE="polkascan/explorer-api-telemetry" API_DOCKER_COMMAND="bash -c '/usr/src/start-api-telemetry.sh'" && docker-compose up --build
After running some graphql queries we can examine the traces in the Signoz dashboard http://localhost:3301/
To create some requests, we can use Locust.
pip3 install locust
locust -f tests/test_http.py
locust -f tests/test_websockets.py
locust -f tests/test_http.py -u 1 -r 10 --headless --run-time 30s
locust -f tests/test_websockets.py -u 1 -r 10 -t 10 --headless --run-time 30s
https://github.com/polkascan/explorer-api/blob/master/LICENSE