Python Micro-profile

Chaim Turkel
Israeli Tech Radar
Published in
4 min readFeb 22, 2020

Yes, micro-profile is built for java, but we don’t want anyone to miss out on the standardization of micro services.

Before micro-profiles, there were micro-frameworks. Multiple frameworks that gave a web server and some security. Others added some metrics into the mix, and that was about it.

Python is a good use case for a micro-framework. You can easily set up a web server with different types of application servers like Flask. Like in most micro frameworks, the basic support is rest & security. But what about metrics, health, tracing and more?

Micro-profile is a standard that covers all the basic needs of micro services so that they can all talk externally in the same language.

At Tikal we had a fuse day, where the company gets together (4 times a year) to try out new technologies or look for solutions to problems. My group decided to look into python solutions for micro-profiles. We did not want to invent the wheel, so we looked to see if some of the items were already covered and if not — start a project to begin to cover them.

I will try to go over the items that we have found, and share with you our conclusions:

OpenTracing

Open trace is a standard by itself and supports just about all the major languages. The python implementation for this can be found at opentracing-python. The problem with the library is that it is very verbose, and you need to add code per rest request (to get the span and update it). The idea behind micro-profiles is that this would be a generic framework so the programmer does not need to spend a lot of time on the implementation (see quickstart for details).

To overcome this issue, a git project of opentracing-utils, has wrapped the functionality of the original project and given a very easy API to use the functionality for different frameworks (Django, Flask, Requests, SQLAlchemy). You can find the repository at opentracing-utils.

For more information see open-tracing.

Config

Configuration is an essential part of Micro profile specification. The spec defines a modular configuration system, in which configuration can be retrieved from multiple sources with priority determines which sources are superior.

In addition, the injection of the configuration could be done using annotations. Since Python does not have annotations (decorations are not functioning as annotations), the library will not cover this requirement.

The suggested implementation includes a single configuration object that builds its values from multiple ConfigSource items with ordinal determine the priority. The default implementation includes configuration from the following sources:

  • Command-line arguments (default ordinal=400)
  • Environment variables (default ordinal=300)
  • Properties file (default ordinal=100)

Metrics

The spec for Metrics for Eclipse Micro-Profile lays out a standard for metrics which is very Java specific: almost all the required metrics are related to heap/GC, and it also focuses on implementing metrics via annotations. We want to consider a wider approach which will not enforce any language-specific details on the spec.

The standardization that we want to introduce here includes, but not restricted to, specifying:

  • the way metrics collection should be implemented (via. REST API)
  • the different metrics-types
  • metrics-tags
  • metrics-metadata
  • metrics-registry
  • naming-conventions

By covering the above we aim to provide an easy interface which could be applied to any polyglot micro service environment. This, in turn, will allow service-owners to publish their metrics using clear semantics and set the expectation on the devops side in a way that will make it easier to know what to expect (in which format and etc) when collecting the metrics.

For more information see metrics.

Health Check

Healthcheck is a very simple and basic concept in the world web-servers. It is used in the probing process of nodes by external, usually governing, nodes in the infrastructure.
As such, it should not be implemented over and over again for each micro service and in each micro-framework, but a simple standard could be in use.

Micro-profile defines such a standard for health checks, providing a standard API to be used in the code and a concrete definition of the Wireformat for the response. Moreover, micro-profile enhances it with the “liveness” and “readiness” terms. Where one provides information about the status of the current node in the system, and the later is used on bootstrapping of a node to probe when it is ready to start receiving load.

For more information see health.

CDI

CDI (Contexts and Dependency Injection) is a standard in the java world, and very not “in” the python world. The micro-profiles uses a lot of injections and therefore is something that should be looked into. There is a pycdi library, though currently it is not very adopted.

For the full repository and summaries, please see our git project: https://github.com/tikal-fuseday/python-microprofile/

If you feel like us that this cause is important for the synergy of polyglot services, please like our git project.

  • Nir Alfasi
  • Haim Cohen
  • Moti Dadison
  • Slava Deminder
  • Avishai Moar
  • Chaim Turkel

--

--