Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus for management #1693

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/latest/consumers/consumers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ consumer:
graphite:
host: "graphite"
metrics:
graphiteReporterEnabled: true
metric-registry:
graphiteReporterEnabled: true
workload:
consumerPerSubscription: 1
schema:
Expand Down
3 changes: 2 additions & 1 deletion docker/latest/frontend/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ frontend:
graphite:
host: "graphite"
metrics:
graphiteReporterEnabled: true
metric-registry:
graphiteReporterEnabled: true
schema:
cache:
refreshAfterWrite: 1m
Expand Down
5 changes: 1 addition & 4 deletions docker/latest/management/management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ management:
enabled: true
consumer-groups:
create-manually: true
metrics:
export:
prometheus:
enabled: false


audit.enabled: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pl.allegro.tech.hermes.api.Topic;
import pl.allegro.tech.hermes.common.clock.ClockFactory;
import pl.allegro.tech.hermes.common.di.factories.MicrometerRegistryParameters;
import pl.allegro.tech.hermes.common.di.factories.PrometheusMeterRegistryFactory;
import pl.allegro.tech.hermes.management.domain.subscription.SubscriptionLagSource;
import pl.allegro.tech.hermes.management.infrastructure.metrics.NoOpSubscriptionLagSource;

Expand All @@ -26,7 +28,10 @@
TopicProperties.class,
MetricsProperties.class,
HttpClientProperties.class,
ConsistencyCheckerProperties.class})
ConsistencyCheckerProperties.class,
PrometheusProperties.class,
MicrometerRegistryProperties.class
})
public class ManagementConfiguration {

@Autowired
Expand Down Expand Up @@ -57,8 +62,16 @@ public MetricRegistry metricRegistry() {

@Bean
@ConditionalOnMissingBean
public MeterRegistry micrometerRegistry() {
return new SimpleMeterRegistry();
public PrometheusMeterRegistry micrometerRegistry(MicrometerRegistryParameters micrometerRegistryParameters,
PrometheusConfig prometheusConfig) {
return new PrometheusMeterRegistryFactory(micrometerRegistryParameters,
prometheusConfig, "hermes-management").provide();
}

@Bean
@ConditionalOnMissingBean
PrometheusConfig prometheusConfig(PrometheusProperties properties) {
return new PrometheusConfigAdapter(properties);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pl.allegro.tech.hermes.management.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import pl.allegro.tech.hermes.common.di.factories.MicrometerRegistryParameters;

import java.util.List;

@ConfigurationProperties(prefix = "metrics.micrometer")
public class MicrometerRegistryProperties implements MicrometerRegistryParameters {

private List<Double> percentiles = List.of(0.5, 0.99, 0.999);

@Override
public List<Double> getPercentiles() {
return percentiles;
}

public void setPercentiles(List<Double> percentiles) {
this.percentiles = percentiles;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pl.allegro.tech.hermes.management.config;

import io.micrometer.prometheus.PrometheusConfig;

import java.time.Duration;

public class PrometheusConfigAdapter implements PrometheusConfig {

private final PrometheusProperties prometheusReporterProperties;

public PrometheusConfigAdapter(PrometheusProperties prometheusReporterProperties) {
this.prometheusReporterProperties = prometheusReporterProperties;
}

@Override
public boolean descriptions() {
return prometheusReporterProperties.isDescriptions();
}

@Override
public Duration step() {
return prometheusReporterProperties.getStep();
}

/**
* Returning null is fine since we override all the methods from PrometheusConfig.
*/
@Override
public String get(String key) {
return null; // Nothing to see here, move along.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pl.allegro.tech.hermes.management.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.time.Duration;

@ConfigurationProperties(prefix = "metrics.prometheus")
public class PrometheusProperties {

private Duration step = Duration.ofMinutes(1);
private boolean descriptions = true;

public Duration getStep() {
return this.step;
}

public void setStep(Duration step) {
this.step = step;
}

public boolean isDescriptions() {
return this.descriptions;
}

public void setDescriptions(boolean descriptions) {
this.descriptions = descriptions;
}
}
11 changes: 3 additions & 8 deletions hermes-management/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,15 @@ server:
management:
endpoints:
web:
base-path: /
base-path: /status
exposure:
include: health, prometheus
rest-template:
connect-timeout: 2000
read-timeout: 2000
server:
servlet:
context-path: /
health:
periodSeconds: 30
enabled: true
metrics:
export:
prometheus:
enabled: false

audit:
isLoggingAuditEnabled: false
Expand Down
4 changes: 0 additions & 4 deletions hermes-management/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ storage:
connectionString: localhost:42182

# this is a hack to make /status/* endpoints work with Jersey
management:
server:
servlet:
context-path: /
spring:
mvc:
servlet:
Expand Down
7 changes: 0 additions & 7 deletions integration/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ management:
endpoints:
web:
base-path: /status
server:
servlet:
context-path: /
metrics:
export:
prometheus:
enabled: false

spring.groovy.template.check-template-location: false

Expand Down
Loading