-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics to track account cache hits and misses (#1018)
* Add metrics to track settings cache population if it is enabled * Add metrics to track account cache hits and misses
- Loading branch information
Showing
10 changed files
with
372 additions
and
99 deletions.
There are no files selected for viewing
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
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/prebid/server/metric/SettingsCacheMetrics.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,58 @@ | ||
package org.prebid.server.metric; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Settings cache metrics support. | ||
*/ | ||
class SettingsCacheMetrics extends UpdatableMetrics { | ||
|
||
private final Function<MetricName, RefreshSettingsCacheMetrics> refreshSettingsCacheMetricsCreator; | ||
private final Map<MetricName, RefreshSettingsCacheMetrics> refreshSettingsCacheMetrics; | ||
|
||
SettingsCacheMetrics(MetricRegistry metricRegistry, CounterType counterType, MetricName type) { | ||
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType), | ||
nameCreator(createPrefix(Objects.requireNonNull(type)))); | ||
|
||
refreshSettingsCacheMetricsCreator = refreshType -> | ||
new RefreshSettingsCacheMetrics(metricRegistry, counterType, createPrefix(type), refreshType); | ||
refreshSettingsCacheMetrics = new HashMap<>(); | ||
} | ||
|
||
RefreshSettingsCacheMetrics forRefreshType(MetricName refreshType) { | ||
return refreshSettingsCacheMetrics.computeIfAbsent(refreshType, refreshSettingsCacheMetricsCreator); | ||
} | ||
|
||
private static String createPrefix(MetricName type) { | ||
return String.format("settings.cache.%s", type.toString()); | ||
} | ||
|
||
private static Function<MetricName, String> nameCreator(String prefix) { | ||
return metricName -> String.format("%s.%s", prefix, metricName.toString()); | ||
} | ||
|
||
static class RefreshSettingsCacheMetrics extends UpdatableMetrics { | ||
|
||
RefreshSettingsCacheMetrics(MetricRegistry metricRegistry, | ||
CounterType counterType, | ||
String prefix, | ||
MetricName type) { | ||
|
||
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType), | ||
nameCreator(createPrefix(Objects.requireNonNull(prefix), Objects.requireNonNull(type)))); | ||
} | ||
|
||
private static String createPrefix(String prefix, MetricName type) { | ||
return String.format("%s.refresh.%s", prefix, type.toString()); | ||
} | ||
|
||
private static Function<MetricName, String> nameCreator(String prefix) { | ||
return metricName -> String.format("%s.%s", prefix, metricName.toString()); | ||
} | ||
} | ||
} |
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.