Skip to content

Commit

Permalink
Add configuration support for ExponentialHistogram in OTLP Registry
Browse files Browse the repository at this point in the history
Closes gh-41837
  • Loading branch information
snicoll committed Sep 6, 2024
1 parent 807a38f commit 6cd6f75
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.util.concurrent.TimeUnit;

import io.micrometer.registry.otlp.AggregationTemporality;
import io.micrometer.registry.otlp.HistogramFlavor;

import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down Expand Up @@ -57,6 +58,22 @@ public class OtlpProperties extends StepRegistryProperties {
*/
private Map<String, String> headers;

/**
* Histogram type to be preferred when histogram publishing is enabled.
*/
private HistogramFlavor histogramFlavor = HistogramFlavor.EXPLICIT_BUCKET_HISTOGRAM;

/**
* Max scale to use for exponential histograms, if configured.
*/
private int maxScale = 20;

/**
* Maximum number of buckets to be used for exponential histograms, if configured.
* This has no effect on explicit bucket histograms.
*/
private int maxBucketCount = 160;

/**
* Time unit for exported metrics.
*/
Expand Down Expand Up @@ -97,6 +114,30 @@ public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

public HistogramFlavor getHistogramFlavor() {
return this.histogramFlavor;
}

public void setHistogramFlavor(HistogramFlavor histogramFlavor) {
this.histogramFlavor = histogramFlavor;
}

public int getMaxScale() {
return this.maxScale;
}

public void setMaxScale(int maxScale) {
this.maxScale = maxScale;
}

public int getMaxBucketCount() {
return this.maxBucketCount;
}

public void setMaxBucketCount(int maxBucketCount) {
this.maxBucketCount = maxBucketCount;
}

public TimeUnit getBaseTimeUnit() {
return this.baseTimeUnit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.TimeUnit;

import io.micrometer.registry.otlp.AggregationTemporality;
import io.micrometer.registry.otlp.HistogramFlavor;
import io.micrometer.registry.otlp.OtlpConfig;

import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
Expand Down Expand Up @@ -98,6 +99,21 @@ public Map<String, String> headers() {
return get(OtlpProperties::getHeaders, OtlpConfig.super::headers);
}

@Override
public HistogramFlavor histogramFlavor() {
return get(OtlpProperties::getHistogramFlavor, OtlpConfig.super::histogramFlavor);
}

@Override
public int maxScale() {
return get(OtlpProperties::getMaxScale, OtlpConfig.super::maxScale);
}

@Override
public int maxBucketCount() {
return get(OtlpProperties::getMaxBucketCount, OtlpConfig.super::maxBucketCount);
}

@Override
public TimeUnit baseTimeUnit() {
return get(OtlpProperties::getBaseTimeUnit, OtlpConfig.super::baseTimeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.TimeUnit;

import io.micrometer.registry.otlp.AggregationTemporality;
import io.micrometer.registry.otlp.HistogramFlavor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -85,6 +86,39 @@ void whenPropertiesHeadersIsSetAdapterHeadersReturnsIt() {
assertThat(createAdapter().headers()).containsEntry("header", "value");
}

@Test
void whenPropertiesHistogramFlavorIsNotSetAdapterHistogramFlavorReturnsExplicitBucketHistogram() {
assertThat(createAdapter().histogramFlavor()).isSameAs(HistogramFlavor.EXPLICIT_BUCKET_HISTOGRAM);
}

@Test
void whenPropertiesHistogramFlavorIsSetAdapterHistogramFlavorReturnsIt() {
this.properties.setHistogramFlavor(HistogramFlavor.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM);
assertThat(createAdapter().histogramFlavor()).isSameAs(HistogramFlavor.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM);
}

@Test
void whenPropertiesMaxScaleIsNotSetAdapterMaxScaleReturns20() {
assertThat(createAdapter().maxScale()).isEqualTo(20);
}

@Test
void whenPropertiesMaxScaleIsSetAdapterMaxScaleReturnsIt() {
this.properties.setMaxScale(5);
assertThat(createAdapter().maxScale()).isEqualTo(5);
}

@Test
void whenPropertiesMaxBucketCountIsNotSetAdapterMaxBucketCountReturns160() {
assertThat(createAdapter().maxBucketCount()).isEqualTo(160);
}

@Test
void whenPropertiesMaxBucketCountIsSetAdapterMaxBucketCountReturnsIt() {
this.properties.setMaxBucketCount(6);
assertThat(createAdapter().maxBucketCount()).isEqualTo(6);
}

@Test
void whenPropertiesBaseTimeUnitIsNotSetAdapterBaseTimeUnitReturnsMillis() {
assertThat(createAdapter().baseTimeUnit()).isSameAs(TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,9 @@ void defaultValuesAreConsistent() {
assertStepRegistryDefaultValues(properties, config);
assertThat(properties.getUrl()).isEqualTo(config.url());
assertThat(properties.getAggregationTemporality()).isSameAs(config.aggregationTemporality());
assertThat(properties.getHistogramFlavor()).isSameAs(config.histogramFlavor());
assertThat(properties.getMaxScale()).isEqualTo(config.maxScale());
assertThat(properties.getMaxBucketCount()).isEqualTo(config.maxBucketCount());
assertThat(properties.getBaseTimeUnit()).isSameAs(config.baseTimeUnit());
}

Expand Down

0 comments on commit 6cd6f75

Please sign in to comment.