An example of a gRPC service, written in Go. The service provides convertions between strings and runes.
To be used with other gRPC and REST services, running locally using docker-compose or running in a Kubernetes cluster.
- Go
- gRPC
- protobufs generated with prototool
- mocks generated with counterfeiter
- redis for caching
- golangci-lint for code quality (https://raw.githubusercontent.com/golangci/golangci-lint/master/.golangci.example.yml)
- dockertest for integration testing
- docker, docker-compose
- telegraf and informixdb for metrics
Generated using the Uber's prototool.
a) proto description (char-vs-rune.proto)
option go_package = "github.com/tamarakaufler/grpc-char-vs-rune/client/char_vs_rune";
the last part char_vs_rune must not contain dashes
b) If there is an issue regarding the go_package line during the generation, try upgrading the protoc and the Go grpc related plugins.
Used to allow import of only what's needed by the client of this service,ie the protobufs and the related mocks.
NOTE
The protobuf package is defined as char_vs_rune in ./client/char-vs-rune/char-vs-rune.pb.go (see the protobufs section a) above), but is imported as:
"github.com/tamarakaufler/grpc-char-vs-rune/client/char-vs-rune"
run and stop using docker-compose:
- make services-start
- make services-stop
-
redis methods for storing and retrieval are tested with the help of dockertest (github.com/ory/dockertest/v3). The dockertest module provides a redis docker container without the need for using docker-compose. These tests are strictly speaking unit tests, but as they require docker, they are tagged as integration_tests.
-
handler integration tests use docker-compose.
Metrics sent using the StatsD protocol to Telegraf, the StatsD aware service that stores the data in a timne-series database influxdb database.
The required services, telegraph and influxdb, are started using make start-services task, that also starts the grpc-char-to-rune service.
Send the metrics
NOTE
While docker pull telegraf pulled the image (docker.io/library/telegraf:latest), using telegraph.latest as the telegraph image in docker-compose.yml ended with: ERROR: pull access denied for telegraph, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
The solution was to use the full name of the image: docker.io/library/telegraf:latest
Telegraf configuration
Needs to contain at least one inputs configurations and one outputs configuration.
https://www.influxdata.com/blog/running-influxdb-2-0-and-telegraf-using-docker/ https://github.com/influxdata/telegraf/blob/master/etc/telegraf.conf