Kora фреймворк для написания Java / Kotlin приложений с упором на производительность, эффективность, прозрачность сделанный разработчиками Т-Банк / Тинькофф

Kora is a framework for writing Java / Kotlin applications with a focus on performance, efficiency, transparency made by T-Bank / Tinkoff developers

Skip to content

Metrics

Module for collecting application metrics using Micrometer.

Requires HTTP server module added to provide metrics in prometheus format.

Dependency

Dependency build.gradle:

implementation "ru.tinkoff.kora:micrometer-module"

Module:

@KoraApp
public interface Application extends MetricsModule { }

Dependency build.gradle.kts:

implementation("ru.tinkoff.kora:micrometer-module")

Module:

@KoraApp
interface Application : MetricsModule

Configuration

Example of HTTP server path configuration for retrieving metrics described in the HttpServerConfig class (default values are specified):

httpServer {
    privateApiHttpMetricsPath = "/metrics" //(1)!
}
  1. Path to get metrics in prometheus format (if HTTP server module is added):
httpServer:
  privateApiHttpMetricsPath: "/metrics" #(1)!
  1. Path to get metrics in prometheus format (if HTTP server module is added):

Example of the complete configuration described in the MetricsConfig class (default values are specified):

metrics {
    opentelemetrySpec = "V120" //(1)!
}
  1. OpenTelemetry standard metrics format (available values: V120 / V123)
metrics:
  opentelemetrySpec: "V120" #(1)!
  1. OpenTelemetry standard metrics format (available values: V120 / V123)

Metrics collection configuration parameters are described in modules where metrics collection is present, e.g. HTTP server, HTTP client, etc.

Usage

We follow and encourage to use the notation described in the specification.

Once the Metrics.globalRegistry module is connected, the PrometheusMeterRegistry will be registered and used in all components that collect metrics.

Personalization

In order to make changes to the PrometheusMeterRegistry configuration, you need to add to the PrometheusMeterRegistryInitializer container.

Important, PrometheusMeterRegistryInitializer is applied only once when the application is initialized.

For example, we want to add a common tag for all metrics:

@Module
public interface MetricsConfigModule {
    default PrometheusMeterRegistryInitializer commonTagsInit() {
        return registry -> {
            registry.config().commonTags("tag", "value");
            return registry;
        };
    }
}
@Module
interface MetricsConfigModule {
    fun commonTagsInit(): PrometheusMeterRegistryInitializer? {
        return PrometheusMeterRegistryInitializer {
            it.config().commonTags("tag", "value")
            it
        }
    }
}

Standard metrics have some configurations such as ServiceLayerObjectives for Distribution summary metrics. The configuration field names can be viewed in ru.tinkoff.kora.micrometer.module.MetricsConfig.

Standard

The original metrics format used the OpenTelemetry V120 standard, after Kora 1.1.0 it became possible to provide metrics in the OpenTelemetry V123 standard. in the OpenTelemetry V123 standard, a partial list of changes can be seen in the OpenTelemetry documentation and OpenTelemetry migration guidelines