Skip to content

Commit

Permalink
Upgrade to micrometer:1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
runeflobakk committed Jun 3, 2024
1 parent 36c9d1e commit f1350d2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 59 deletions.
11 changes: 6 additions & 5 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ This software includes third party software subject to the following licenses:
micrometer-core under The Apache Software License, Version 2.0
micrometer-observation under The Apache Software License, Version 2.0
micrometer-registry-prometheus under The Apache Software License, Version 2.0
Prometheus Java Simpleclient under The Apache Software License, Version 2.0
Prometheus Java Simpleclient Common under The Apache Software License, Version 2.0
Prometheus Java Span Context Supplier - Common under The Apache Software License, Version 2.0
Prometheus Java Span Context Supplier - OpenTelemetry under The Apache Software License, Version 2.0
Prometheus Java Span Context Supplier - OpenTelemetry Agent under The Apache Software License, Version 2.0
Prometheus Metrics Config under The Apache Software License, Version 2.0
Prometheus Metrics Core under The Apache Software License, Version 2.0
Prometheus Metrics Exposition Formats under The Apache Software License, Version 2.0
Prometheus Metrics Model under The Apache Software License, Version 2.0
Prometheus Metrics Tracer Common under The Apache Software License, Version 2.0
Shaded Protobuf under The Apache Software License, Version 2.0

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-bom</artifactId>
<version>1.12.6</version>
<version>1.13.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package no.digipost.monitoring.prometheus;

import com.sun.net.httpserver.HttpServer;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;

import java.io.IOException;
import java.io.OutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package no.digipost.monitoring;

import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import no.digipost.monitoring.logging.LogbackLoggerMetrics;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -44,8 +44,8 @@ void test_named_logger() {
LoggerFactory.getLogger("test").error("error");
LoggerFactory.getLogger("another.logger").error("another error");

assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"warn\",logger=\"test\",} 2.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"test\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"warn\",logger=\"test\"} 2.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"test\"} 1.0"));
}

@Test
Expand All @@ -55,8 +55,8 @@ void test_root_logger() {
LoggerFactory.getLogger("test").error("error");
LoggerFactory.getLogger("test").warn("warn");

assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"warn\",logger=\"ROOT\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"ROOT\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"warn\",logger=\"ROOT\"} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"ROOT\"} 1.0"));
}

@Test
Expand All @@ -67,8 +67,8 @@ void test_both_root_and_named_logger() {
LoggerFactory.getLogger("test").error("error"); // counted by both
LoggerFactory.getLogger("another.logger").error("error"); // counted by root

assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"ROOT\",} 2.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"test\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"ROOT\"} 2.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"test\"} 1.0"));
}

@Test
Expand All @@ -82,7 +82,7 @@ void test_excluded_loggers_should_not_be_included_in_count() {
LoggerFactory.getLogger("also.ignored").error("error");
LoggerFactory.getLogger("another.logger").error("error"); // counted by root

assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"ROOT\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("logback_logger_events_total{level=\"error\",logger=\"ROOT\"} 1.0"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package no.digipost.monitoring.event;

import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -40,40 +40,40 @@ void setUp() {
@Test
void should_register_event() {
eventLogger.log(MyBusinessEvents.VIOLATION);
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION\"} 1.0"));
assertThat(prometheusRegistry.scrape(), not(containsString("app_business_events_1min_warn_thresholds")));
assertThat(prometheusRegistry.scrape(), not(containsString("app_business_events_1min_error_thresholds")));
}

@Test
void should_register_event_with_warn() {
eventLogger.log(MyBusinessEvents.VIOLATION_WITH_WARN);
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION_WITH_WARN\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_warn_thresholds{name=\"VIOLATION_WITH_WARN\",} 5.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION_WITH_WARN\"} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_warn_thresholds{name=\"VIOLATION_WITH_WARN\"} 5.0"));
assertThat(prometheusRegistry.scrape(), not(containsString("app_business_events_1min_error_thresholds")));
}

@Test
void should_register_event_with_error() {
eventLogger.log(MyBusinessEvents.VIOLATION_WITH_ERROR);
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION_WITH_ERROR\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION_WITH_ERROR\"} 1.0"));
assertThat(prometheusRegistry.scrape(), not(containsString("app_business_events_1min_warn_thresholds")));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_error_thresholds{name=\"VIOLATION_WITH_ERROR\",} 5.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_error_thresholds{name=\"VIOLATION_WITH_ERROR\"} 5.0"));
}

