-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-7648. Add a servername tag in UGI metrics. #4094
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c18e38
Add servername tag to Prometheus metrics
mladjan-gadzic 8e4f3b7
Refactor for readability and move utils to util class
mladjan-gadzic ada071a
Remove dependecy from hdds to ozone and refactor to increase readability
mladjan-gadzic 2fde42b
Refactor class name to be inline with naming conventions and add javadoc
mladjan-gadzic e7ce28d
Merge branch 'master' into HDDS-7648
mladjan-gadzic c368c45
Remove uneccessary test and set servername in constructor
mladjan-gadzic 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
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
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
116 changes: 116 additions & 0 deletions
116
...-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/PrometheusMetricsSinkUtil.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,116 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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 org.apache.hadoop.hdds.utils; | ||
|
|
||
| import static org.apache.hadoop.hdds.utils.RocksDBStoreMBean.ROCKSDB_CONTEXT_PREFIX; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Stream; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.hadoop.metrics2.MetricsTag; | ||
|
|
||
| /** | ||
| * Util class for | ||
| * {@link org.apache.hadoop.hdds.server.http.PrometheusMetricsSink}. | ||
| */ | ||
| public final class PrometheusMetricsSinkUtil { | ||
| private static final Pattern SPLIT_PATTERN = | ||
| Pattern.compile("(?<!(^|[A-Z_]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"); | ||
| private static final Pattern REPLACE_PATTERN = | ||
| Pattern.compile("[^a-zA-Z0-9]+"); | ||
|
|
||
| /** | ||
| * Never constructed. | ||
| */ | ||
| private PrometheusMetricsSinkUtil() { | ||
| } | ||
|
|
||
| /** | ||
| * Adds necessary tags. | ||
| * | ||
| * @param key metrics entry key | ||
| * @param username caller username | ||
| * @param servername servername | ||
| * @param unmodifiableTags list of metrics tags | ||
| * @return modifiable list of metrics tags | ||
| */ | ||
| public static List<MetricsTag> addTags(String key, String username, | ||
| String servername, Collection<MetricsTag> unmodifiableTags) { | ||
| List<MetricsTag> metricTags = new ArrayList<>(unmodifiableTags); | ||
|
|
||
| Stream.of(DecayRpcSchedulerUtil.createUsernameTag(username), | ||
| UgiMetricsUtil.createServernameTag(key, servername)) | ||
| .forEach( | ||
| metricsTag -> metricsTag.ifPresent(mt -> addTag(mt, metricTags))); | ||
|
|
||
| return metricTags; | ||
| } | ||
|
|
||
| /** | ||
| * Adds metric tag to a metrics tags. | ||
| * @param metricsTag metrics tag to be added | ||
| * @param metricsTags metrics tags where metrics tag needs to be added | ||
| */ | ||
| private static void addTag(MetricsTag metricsTag, | ||
| List<MetricsTag> metricsTags) { | ||
| metricsTags.add(metricsTag); | ||
| } | ||
|
|
||
| /** | ||
| * Convert CamelCase based names to lower-case names where the separator | ||
| * is the underscore, to follow prometheus naming conventions. | ||
| */ | ||
| public static String prometheusName(String recordName, | ||
| String metricName) { | ||
|
|
||
| // RocksDB metric names already have underscores as delimiters, | ||
| // but record name is from DB file name and '.' (as in 'om.db') is invalid | ||
| if (StringUtils.isNotEmpty(recordName) && | ||
| recordName.startsWith(ROCKSDB_CONTEXT_PREFIX)) { | ||
| return normalizeName(recordName) + "_" + metricName.toLowerCase(); | ||
| } | ||
|
|
||
| String baseName = StringUtils.capitalize(recordName) | ||
| + StringUtils.capitalize(metricName); | ||
| return normalizeName(baseName); | ||
| } | ||
|
|
||
| /** | ||
| * Normalizes metrics tag key name. | ||
| * @param baseName | ||
| * @return normalized name. | ||
| */ | ||
| private static String normalizeName(String baseName) { | ||
| String[] parts = SPLIT_PATTERN.split(baseName); | ||
| String result = String.join("_", parts).toLowerCase(); | ||
| return REPLACE_PATTERN.matcher(result).replaceAll("_"); | ||
| } | ||
|
|
||
| public static String getMetricName(String recordName, String metricName) { | ||
| return DecayRpcSchedulerUtil.splitMetricNameIfNeeded(recordName, | ||
| metricName); | ||
| } | ||
|
|
||
| public static String getUsername(String recordName, String metricName) { | ||
| return DecayRpcSchedulerUtil.checkMetricNameForUsername(recordName, | ||
| metricName); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should be more generic and agnostic to any metrics specific operations. It would be best to have another final class called
UgiMetricsUtilsimilar toDecayRpcSchedulerUtiland move the relevant methods under it.Also, if it turns out that we have a dependency issue, it will be best to have the code that causes the issue in a new class and maybe move that class under another package.