-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add capability to correctly export fixed buckets histogram to SignalFx #2977
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
Merged
jonatan-ivanov
merged 5 commits into
micrometer-metrics:1.9.x
from
bogdandrutu:testgauge
Mar 18, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b66025e
Add capability to correctly export fixed buckets histogram to SignalFx
bogdandrutu 37b6434
Address feedback
bogdandrutu 09f2c52
Make SignalFx histograms cumulative without breaking max()
79693ed
Hide DistributionStatisticsConfig changes behind a config flag
066d4a7
Polishing pass
jonatan-ivanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...registry-signalfx/src/main/java/io/micrometer/signalfx/CumulativeHistogramConfigUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright 2022 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.signalfx; | ||
|
|
||
| import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Adds cumulative histogram capabilities to the {@link DistributionStatisticConfig}. | ||
| * | ||
| * @author Bogdan Drutu | ||
| * @author Mateusz Rzeszutek | ||
| */ | ||
| final class CumulativeHistogramConfigUtil { | ||
|
|
||
| static DistributionStatisticConfig updateConfig(DistributionStatisticConfig distributionStatisticConfig) { | ||
| double[] sloBoundaries = distributionStatisticConfig.getServiceLevelObjectiveBoundaries(); | ||
| if (sloBoundaries == null || sloBoundaries.length == 0) { | ||
| return distributionStatisticConfig; | ||
| } | ||
| double[] newSloBoundaries = sloBoundaries; | ||
| // Add the +Inf bucket since the "count" resets every export. | ||
| if (!isPositiveInf(sloBoundaries[sloBoundaries.length - 1])) { | ||
| newSloBoundaries = Arrays.copyOf(sloBoundaries, sloBoundaries.length + 1); | ||
| newSloBoundaries[newSloBoundaries.length - 1] = Double.MAX_VALUE; | ||
| } | ||
|
|
||
| return DistributionStatisticConfig.builder() | ||
| // Set the expiration duration for the histogram counts to be effectively infinite. | ||
| // Without this, the counts are reset every expiry duration. | ||
| .expiry(Duration.ofNanos(Long.MAX_VALUE)) // effectively infinite | ||
| .bufferLength(1) | ||
| .serviceLevelObjectives(newSloBoundaries) | ||
| .build() | ||
| .merge(distributionStatisticConfig); | ||
| } | ||
|
|
||
| private static boolean isPositiveInf(double bucket) { | ||
| return bucket == Double.POSITIVE_INFINITY || bucket == Double.MAX_VALUE || (long) bucket == Long.MAX_VALUE; | ||
| } | ||
|
|
||
| private CumulativeHistogramConfigUtil() { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...r-registry-signalfx/src/main/java/io/micrometer/signalfx/SignalfxDistributionSummary.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2022 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.signalfx; | ||
|
|
||
| import io.micrometer.core.instrument.AbstractDistributionSummary; | ||
| import io.micrometer.core.instrument.Clock; | ||
| import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||
| import io.micrometer.core.instrument.distribution.TimeWindowMax; | ||
| import io.micrometer.core.instrument.step.StepTuple2; | ||
|
|
||
| import java.util.concurrent.atomic.DoubleAdder; | ||
| import java.util.concurrent.atomic.LongAdder; | ||
|
|
||
| /** | ||
| * This class is mostly the same as {@link io.micrometer.core.instrument.step.StepDistributionSummary}, with one notable | ||
| * difference: the {@link DistributionStatisticConfig} is modified before being passed to the super class constructor - | ||
| * that forces the histogram generated by this meter to be cumulative. | ||
| * | ||
| * @author Bogdan Drutu | ||
| * @author Mateusz Rzeszutek | ||
| */ | ||
| final class SignalfxDistributionSummary extends AbstractDistributionSummary { | ||
|
|
||
| private final LongAdder count = new LongAdder(); | ||
| private final DoubleAdder total = new DoubleAdder(); | ||
| private final StepTuple2<Long, Double> countTotal; | ||
| private final TimeWindowMax max; | ||
|
|
||
| SignalfxDistributionSummary(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, double scale, long stepMillis) { | ||
| super(id, clock, CumulativeHistogramConfigUtil.updateConfig(distributionStatisticConfig), scale, false); | ||
| this.countTotal = new StepTuple2<>(clock, stepMillis, 0L, 0.0, count::sumThenReset, total::sumThenReset); | ||
| max = new TimeWindowMax(clock, distributionStatisticConfig); | ||
| } | ||
|
|
||
| @Override | ||
| protected void recordNonNegative(double amount) { | ||
| count.increment(); | ||
| total.add(amount); | ||
| max.record(amount); | ||
| } | ||
|
|
||
| @Override | ||
| public long count() { | ||
| return countTotal.poll1(); | ||
| } | ||
|
|
||
| @Override | ||
| public double totalAmount() { | ||
| return countTotal.poll2(); | ||
| } | ||
|
|
||
| @Override | ||
| public double max() { | ||
| return max.poll(); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
...ions/micrometer-registry-signalfx/src/main/java/io/micrometer/signalfx/SignalfxTimer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright 2022 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.signalfx; | ||
|
|
||
| import io.micrometer.core.instrument.AbstractTimer; | ||
| import io.micrometer.core.instrument.Clock; | ||
| import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||
| import io.micrometer.core.instrument.distribution.TimeWindowMax; | ||
| import io.micrometer.core.instrument.distribution.pause.PauseDetector; | ||
| import io.micrometer.core.instrument.step.StepTuple2; | ||
| import io.micrometer.core.instrument.util.TimeUtils; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.LongAdder; | ||
|
|
||
| /** | ||
| * This class is mostly the same as {@link io.micrometer.core.instrument.step.StepTimer}, with one notable difference: | ||
| * the {@link DistributionStatisticConfig} is modified before being passed to the super class constructor - | ||
| * that forces the histogram generated by this meter to be cumulative. | ||
| * | ||
| * @author Bogdan Drutu | ||
| * @author Mateusz Rzeszutek | ||
| */ | ||
| final class SignalfxTimer extends AbstractTimer { | ||
|
|
||
| private final LongAdder count = new LongAdder(); | ||
| private final LongAdder total = new LongAdder(); | ||
| private final StepTuple2<Long, Long> countTotal; | ||
| private final TimeWindowMax max; | ||
|
|
||
| SignalfxTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, TimeUnit baseTimeUnit, long stepMillis) { | ||
| super(id, clock, CumulativeHistogramConfigUtil.updateConfig(distributionStatisticConfig), pauseDetector, baseTimeUnit, false); | ||
| countTotal = new StepTuple2<>(clock, stepMillis, 0L, 0L, count::sumThenReset, total::sumThenReset); | ||
| max = new TimeWindowMax(clock, distributionStatisticConfig); | ||
| } | ||
|
|
||
| @Override | ||
| protected void recordNonNegative(long amount, TimeUnit unit) { | ||
| final long nanoAmount = (long) TimeUtils.convert(amount, unit, TimeUnit.NANOSECONDS); | ||
| count.increment(); | ||
| total.add(nanoAmount); | ||
| max.record(amount, unit); | ||
| } | ||
|
|
||
| @Override | ||
| public long count() { | ||
| return countTotal.poll1(); | ||
| } | ||
|
|
||
| @Override | ||
| public double totalTime(TimeUnit unit) { | ||
| return TimeUtils.nanosToUnit(countTotal.poll2(), unit); | ||
| } | ||
|
|
||
| @Override | ||
| public double max(TimeUnit unit) { | ||
| return max.poll(unit); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.