Services are libraries, resources and extensions added to the Microservice in the configuration file. These services are created as an attribute of the Microservice class to use in the code.
To add a service check the configuration section.
You can declare a service but activate/deactivate with the keyword enabled, like so:
pyms:
services:
requests:
enabled: falseCurrently availabe services are:
Extends the Microservice with Connexion and swagger-ui.
You must install pyms with pip install py-ms[all] or pip install py-ms[swagger]
The parameters you can add to your config are the following:
- path: The relative or absolute route to your swagger yaml file. The default value is the current directory
- file: The name of you swagger yaml file. The default value is
swagger.yaml - url: The url where swagger run in your server. The default value is
/ui/. - project_dir: Relative path of the project folder to automatic routing,
See this link for more info. The default value is project.
See Routing in this documentation to how configure your Swagger.
pyms:
services:
swagger:
path: "swagger"
file: "swagger.yaml"
url: "/ui/"
project_dir: "project.views"Extend the requests library with trace headers and parsing JSON objects. Encapsulates common rest operations between business services propagating trace headers if set up.
You must install pyms with pip install py-ms[all] or pip install py-ms[request]
The parameters you can add to your config are:
- data: wrap the response in a data field of an envelope object, and add other meta data to that wrapper. The default value is None
- retries: If the response is not correct, this specifies the amount of times it performs the request again. The default number of retries is 3.
- status_retries: List of response status codes that are considered "not correct". The default values are [500, 502, 504]
- propagate_headers: Propagate the headers of the current execution to the request. The default values is False
pyms:
services:
requests:
data: "data"
retries: 4
status_retries: [400, 401, 402, 403, 404, 405, 500, 501, 502, 503]
propagate_headers: trueAdd traces to all executions with opentracing. This service solves the problem of distributed tracing
See Propagate traces tutorial in this documentation for more information.
You must install pyms with pip install pyms[all] or pip install pyms[trace]
The parameters you can add to your config are:
- client: set the client that will receive the traces, The current options are Jaeger and Lightstep. The default value is jaeger.
- host: The url to send the data of traces. Check this tutorial to create your own server
- component_name: The name of your application to show in Prometheus metrics
pyms:
services:
tracer:
client: "jaeger"
host: "localhost"
component_name: "Python Microservice"Adds Prometheus metrics using the Prometheus Client Library.
The following metrics are currently available:
- Incoming requests latency as a histogram
- Metric name:
http_server_requests_seconds - Labels:
- service: the
APP_NAME - method: HTTP method (get, post, ...)
- uri: Received flask route
- status: HTTP status (200, 503, ...)
- service: the
- Metric name:
- Incoming requests number as a counter
- Metric name:
http_server_requests_count - Labels:
- service: the
APP_NAME - method: HTTP method (get, post, ...)
- uri: Received flask route
- status: HTTP status (200, 503, ...)
- service: the
- Metric name:
- Total number of log events grouped by level
- Metric name:
logger_messages_total - Labels:
- service: the
APP_NAME - level: log's severity level (warning, info, ...)
- service: the
- Metric name:
- If the
tracerservice is activated and it's jaeger, it will show its metrics- Metric name: the metrics are not named, but its prefix is
jaeger
- Metric name: the metrics are not named, but its prefix is
- If the
requestsservice is activated, outgoing requests latency as a histogram:- Metric name:
http_server_responses_seconds - Labels:
- service: the
APP_NAME - method: HTTP method (get, post, ...)
- uri: Received flask route
- status: HTTP status (200, 503, ...)
- service: the
- Metric name:
- If the
requestsservice is activated, outgoing requests number as a counter:- Metric name:
http_server_responses_count - Labels:
- service: the
APP_NAME - method: HTTP method (get, post, ...)
- uri: Received flask route
- status: HTTP status (200, 503, ...)
- service: the
- Metric name:
You must install pyms with pip install py-ms[all] or pip install py-ms[metrics]
pyms:
services:
metrics: trueThis will add the endpoint /metrics to your microservice, which will expose
the metrics.
Adds Consul as service discovery using the Consul Client Library or create your own service discovery
See Service Ddiscovery section in this documentation for more information.
You must install pyms with pip install py-ms[all] or pip install py-ms[consul]
pyms:
services:
service_discovery:
service: consul
host: localhost
port: 8500
autoregister: trueThis will add the endpoint /metrics to your microservice, which will expose
the metrics.