Skip to content

Commit

Permalink
Merge branch '3.0.x' into 3.1.x
Browse files Browse the repository at this point in the history
Closes gh-36553
  • Loading branch information
wilkinsona committed Jul 25, 2023
2 parents 6f69f64 + 826bad5 commit 5d1b234
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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 @@ -54,6 +54,11 @@ public class SignalFxProperties extends StepRegistryProperties {
*/
private String source;

/**
* Type of histogram to publish.
*/
private HistogramType publishedHistogramType = HistogramType.DEFAULT;

@Override
public Duration getStep() {
return this.step;
Expand Down Expand Up @@ -88,4 +93,31 @@ public void setSource(String source) {
this.source = source;
}

public HistogramType getPublishedHistogramType() {
return this.publishedHistogramType;
}

public void setPublishedHistogramType(HistogramType publishedHistogramType) {
this.publishedHistogramType = publishedHistogramType;
}

public enum HistogramType {

/**
* Default, time-based histogram.
*/
DEFAULT,

/**
* Cumulative histogram.
*/
CUMULATIVE,

/**
* Delta histogram.
*/
DELTA;

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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 @@ -19,6 +19,7 @@
import io.micrometer.signalfx.SignalFxConfig;

import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType;

/**
* Adapter to convert {@link SignalFxProperties} to a {@link SignalFxConfig}.
Expand Down Expand Up @@ -54,4 +55,22 @@ public String source() {
return get(SignalFxProperties::getSource, SignalFxConfig.super::source);
}

@Override
public boolean publishCumulativeHistogram() {
return get(this::isPublishCumulativeHistogram, SignalFxConfig.super::publishCumulativeHistogram);
}

private boolean isPublishCumulativeHistogram(SignalFxProperties properties) {
return HistogramType.CUMULATIVE == properties.getPublishedHistogramType();
}

@Override
public boolean publishDeltaHistogram() {
return get(this::isPublishDeltaHistogram, SignalFxConfig.super::publishDeltaHistogram);
}

private boolean isPublishDeltaHistogram(SignalFxProperties properties) {
return HistogramType.DELTA == properties.getPublishedHistogramType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.Test;

import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests;
import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -62,4 +63,20 @@ void whenPropertiesSourceIsSetAdapterSourceReturnsIt() {
assertThat(createConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5");
}

@Test
void whenPropertiesPublishHistogramTypeIsCumulativePublishCumulativeHistogramReturnsIt() {
SignalFxProperties properties = createProperties();
properties.setPublishedHistogramType(HistogramType.CUMULATIVE);
assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isTrue();
assertThat(createConfigAdapter(properties).publishDeltaHistogram()).isFalse();
}

@Test
void whenPropertiesPublishHistogramTypeIsDeltaPublishDeltaHistogramReturnsIt() {
SignalFxProperties properties = createProperties();
properties.setPublishedHistogramType(HistogramType.DELTA);
assertThat(createConfigAdapter(properties).publishDeltaHistogram()).isTrue();
assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isFalse();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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 org.junit.jupiter.api.Test;

import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesTests;
import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -38,6 +39,11 @@ void defaultValuesAreConsistent() {
// access token is mandatory
assertThat(properties.getUri()).isEqualTo(config.uri());
// source has no static default value
// Not publishing cumulative or delta histograms implies that the default
// histogram type should be published.
assertThat(config.publishCumulativeHistogram()).isFalse();
assertThat(config.publishDeltaHistogram()).isFalse();
assertThat(properties.getPublishedHistogramType()).isEqualTo(HistogramType.DEFAULT);
}

}

0 comments on commit 5d1b234

Please sign in to comment.