@Test
void should_register_event_with_warn_and_error() {
eventLogger.log(MyBusinessEvents.VIOLATION_WITH_WARN_AND_ERROR);
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION_WITH_WARN_AND_ERROR\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_warn_thresholds{name=\"VIOLATION_WITH_WARN_AND_ERROR\",} 5.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_error_thresholds{name=\"VIOLATION_WITH_WARN_AND_ERROR\",} 5.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_total{name=\"VIOLATION_WITH_WARN_AND_ERROR\"} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_warn_thresholds{name=\"VIOLATION_WITH_WARN_AND_ERROR\"} 5.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_business_events_1min_error_thresholds{name=\"VIOLATION_WITH_WARN_AND_ERROR\"} 5.0"));
}

@Test
void check_that_values_are_not_GCed() {
eventLogger.log(MyBusinessEvents.VIOLATION_WITH_WARN_AND_ERROR, 1337);
Runtime.getRuntime().gc();

assertThat(prometheusRegistry.scrape(), not(containsString("NaN")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package no.digipost.monitoring.logging;

import ch.qos.logback.classic.Logger;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -41,9 +41,9 @@ public void should_create_metrics_for_warn_and_error_threshold(){
.errorThreshold5min(5)
.bindTo(prometheusRegistry);
String scrape = prometheusRegistry.scrape();
assertThat(scrape, containsString("log_events_5min_threshold{level=\"warn\",logger=\"ROOT\",} 10.0"));
assertThat(scrape, containsString("log_events_5min_threshold{level=\"error\",logger=\"ROOT\",} 5.0"));

assertThat(scrape, containsString("log_events_5min_threshold{level=\"warn\",logger=\"ROOT\"} 10.0"));
assertThat(scrape, containsString("log_events_5min_threshold{level=\"error\",logger=\"ROOT\"} 5.0"));
}

@Test
Expand All @@ -52,8 +52,8 @@ public void should_only_create_metric_for_warn_threshold(){
.warnThreshold5min(10)
.bindTo(prometheusRegistry);
String scrape = prometheusRegistry.scrape();
assertThat(scrape, containsString("log_events_5min_threshold{level=\"warn\",logger=\"ROOT\",} 10.0"));

assertThat(scrape, containsString("log_events_5min_threshold{level=\"warn\",logger=\"ROOT\"} 10.0"));
assertThat(scrape, not(containsString("log_events_5min_threshold{level=\"error\"")));
}

Expand All @@ -62,8 +62,8 @@ public void should_not_create_metrics_for_threshold(){
LogbackLoggerMetrics.forLogger(Logger.ROOT_LOGGER_NAME)
.bindTo(prometheusRegistry);
String scrape = prometheusRegistry.scrape();

assertThat(scrape, not(containsString("log_events_5min_threshold")));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package no.digipost.monitoring.micrometer;

import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;

import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package no.digipost.monitoring.servlet;

import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import no.digipost.monitoring.servlet.ActiveRequestsFilter.RequestMetaInfo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package no.digipost.monitoring.thirdparty;

import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import no.digipost.monitoring.micrometer.AppStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,7 +46,7 @@ void should_return_OK_and_record_timing() {
.exceptionAsFailure();

final String result = getStuff.call(() -> "OK");

assertThat(result, is(equalTo("OK")));

assertSendOK();
Expand Down Expand Up @@ -150,8 +150,8 @@ void define_percentiles() {
.exceptionAsFailure();

getStuff.call(() -> new MyResponse("OK"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.17\",}"));

assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.17\"}"));
}

@Test
Expand All @@ -177,25 +177,25 @@ void exception_should_propagate_and_record_failed_request() {
}

void assertSendOK() {
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"OK\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"FAILED\",} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds_count{name=\"ExternalService_getStuff\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.95\",}"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.99\",}"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.5\",}"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"OK\"} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"FAILED\"} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds_count{name=\"ExternalService_getStuff\"} 1"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.95\"}"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.99\"}"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds{name=\"ExternalService_getStuff\",quantile=\"0.5\"}"));
}

void assertSendFailed() {
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"OK\",} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"FAILED\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds_count{name=\"ExternalService_getStuff\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"OK\"} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"FAILED\"} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds_count{name=\"ExternalService_getStuff\"} 1"));
}

void assertSendWarn() {
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"OK\",} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"FAILED\",} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"WARN\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds_count{name=\"ExternalService_getStuff\",} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"OK\"} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"FAILED\"} 0.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_total{name=\"ExternalService_getStuff\",status=\"WARN\"} 1.0"));
assertThat(prometheusRegistry.scrape(), containsString("app_third_party_call_seconds_count{name=\"ExternalService_getStuff\"} 1"));
}

static class MyResponse {
Expand Down

0 comments on commit f1350d2

Please sign in to comment.