Skip to content
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

Metrics: Fix issues caused by metric system update #105

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/main/java/org/prebid/cache/config/MetricsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@
@Configuration
public class MetricsConfig {

@Bean
MeterRegistryCustomizer<MeterRegistry> identityNamingConventionMeterCustomizer() {
// To preserve metric names as they defined in code
return registry -> registry.config().namingConvention(NamingConvention.identity);
}

@Bean
@ConditionalOnProperty(name = "management.graphite.metrics.export.enabled", havingValue = "true")
MeterRegistryCustomizer<MeterRegistry> graphitePrefixMeterCustomizer(
MeterRegistryCustomizer<MeterRegistry> graphiteMeterCustomizer(
@Value("${management.graphite.metrics.export.prefix:}") String prefix) {

return registry -> {
if (StringUtils.isNotBlank(prefix)) {
registry.config().commonTags("prefix", prefix);
}
// To preserve old metric names
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment will have no value for future developers

registry.config().namingConvention(NamingConvention.identity);
};
}
}
16 changes: 4 additions & 12 deletions src/main/java/org/prebid/cache/metrics/MetricsRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.prebid.cache.handlers.ServiceType;
import org.springframework.stereotype.Component;

import java.time.Duration;

@Component
public class MetricsRecorder {

Expand Down Expand Up @@ -46,21 +44,15 @@ public enum MeasurementTag {

public class MetricsRecorderTimer {
private Timer timer;
private long start;
private long stop;
private Timer.Sample sample;

MetricsRecorderTimer(String measurementTag) {
this.timer = meterRegistry.timer(measurementTag);
}

public MetricsRecorderTimer start() {
this.start = System.currentTimeMillis();
return this;
timer = meterRegistry.timer(measurementTag);
sample = Timer.start(meterRegistry);
}

public void stop() {
this.stop = System.currentTimeMillis();
this.timer.record(Duration.ofMillis(this.stop - this.start));
sample.stop(timer);
}
}

Expand Down