Skip to main content

Overview

The Seal service is responsible for sealing messages. The service receives messages, seals them, composes an email containing the sealed message and sends the email. The service is designed to be scalable and fault-tolerant. The service is built using the Go programming language and is designed to be run in a containerized environment.

Sealing means breaking apart a message, encrypting each part, storing it in IPFS and then preparing a sealed message that is sent to a recipient.

Table of Contents

Overview Diagram

Configuration

The seal service is configured using the [Configuration File] that coult be found at /internal/config/config.go. All configurations are expected as Environment variables specified in the configuration file. For managing the configuration data from ENV variables, envconfig library is used.

DB migrations

SQL migration files are created in /db/migrations by using the Golang migrate tool. Example command to make a new migration file:

migrate create -ext sql -dir ./db/migrations messages_table

Build

Local binary

To make the service binary locally, you can run the following command from the root directory (you must have Go installed):

go build -o seal ./cmd/seal/...
Docker image

You can see the Dockerfile of the service under the ./deployment directory. There is one Dockerfile for use during local development with /deployment/compose/Dockerfile and one for building an optimized production image: /deployment/ci/Dockerfile.

Versioning

There is one global exported variable named Version in main.go. The variable is set to the latest tag or commit hash during the build process. You can look in the production Dockerfile to see how the Version is set during build. The version is printed in the service log on startup and can be used to verify which specific commit of the code is deployed. The Version is also present in the health check responses on the /liveness and /readiness endpoints.

Metrics

The service exposes the following Prometheus metrics.

Metric NameType
http_requests_totalCounter with labels [operation, code]
http_request_duration_secondsHistogram with labels [operation, code]
sealed_messages_totalCounter
sealed_messages_total_size_bytesCounter
failed_seal_messages_totalCounter
messages_in_queueGauge
seal_process_duration_secondsHistogram

Swagger API Documentation

The service uses Swag to generate Swagger documentation. The documentation is generated from annotations in the source code. You can find documentation and examples on how to use Swag in the Swaggo GitHub repository.

In order to generate the Swagger documentation, you need to run the swagger.sh script.

./generate_swagger.sh

The script will generate the Swagger documentation by creating openapi.json file in the swagger directory.

Logging

The service outputs all logs to stdout as defined by the best practices in the Cloud Native community. See here for more details 12 Factor App. From there logs could be processed as needed in the specific running environment. The standard log levels are [debug,info,warn,error,fatal] and info is the default level. If you want to set another log level, use the ENV configuration variable LOG_LEVEL to set it.

Tests and Linters

To execute the units tests for the service go to the root project directory and run:

go test -race ./...

To run the linters go to the root project directory and run:

golangci-lint run