-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add resettable DistributionSummary and Timer for Dynatrace registry #3093
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 8 commits into
micrometer-metrics:1.9.x
from
dynatrace-oss-contrib:add-resettable-summaries
Apr 8, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56d4404
Add resettable DistributionSummary and Timer instruments for Dynatrac…
pirgeo 78cc0f5
Use Atomic types instead of synchronized
pirgeo 967fc16
Add scale to DynatraceDistributionSummary
pirgeo f9d6f24
Add DistributionStatisticConfig
pirgeo 9d0ae4b
base DynatraceTimer on AbstractTimer
pirgeo 176bc77
base DynatraceDistributionSummary on AbstractDistributionSummary
pirgeo 57c2c45
appease linter
pirgeo 8b07d28
Allow users to fall back to Micrometer instruments
pirgeo 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
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
109 changes: 109 additions & 0 deletions
109
...y-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceDistributionSummary.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,109 @@ | ||
| /* | ||
| * 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.dynatrace.types; | ||
|
|
||
| import io.micrometer.core.instrument.AbstractDistributionSummary; | ||
| import io.micrometer.core.instrument.Clock; | ||
| import io.micrometer.core.instrument.DistributionSummary; | ||
| import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||
| import io.micrometer.core.instrument.distribution.HistogramSnapshot; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Resettable {@link DistributionSummary} implementation for Dynatrace exporters. | ||
| * | ||
| * @author Georg Pirklbauer | ||
| * @since 1.9.0 | ||
| */ | ||
| public final class DynatraceDistributionSummary extends AbstractDistributionSummary implements DynatraceSummarySnapshotSupport { | ||
| private final DynatraceSummary summary = new DynatraceSummary(); | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(DynatraceDistributionSummary.class.getName()); | ||
|
|
||
| // Configuration that will set the Histogram in AbstractTimer to a NoopHistogram. | ||
| private static final DistributionStatisticConfig NOOP_HISTOGRAM_CONFIG = | ||
| DistributionStatisticConfig.builder().percentilesHistogram(false).percentiles().build(); | ||
|
|
||
| public DynatraceDistributionSummary(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, double scale) { | ||
| super(id, clock, NOOP_HISTOGRAM_CONFIG, scale, false); | ||
|
|
||
| if (distributionStatisticConfig != DistributionStatisticConfig.NONE) { | ||
| LOGGER.warn("Distribution statistic config is currently ignored."); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void recordNonNegative(double amount) { | ||
| summary.recordNonNegative(amount); | ||
| } | ||
|
|
||
| @Override | ||
| public long count() { | ||
| return summary.getCount(); | ||
| } | ||
|
|
||
| @Override | ||
| public double totalAmount() { | ||
| return summary.getTotal(); | ||
| } | ||
|
|
||
| @Override | ||
| public double max() { | ||
| return summary.getMax(); | ||
| } | ||
|
|
||
| public double min() { | ||
| return summary.getMin(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasValues() { | ||
| return count() > 0; | ||
| } | ||
|
|
||
| @Override | ||
| public DynatraceSummarySnapshot takeSummarySnapshot() { | ||
| return new DynatraceSummarySnapshot(min(), max(), totalAmount(), count()); | ||
| } | ||
|
|
||
| @Override | ||
| public DynatraceSummarySnapshot takeSummarySnapshot(TimeUnit timeUnit) { | ||
| LOGGER.debug("Called takeSummarySnapshot with a TimeUnit on a DistributionSummary. Ignoring TimeUnit."); | ||
| return takeSummarySnapshot(); | ||
| } | ||
|
|
||
| @Override | ||
| public DynatraceSummarySnapshot takeSummarySnapshotAndReset() { | ||
| DynatraceSummarySnapshot snapshot = takeSummarySnapshot(); | ||
| summary.reset(); | ||
| return snapshot; | ||
| } | ||
|
|
||
| @Override | ||
| public DynatraceSummarySnapshot takeSummarySnapshotAndReset(TimeUnit unit) { | ||
| LOGGER.debug("Called takeSummarySnapshot with a TimeUnit on a DistributionSummary. Ignoring TimeUnit."); | ||
| return takeSummarySnapshotAndReset(); | ||
| } | ||
|
|
||
| @Override | ||
| public HistogramSnapshot takeSnapshot() { | ||
| LOGGER.warn("Called takeSnapshot on a Dynatrace Distribution Summary, no percentiles will be exported."); | ||
| DynatraceSummarySnapshot dtSnapshot = takeSummarySnapshot(); | ||
| return HistogramSnapshot.empty(dtSnapshot.getCount(), dtSnapshot.getTotal(), dtSnapshot.getMax()); | ||
| } | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
...eter-registry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceSummary.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,76 @@ | ||
| /* | ||
| * 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.dynatrace.types; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import java.util.concurrent.atomic.DoubleAdder; | ||
| import java.util.concurrent.atomic.LongAdder; | ||
|
|
||
| /** | ||
| * Internal class for resettable summary statistics | ||
| * | ||
| * @author Georg Pirklbauer | ||
| * @since 1.9.0 | ||
| */ | ||
| final class DynatraceSummary { | ||
| private final LongAdder count = new LongAdder(); | ||
| private final DoubleAdder total = new DoubleAdder(); | ||
| private final AtomicLong min = new AtomicLong(0); | ||
| private final AtomicLong max = new AtomicLong(0); | ||
|
|
||
| void recordNonNegative(double amount) { | ||
| if (amount < 0) { | ||
| return; | ||
| } | ||
|
|
||
| synchronized (this) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking if we can get into trouble because of this or using a |
||
| long longBits = Double.doubleToLongBits(amount); | ||
|
|
||
| max.getAndUpdate(prev -> Math.max(prev, longBits)); | ||
| // have to check if a value was already recorded before, otherwise min will always stay 0 (because the default is 0). | ||
| min.getAndUpdate(prev -> count.longValue() > 0 ? Math.min(prev, longBits) : longBits); | ||
|
|
||
| total.add(amount); | ||
| count.increment(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public long getCount() { | ||
| return count.longValue(); | ||
| } | ||
|
|
||
| public double getTotal() { | ||
| return total.doubleValue(); | ||
| } | ||
|
|
||
| public double getMin() { | ||
| return Double.longBitsToDouble(min.longValue()); | ||
| } | ||
|
|
||
| public double getMax() { | ||
| return Double.longBitsToDouble(max.longValue()); | ||
| } | ||
|
|
||
| void reset() { | ||
| synchronized (this) { | ||
| min.set(0); | ||
| max.set(0); | ||
| total.reset(); | ||
| count.reset(); | ||
| } | ||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
...istry-dynatrace/src/main/java/io/micrometer/dynatrace/types/DynatraceSummarySnapshot.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,57 @@ | ||
| /* | ||
| * 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.dynatrace.types; | ||
|
|
||
| import javax.annotation.concurrent.Immutable; | ||
|
|
||
|
|
||
| /** | ||
| * Snapshot of a Dynatrace summary object. | ||
| * | ||
| * @author Georg Pirklbauer | ||
| * @since 1.9.0 | ||
| */ | ||
| @Immutable | ||
| public final class DynatraceSummarySnapshot { | ||
| private final double min; | ||
| private final double max; | ||
| private final double total; | ||
| private final long count; | ||
|
|
||
| DynatraceSummarySnapshot(double min, double max, double total, long count) { | ||
| this.min = min; | ||
| this.max = max; | ||
| this.total = total; | ||
| this.count = count; | ||
| } | ||
|
|
||
| public double getMin() { | ||
| return min; | ||
| } | ||
|
|
||
| public double getMax() { | ||
| return max; | ||
| } | ||
|
|
||
| public double getTotal() { | ||
| return total; | ||
| } | ||
|
|
||
| public long getCount() { | ||
| return count; | ||
| } | ||
| } | ||
|
|
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.