diff --git a/envoy-control-core/build.gradle b/envoy-control-core/build.gradle index d430d0b56..9b0537eff 100644 --- a/envoy-control-core/build.gradle +++ b/envoy-control-core/build.gradle @@ -7,6 +7,7 @@ dependencies { implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect' api group: 'io.dropwizard.metrics', name: 'metrics-core', version: versions.dropwizard api group: 'io.micrometer', name: 'micrometer-core' + api group: 'io.micrometer', name: 'micrometer-registry-prometheus' implementation group: 'com.google.re2j', name: 're2j', version: versions.re2j diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlMetrics.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlMetrics.kt index 9c17c302a..ba224759c 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlMetrics.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlMetrics.kt @@ -1,7 +1,8 @@ package pl.allegro.tech.servicemesh.envoycontrol import io.micrometer.core.instrument.MeterRegistry -import io.micrometer.core.instrument.simple.SimpleMeterRegistry +import io.micrometer.prometheusmetrics.PrometheusConfig +import io.micrometer.prometheusmetrics.PrometheusMeterRegistry import java.util.concurrent.atomic.AtomicInteger interface EnvoyControlMetrics { @@ -21,7 +22,7 @@ data class DefaultEnvoyControlMetrics( val snapshotChanges: AtomicInteger = AtomicInteger(), val cacheGroupsCount: AtomicInteger = AtomicInteger(), val errorWatchingServices: AtomicInteger = AtomicInteger(), - override val meterRegistry: MeterRegistry = SimpleMeterRegistry() + override val meterRegistry: MeterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT) ) : EnvoyControlMetrics { override fun errorWatchingServices() { diff --git a/envoy-control-runner/build.gradle b/envoy-control-runner/build.gradle index fafd8f611..273660343 100644 --- a/envoy-control-runner/build.gradle +++ b/envoy-control-runner/build.gradle @@ -11,7 +11,7 @@ dependencies { api group: 'org.springframework.boot', name: 'spring-boot-starter-web' api group: 'org.springframework.boot', name: 'spring-boot-starter-actuator' api group: 'org.springframework.boot', name: 'spring-boot-starter-security' - implementation group: 'io.micrometer', name: 'micrometer-registry-prometheus' + api group: 'io.micrometer', name: 'micrometer-registry-prometheus' implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin' implementation group: 'net.openhft', name: 'zero-allocation-hashing', version: versions.xxhash diff --git a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/debug/SnapshotDebugController.kt b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/debug/SnapshotDebugController.kt index 414c33888..bcfcac981 100644 --- a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/debug/SnapshotDebugController.kt +++ b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/debug/SnapshotDebugController.kt @@ -24,6 +24,7 @@ import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContex import io.envoyproxy.envoy.type.matcher.PathMatcher import io.envoyproxy.envoy.type.matcher.StringMatcher import io.micrometer.core.instrument.MeterRegistry +import io.micrometer.prometheusmetrics.PrometheusMeterRegistry import org.springframework.boot.jackson.JsonComponent import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity @@ -85,6 +86,15 @@ class SnapshotDebugController( } catch (e: Exception) { stringBuilder.append(e.message) } + + try { + if (meterRegistry is PrometheusMeterRegistry) { + stringBuilder.append("Prometheus") + .append((meterRegistry as PrometheusMeterRegistry).scrape()) + } + } catch (e: Exception) { + stringBuilder.append(e.message) + } return ResponseEntity( stringBuilder.toString(), HttpStatus.OK diff --git a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/MetricsDiscoveryServerCallbacksTest.kt b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/MetricsDiscoveryServerCallbacksTest.kt index b7c9fda0a..66ea05672 100644 --- a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/MetricsDiscoveryServerCallbacksTest.kt +++ b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/MetricsDiscoveryServerCallbacksTest.kt @@ -20,8 +20,8 @@ import pl.allegro.tech.servicemesh.envoycontrol.server.callbacks.MetricsDiscover import pl.allegro.tech.servicemesh.envoycontrol.server.callbacks.MetricsDiscoveryServerCallbacks.StreamType.RDS import pl.allegro.tech.servicemesh.envoycontrol.server.callbacks.MetricsDiscoveryServerCallbacks.StreamType.SDS import pl.allegro.tech.servicemesh.envoycontrol.server.callbacks.MetricsDiscoveryServerCallbacks.StreamType.UNKNOWN -import pl.allegro.tech.servicemesh.envoycontrol.utils.CONNECTION_TYPE_TAG import pl.allegro.tech.servicemesh.envoycontrol.utils.CONNECTIONS_METRIC +import pl.allegro.tech.servicemesh.envoycontrol.utils.CONNECTION_TYPE_TAG import pl.allegro.tech.servicemesh.envoycontrol.utils.DISCOVERY_REQ_TYPE_TAG import pl.allegro.tech.servicemesh.envoycontrol.utils.REQUESTS_METRIC import pl.allegro.tech.servicemesh.envoycontrol.utils.STREAM_TYPE_TAG