gRPC, queues and jobs
When your service takes its work some way other than HTTP, replace the driver with a container of your own. Everything it sends is an input, and everything the app does while serving it is compared.
On this page
Replace the driver #
By default the driver is Hurl, sending the .hurl files in your requests folder, one at a time.
To change it, define a service named driver in nk/app.yaml, with an image and a command. It starts once your app service is healthy, and it runs the same way against both builds.
Two things to get right:
- Name the service that runs your app
app. The driver waits for the service of that name, as The app file describes. - Start what it needs yourself. The driver starts with
--no-deps, so a service it depends on is not started for it.
The examples below assume the app listens on port 8000 and that a broker is a service named kafka in your app file. Change those to match yours.
Send gRPC calls #
Use grpcurl as the driver:
services:
driver:
image: fullstorydev/grpcurl:latest-alpine
user: "0:0"
entrypoint: ["sh", "-c"]
command:
- >-
grpcurl -plaintext app:8000 list;
grpcurl -plaintext -d '{"sku":"mug"}' app:8000 myapp.v1.Orders/Create;
grpcurl -plaintext -d '{"id":"1"}' app:8000 myapp.v1.Orders/GetEach call is one input. The report names it by its gRPC method, as in 0002 POST /myapp.v1.Orders/Create, the way it names HTTP requests by method and path.
--proto <file or folder> reads gRPC messages by their schema.
Send WebSocket messages #
Drive it the same way, with a client such as websocat in the driver and one message per input.
Send a message on a queue #
Make the driver produce the message your service consumes, for example with kcat:
services:
driver:
image: edenhill/kcat:1.7.1
entrypoint: ["sh", "-c"]
command:
- >-
echo '{"order":1,"sku":"mug"}' | kcat -P -b kafka:9092 -t orders;
sleep 2;
echo '{"order":2,"sku":"plate"}' | kcat -P -b kafka:9092 -t ordersFit this to your broker, topic and payload, and expect to tune the pause.
Run a scheduled job #
Work no input started, such as a cron job, is compared as well:
- Before the first input, it counts as startup.
- After it, it counts as part of the last input sent.
Make it run inside the window Nikasa watches, in one of two ways:
- Shorten the schedule through the service's own settings in the app file, to an interval of a few seconds.
- Have the driver call the endpoint that triggers the job, if the service has one.
As with a queue, expect to tune this to your job, and leave the job time to finish before the run ends.
Several inputs, one report #
However the driver sends its inputs, Nikasa keeps them in the order they were sent.
- Keep inputs that depend on time or randomness out of the command. Otherwise Nikasa learns them as varying and compares less.
- If your driver sends inputs at the same time, Nikasa cannot tell which one caused a call. It names them and does not count their cost.
Next steps #
- The app file: where the
driverservice lives, and what else the file holds. - Record your tests: the easier route when your tests already send HTTP.
- Your first compare: run a compare and read its report.
- Words in a report: what an input and a driver are.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.