Doctor Service
The purpose of the doctor service is to do a complete check of the services status in the project in which is deployed.
To do this, the service will call a specific route, the /-/check-up
one.
NB. the Doctor service is the only one who can call the /-/check-up
route of services.
NEVER call the /-/check-up
route of a service from the checkUpHandler of another service, the risk is to start a /-/check-up
calls loop.
Deploy
The Doctor Service is easily deployable on every project by using the Console. You just need to add the service and configure it's configuration file.
The Doctor Service is simply based on one file, the configurations file.
With the configurations file it's easy to manage all services to check-up
.
Specifically, the Doctor allows the user to do two things:
check-up
all services in the configurations file by simply call the root path (e.g. http://api.foobar.it/playground/check-up);check-up
a subgroup of services by specify the tag → all services can have a list of tags (optional) and the Doctor will expose a dedicated route for each tag, that will return thecheck-up
of services with that tag.
NB. all the services call by the Doctor MUST have the /-/check-up
route.
Configuration
Following an overview of the steps that you have to do to integrate the Doctor Service in your project:
- Build the configurations file of the Doctor Service
- Create the service using the API Console
- Configure the Advanced configurations
- Check-up'em all
The following example is based on a Playground project.
1. Build the configurations file
As previously said, the Doctor Service just needs a configurations file that has to follow this schema:
{
type: 'array',
items: {
type: 'object',
required: ['hostname'],
properties: {
hostname: { type: 'string' },
tags: {
type: 'array',
items: {
type: 'string',
},
},
options: {
type: 'object',
properties: {
prefix: {
type: 'string',
pattern: '^(\\/.*[A-Za-z1-9])?$',
default: '',
},
port: {
type: 'number',
default: 80,
},
protocol: {
type: 'string',
default: 'http',
enum: ['http', 'https'],
},
},
default: {},
additionalProperties: false,
},
},
additionalProperties: false,
},
}
As specified into the schema, the tags property is optional → a Doctor Service can have all services without tags and it still works on the root path.
Additionally, it is possible to specify an options
object in order to manage further how the /-/check-up
route is called.
The following options can be provided:
prefix
: to specify a prefix to append before/-/check-up
route. Default is an empty string.protocol
: to specify a different protocol. Onlyhttp
orhttps
can be specified. Default ishttp
.port
: to specify a different port. Default is 1.
In the following example we will set just one tag, the core tag, just for core services:
[
{ "hostname": "auth-service", "tags": ["core"] },
{ "hostname": "cms-backend", "tags": ["core"] },
{ "hostname": "crud-service", "tags": ["core"] },
{ "hostname": "microservice-gateway", "tags": ["core"] },
{ "hostname": "swagger-aggregator", "tags": ["core"] },
{ "hostname": "v1-adapter", "tags": ["core"], "options": { "prefix": "/api/v2", "port": 8888, "protocol": "https" } },
{ "hostname": "node-service" },
{ "hostname": "angular-service" },
{ "hostname": "react-service" },
{ "hostname": "java-service" },
]
This way, for swagger-aggregator
service, doctor-service will call the /-/check-up
route at https://swagger-aggregator/-/check-up
, instead for v1-adapter
service, doctor-service will call the /-/check-up
route at https://v1-adapter:8888/api/v2/-/check-up
.
In this way, we should have the following routes:
baseUrl/check-up
→ should return thecheck-up
response of all servicesbaseUrl/check-up/core
→ should return thecheck-up
response just of services with the core tag
The configurations file is ready, let's continue.
2. Doctor Service creation on the API Console
Now it's time to create the real service.
Following the steps to create the services:
- Open the API Console and choose the project
- Click, on the left, on Microservices
- Click on the Create a Microservice button
- Search for doctor service and click on the Doctor Service plugin button
- Fill the form:
- Name: the name of the service (in the example is doctor-service)
- Description: the description of the service
- Click on the Create button
- Scroll down and click on Add a configuration
- Edit the environment variable SERVICES_LIST_PATH and set /home/node/app/config/services.json
- Fill the form:
- Configuration name: The name of the configuration (e.g. doctor-service-config)
- Runtime Mount Path: The folder path where will be created the configuration. Set to /home/node/app/config/
- Click on Add file, fill Name with services.json and click on Create
- Insert the previously created configurations file into the just created file
- Save (Commit and generate button)
3. Check-up'em all
Now the /check-up
route of the project is ready to be called like this:
projectBaseUrl/check-up
→ for a check-up of all servicesprojectBaseUrl/check-up/core
→ for a check-up of core services only (in this example)