Answers to stackpath.com's Backend Developer Tests
Original README
The answer is just one test file located here.
The core answer is in the people.go file inside the rest-api/pkg/handlers
sub-directory. But I've thrown a bunch of extras so the answer to this test is pretty much the whole rest-service sub-directory. Extras:
-
Lots of tests for the main handler in the
rest-api/pkg/handlers
sub-directory. -
The service is deployed using AWS Lambda. The endpoint is here.
cd
intorest-service/cmd/microservice/deploy
, then runmake test
to test the different scenarios (GET /people, GET /people/?first_name=...&last_name=...) specified in the test against the endpoint. I used Terraform to provision the AWS resources. The Terraform code is located here. -
Instrumentation and metrics gathering using Prometheus and Grafana. Some of the metrics gathered are total number of requests and response time. Use the term
stackpath_dev_tests
in Grafana's Metrics Browser to filter the custom metrics I've added. For now, this only works locally.
-
cd
intorest-service
, then rundocker compose up
. This command will run the REST service, Prometheus, Grafana, and Node Exporter inside containers. Once the containers are running, proceed to the next steps. -
Open your browser to http://localhost:3030/. This is the Grafana portal. The default log in username and password is
admin
. -
Once you're logged in, click on "Add your first data source", then click on "Prometheus", then enter "http://prometheus:9090" in the HTTP URL text box. Click on "Save & Test" button located below. If everything works, you should see a green check mark "Data source is working" status message.
-
Click on "Explore" on the side bar (compass icon), click on "Metrics Browser", then enter "stackpath_dev_tests" in the "Select a metric" text box. Click on a metric to see information and graphs about that metric.