forked from micrometer-metrics/micrometer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Stackdriver Distribution count and bucket count sum mismatch
The count passed to the `HistogramSnapshot` is from the StepTimer and is step-based, while the histogram buckets have a separate time window. This mismatch in time windows caused the two to generally not match which causes a validation error when publishing Distribution metrics to Stackdriver. This solves this by tracking an infinity bucket in the histogram so we can get a consistent count in the same time window as the rest of the histogram.
- Loading branch information
Showing
10 changed files
with
395 additions
and
113 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...y-stackdriver/src/main/java/io/micrometer/stackdriver/StackdriverDistributionSummary.java
This file contains 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,32 @@ | ||
/* | ||
* Copyright 2025 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.stackdriver; | ||
|
||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.core.instrument.distribution.*; | ||
import io.micrometer.core.instrument.step.StepDistributionSummary; | ||
|
||
import static io.micrometer.stackdriver.StackdriverHistogramUtil.stackdriverHistogram; | ||
|
||
class StackdriverDistributionSummary extends StepDistributionSummary { | ||
|
||
public StackdriverDistributionSummary(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, | ||
double scale, long stepMillis) { | ||
super(id, clock, distributionStatisticConfig, scale, stepMillis, | ||
stackdriverHistogram(clock, distributionStatisticConfig)); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...egistry-stackdriver/src/main/java/io/micrometer/stackdriver/StackdriverHistogramUtil.java
This file contains 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 2025 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.stackdriver; | ||
|
||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.core.instrument.distribution.*; | ||
|
||
final class StackdriverHistogramUtil { | ||
|
||
private StackdriverHistogramUtil() { | ||
} | ||
|
||
// copied and modified from AbstractDistributionSummary/AbstractTimer | ||
static Histogram stackdriverHistogram(Clock clock, DistributionStatisticConfig distributionStatisticConfig) { | ||
if (distributionStatisticConfig.isPublishingPercentiles()) { | ||
return new TimeWindowPercentileHistogram(clock, distributionStatisticConfig, true, false, true); | ||
} | ||
if (distributionStatisticConfig.isPublishingHistogram()) { | ||
return new StackdriverFixedBoundaryHistogram(clock, distributionStatisticConfig); | ||
} | ||
return NoopHistogram.INSTANCE; | ||
} | ||
|
||
// Can't do this because java: cannot access org.HdrHistogram.DoubleRecorder | ||
/* | ||
* static class StackdriverClientSidePercentilesHistogram extends | ||
* TimeWindowPercentileHistogram { | ||
* | ||
* public StackdriverClientSidePercentilesHistogram(Clock clock, | ||
* DistributionStatisticConfig distributionStatisticConfig) { super(clock, | ||
* distributionStatisticConfig, true, false, true); } | ||
* | ||
* } | ||
*/ | ||
|
||
static class StackdriverFixedBoundaryHistogram extends TimeWindowFixedBoundaryHistogram { | ||
|
||
StackdriverFixedBoundaryHistogram(Clock clock, DistributionStatisticConfig config) { | ||
super(clock, config, true, false, true); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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
35 changes: 35 additions & 0 deletions
35
...ometer-registry-stackdriver/src/main/java/io/micrometer/stackdriver/StackdriverTimer.java
This file contains 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,35 @@ | ||
/* | ||
* Copyright 2025 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.stackdriver; | ||
|
||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; | ||
import io.micrometer.core.instrument.distribution.pause.PauseDetector; | ||
import io.micrometer.core.instrument.step.StepTimer; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static io.micrometer.stackdriver.StackdriverHistogramUtil.stackdriverHistogram; | ||
|
||
class StackdriverTimer extends StepTimer { | ||
|
||
public StackdriverTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, | ||
PauseDetector pauseDetector, TimeUnit baseTimeUnit, long stepDurationMillis) { | ||
super(id, clock, distributionStatisticConfig, pauseDetector, baseTimeUnit, stepDurationMillis, | ||
stackdriverHistogram(clock, distributionStatisticConfig)); | ||
} | ||
|
||
} |
This file contains 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
Oops, something went wrong.