Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 4be0e17

Browse files
author
Mateusz Rzeszutek
authored
Merge pull request #207 from signalfx/micrometer-temp
Temporary fork of micrometer-signalfx-registry lib with histogram fix
2 parents db1ba94 + 6454b2f commit 4be0e17

13 files changed

+1485
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.signalfx.public</groupId>
9+
<artifactId>clients-parent</artifactId>
10+
<version>1.0.14</version>
11+
</parent>
12+
13+
<artifactId>micrometer-registry-signalfx</artifactId>
14+
<name>Micrometer Registry for SignalFx</name>
15+
<packaging>jar</packaging>
16+
<description>
17+
A temporary fork of the io.micrometer:micrometer-registry-signalfx project
18+
</description>
19+
<version>1.8.4-splunk1</version>
20+
21+
<url>https://www.signalfx.com</url>
22+
23+
<licenses>
24+
<license>
25+
<name>Apache License 2.0</name>
26+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
27+
<distribution>repo</distribution>
28+
</license>
29+
</licenses>
30+
31+
<scm>
32+
<connection>scm:git:[email protected]:signalfx/signalfx-java.git</connection>
33+
<developerConnection>scm:git:[email protected]:signalfx/signalfx-java.git</developerConnection>
34+
<url>[email protected]:signalfx/signalfx-java.git</url>
35+
</scm>
36+
37+
<developers>
38+
<developer>
39+
<id>signalfx</id>
40+
<name>SignalFx</name>
41+
<email>[email protected]</email>
42+
<organization>SignalFx, Inc</organization>
43+
<organizationUrl>http://www.signalfx.com</organizationUrl>
44+
</developer>
45+
</developers>
46+
47+
<dependencies>
48+
<!-- compile -->
49+
<dependency>
50+
<groupId>com.signalfx.public</groupId>
51+
<artifactId>signalfx-java</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.slf4j</groupId>
55+
<artifactId>slf4j-api</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>io.micrometer</groupId>
59+
<artifactId>micrometer-core</artifactId>
60+
<version>1.8.4</version>
61+
</dependency>
62+
63+
<!-- test -->
64+
<dependency>
65+
<groupId>org.slf4j</groupId>
66+
<artifactId>slf4j-simple</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.hamcrest</groupId>
70+
<artifactId>hamcrest-core</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>io.micrometer</groupId>
74+
<artifactId>micrometer-test</artifactId>
75+
<version>1.8.3</version>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.junit.jupiter</groupId>
80+
<artifactId>junit-jupiter-api</artifactId>
81+
<version>5.8.2</version>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.junit.jupiter</groupId>
86+
<artifactId>junit-jupiter-engine</artifactId>
87+
<version>5.8.2</version>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
</dependencies>
92+
93+
<build>
94+
<plugins>
95+
<!-- skip the shading for this artifact -->
96+
<plugin>
97+
<groupId>org.apache.maven.plugins</groupId>
98+
<artifactId>maven-shade-plugin</artifactId>
99+
<version>3.2.4</version>
100+
<executions>
101+
<execution>
102+
<id>build-shaded-jar</id>
103+
<phase>none</phase>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
<!-- use a newer version for junit5 support -->
108+
<plugin>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-surefire-plugin</artifactId>
111+
<version>3.0.0-M3</version>
112+
</plugin>
113+
</plugins>
114+
</build>
115+
</project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright Splunk Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Includes work from:
18+
/*
19+
* Copyright 2017 VMware, Inc.
20+
*
21+
* Licensed under the Apache License, Version 2.0 (the "License");
22+
* you may not use this file except in compliance with the License.
23+
* You may obtain a copy of the License at
24+
*
25+
* https://www.apache.org/licenses/LICENSE-2.0
26+
*
27+
* Unless required by applicable law or agreed to in writing, software
28+
* distributed under the License is distributed on an "AS IS" BASIS,
29+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30+
* See the License for the specific language governing permissions and
31+
* limitations under the License.
32+
*/
33+
package io.micrometer.signalfx;
34+
35+
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
36+
37+
import java.time.Duration;
38+
import java.util.Arrays;
39+
40+
final class CumulativeHistogramConfigUtil {
41+
42+
static DistributionStatisticConfig updateConfig(
43+
DistributionStatisticConfig distributionStatisticConfig) {
44+
double[] sloBoundaries = distributionStatisticConfig.getServiceLevelObjectiveBoundaries();
45+
if (sloBoundaries == null || sloBoundaries.length == 0) {
46+
return distributionStatisticConfig;
47+
}
48+
double[] newSLA = sloBoundaries;
49+
// Add the +Inf bucket since the "count" resets every export.
50+
if (!isPositiveInf(sloBoundaries[sloBoundaries.length - 1])) {
51+
newSLA = Arrays.copyOf(sloBoundaries, sloBoundaries.length + 1);
52+
newSLA[newSLA.length - 1] = Double.MAX_VALUE;
53+
}
54+
return DistributionStatisticConfig.builder()
55+
// Set the expiration duration for the histogram counts to be effectively a lifetime.
56+
// Without this, the counts are reset every expiry duration.
57+
.expiry(Duration.ofNanos(Long.MAX_VALUE)) // effectively a lifetime
58+
.bufferLength(1)
59+
.serviceLevelObjectives(newSLA)
60+
.build()
61+
.merge(distributionStatisticConfig);
62+
}
63+
64+
private static boolean isPositiveInf(double bucket) {
65+
return bucket == Double.POSITIVE_INFINITY || bucket == Double.MAX_VALUE || (long) bucket == Long.MAX_VALUE;
66+
}
67+
68+
private CumulativeHistogramConfigUtil() {
69+
}
70+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright Splunk Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Includes work from:
18+
/*
19+
* Copyright 2017 VMware, Inc.
20+
*
21+
* Licensed under the Apache License, Version 2.0 (the "License");
22+
* you may not use this file except in compliance with the License.
23+
* You may obtain a copy of the License at
24+
*
25+
* https://www.apache.org/licenses/LICENSE-2.0
26+
*
27+
* Unless required by applicable law or agreed to in writing, software
28+
* distributed under the License is distributed on an "AS IS" BASIS,
29+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30+
* See the License for the specific language governing permissions and
31+
* limitations under the License.
32+
*/
33+
package io.micrometer.signalfx;
34+
35+
import io.micrometer.core.instrument.config.validate.Validated;
36+
import io.micrometer.core.instrument.step.StepRegistryConfig;
37+
38+
import java.net.InetAddress;
39+
import java.net.UnknownHostException;
40+
import java.time.Duration;
41+
42+
import static io.micrometer.core.instrument.config.MeterRegistryConfigValidator.checkAll;
43+
import static io.micrometer.core.instrument.config.MeterRegistryConfigValidator.checkRequired;
44+
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getBoolean;
45+
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getDuration;
46+
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getSecret;
47+
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getString;
48+
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getUrlString;
49+
50+
/**
51+
* Configuration for {@link SignalFxMeterRegistry}.
52+
*
53+
* @author Jon Schneider
54+
*/
55+
public interface SignalFxConfig extends StepRegistryConfig {
56+
57+
@Override
58+
default String prefix() {
59+
return "signalfx";
60+
}
61+
62+
default String accessToken() {
63+
return getSecret(this, "accessToken").required().get();
64+
}
65+
66+
/**
67+
* @return {@code true} if the SignalFx registry should emit cumulative histogram buckets.
68+
*/
69+
default boolean publishCumulativeHistogram() {
70+
return getBoolean(this, "publishCumulativeHistogram").orElse(false);
71+
}
72+
73+
/**
74+
* @return The URI to ship metrics to. If you need to publish metrics to an internal proxy en route to
75+
* SignalFx, you can define the location of the proxy with this.
76+
*/
77+
default String uri() {
78+
// NOTE: at some point, the property 'apiHost' diverged from the name of the method 'uri', so we accept
79+
// either here for backwards compatibility.
80+
return getUrlString(this, "apiHost")
81+
.flatMap((uri, valid) -> uri == null ? getUrlString(this, "uri") : valid)
82+
.orElse("https://ingest.signalfx.com");
83+
}
84+
85+
/**
86+
* @return Unique identifier for the app instance that is publishing metrics to SignalFx. Defaults to the local host name.
87+
*/
88+
default String source() {
89+
return getString(this, "source").orElseGet(() -> {
90+
try {
91+
return InetAddress.getLocalHost().getHostName();
92+
} catch (UnknownHostException uhe) {
93+
return "unknown";
94+
}
95+
});
96+
}
97+
98+
@Override
99+
default Duration step() {
100+
return getDuration(this, "step").orElse(Duration.ofSeconds(10));
101+
}
102+
103+
@Override
104+
default Validated<?> validate() {
105+
return checkAll(this,
106+
c -> StepRegistryConfig.validate(c),
107+
checkRequired("accessToken", SignalFxConfig::accessToken),
108+
checkRequired("uri", SignalFxConfig::uri),
109+
checkRequired("source", SignalFxConfig::source)
110+
);
111+
}
112+
}

0 commit comments

Comments
 (0)