-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add metrics registry for all components
Most components had metric names hardcoded. Adding a metrics registry for each component to contain all metric name templates, and export them for document generation.
- Loading branch information
Showing
11 changed files
with
1,010 additions
and
129 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
core/src/main/java/io/aiven/kafka/tieredstorage/metrics/CaffeineMetricsRegistry.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,102 @@ | ||
/* | ||
* Copyright 2024 Aiven Oy | ||
* | ||
* 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 | ||
* | ||
* http://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.aiven.kafka.tieredstorage.metrics; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.kafka.common.MetricNameTemplate; | ||
|
||
public class CaffeineMetricsRegistry { | ||
|
||
static final String CACHE_HITS = "cache-hits"; | ||
static final String CACHE_HITS_TOTAL = CACHE_HITS + "-total"; | ||
static final String CACHE_MISSES = "cache-misses"; | ||
static final String CACHE_MISSES_TOTAL = CACHE_MISSES + "-total"; | ||
static final String CACHE_LOAD = "cache-load"; | ||
static final String CACHE_LOAD_SUCCESS = CACHE_LOAD + "-success"; | ||
static final String CACHE_LOAD_SUCCESS_TOTAL = CACHE_LOAD_SUCCESS + "-total"; | ||
static final String CACHE_LOAD_SUCCESS_TIME = CACHE_LOAD_SUCCESS + "-time"; | ||
static final String CACHE_LOAD_SUCCESS_TIME_TOTAL = CACHE_LOAD_SUCCESS_TIME + "-total"; | ||
static final String CACHE_LOAD_FAILURE = CACHE_LOAD + "-failure"; | ||
static final String CACHE_LOAD_FAILURE_TOTAL = CACHE_LOAD_FAILURE + "-total"; | ||
static final String CACHE_LOAD_FAILURE_TIME = CACHE_LOAD_FAILURE + "-time"; | ||
static final String CACHE_LOAD_FAILURE_TIME_TOTAL = CACHE_LOAD_FAILURE_TIME + "-total"; | ||
|
||
static final String CACHE_EVICTION = "cache-eviction"; | ||
static final String CACHE_EVICTION_TOTAL = CACHE_EVICTION + "-total"; | ||
static final String CACHE_EVICTION_WEIGHT = CACHE_EVICTION + "-weight"; | ||
static final String CACHE_EVICTION_WEIGHT_TOTAL = CACHE_EVICTION_WEIGHT + "-total"; | ||
|
||
static final String CACHE_SIZE = "cache-size"; | ||
static final String CACHE_SIZE_TOTAL = CACHE_SIZE + "-total"; | ||
|
||
final String groupName; | ||
|
||
final MetricNameTemplate cacheHitsMetricName; | ||
final MetricNameTemplate cacheMissesMetricName; | ||
final MetricNameTemplate cacheLoadSuccessMetricName; | ||
final MetricNameTemplate cacheLoadSuccessTimeMetricName; | ||
final MetricNameTemplate cacheLoadFailureMetricName; | ||
final MetricNameTemplate cacheLoadFailureTimeMetricName; | ||
final MetricNameTemplate cacheEvictionMetricName; | ||
final MetricNameTemplate cacheEvictionByCauseMetricName; | ||
final MetricNameTemplate cacheEvictionWeightMetricName; | ||
final MetricNameTemplate cacheEvictionWeightByCauseMetricName; | ||
final MetricNameTemplate cacheSizeTotalMetricName; | ||
|
||
public CaffeineMetricsRegistry(final String groupName) { | ||
this.groupName = groupName; | ||
cacheHitsMetricName = | ||
new MetricNameTemplate(CACHE_HITS_TOTAL, groupName, ""); | ||
cacheMissesMetricName = | ||
new MetricNameTemplate(CACHE_MISSES_TOTAL, groupName, ""); | ||
cacheLoadSuccessMetricName = | ||
new MetricNameTemplate(CACHE_LOAD_SUCCESS_TOTAL, groupName, ""); | ||
cacheLoadSuccessTimeMetricName = | ||
new MetricNameTemplate(CACHE_LOAD_SUCCESS_TIME_TOTAL, groupName, ""); | ||
cacheLoadFailureMetricName = | ||
new MetricNameTemplate(CACHE_LOAD_FAILURE_TOTAL, groupName, ""); | ||
cacheLoadFailureTimeMetricName = | ||
new MetricNameTemplate(CACHE_LOAD_FAILURE_TIME_TOTAL, groupName, ""); | ||
cacheEvictionMetricName = | ||
new MetricNameTemplate(CACHE_EVICTION_TOTAL, groupName, ""); | ||
cacheEvictionByCauseMetricName = | ||
new MetricNameTemplate(CACHE_EVICTION_TOTAL, groupName, "", "cause"); | ||
cacheEvictionWeightMetricName = | ||
new MetricNameTemplate(CACHE_EVICTION_WEIGHT_TOTAL, groupName, ""); | ||
cacheEvictionWeightByCauseMetricName = | ||
new MetricNameTemplate(CACHE_EVICTION_WEIGHT_TOTAL, groupName, "", "cause"); | ||
cacheSizeTotalMetricName = | ||
new MetricNameTemplate(CACHE_SIZE_TOTAL, groupName, ""); | ||
} | ||
|
||
public List<MetricNameTemplate> all() { | ||
return List.of( | ||
cacheHitsMetricName, | ||
cacheMissesMetricName, | ||
cacheLoadSuccessMetricName, | ||
cacheLoadSuccessTimeMetricName, | ||
cacheLoadFailureMetricName, | ||
cacheLoadFailureTimeMetricName, | ||
cacheEvictionMetricName, | ||
cacheEvictionByCauseMetricName, | ||
cacheEvictionWeightMetricName, | ||
cacheEvictionWeightByCauseMetricName, | ||
cacheSizeTotalMetricName | ||
); | ||
} | ||
} |
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
Oops, something went wrong.