-
Notifications
You must be signed in to change notification settings - Fork 616
HDDS-7464. Container Report at SCM is not coming separately for ICR and FCR in prometheus endpoint #4035
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
HDDS-7464. Container Report at SCM is not coming separately for ICR and FCR in prometheus endpoint #4035
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1143918
HDDS-7464. Container Report at SCM is not coming separately for ICR a…
sumitagrawl 9e83080
HDDS-7464. Container Report at SCM is not coming separately for ICR a…
sumitagrawl 0ab676c
Merge branch 'apache:master' into HDDS-7464
sumitagrawl 9accf07
HDDS-7464. Container Report at SCM is not coming separately for ICR a…
sumitagrawl 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
100 changes: 100 additions & 0 deletions
100
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/metrics/MetricsUtil.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,100 @@ | ||
| /* | ||
| * 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.metrics; | ||
|
|
||
| import java.lang.annotation.Annotation; | ||
| import java.lang.reflect.Field; | ||
| import java.lang.reflect.Method; | ||
| import java.util.Map; | ||
| import org.apache.hadoop.metrics2.annotation.Metrics; | ||
| import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Metrics util for metrics. | ||
| */ | ||
| public final class MetricsUtil { | ||
| private static final String ANNOTATIONS = "annotations"; | ||
| private static final String ANNOTATION_DATA = "annotationData"; | ||
| private static final Class<? extends Annotation> ANNOTATION_TO_ALTER | ||
| = Metrics.class; | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(MetricsUtil.class); | ||
|
|
||
| private MetricsUtil() { | ||
| } | ||
|
|
||
| /** | ||
| * register metric with changing class annotation for metrics. | ||
| * | ||
| * @param source source to register | ||
| * @param name name of metric | ||
| * @param desc description of metric | ||
| * @param context context of metric | ||
| * @param <T> source type | ||
| */ | ||
| public static <T> void registerDynamic( | ||
| T source, String name, String desc, String context) { | ||
| updateAnnotation(source.getClass(), name, desc, context); | ||
| DefaultMetricsSystem.instance().register(name, desc, source); | ||
| } | ||
|
|
||
| private static void updateAnnotation( | ||
| Class clz, String name, String desc, String context) { | ||
| try { | ||
| Annotation annotationValue = new Metrics() { | ||
|
|
||
| @Override | ||
| public Class<? extends Annotation> annotationType() { | ||
| return ANNOTATION_TO_ALTER; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public String about() { | ||
| return desc; | ||
| } | ||
|
|
||
| @Override | ||
| public String context() { | ||
| return context; | ||
| } | ||
| }; | ||
|
|
||
| Method method = clz.getClass().getDeclaredMethod( | ||
| ANNOTATION_DATA, null); | ||
| method.setAccessible(true); | ||
| Object annotationData = method.invoke(clz); | ||
| Field annotations = annotationData.getClass() | ||
| .getDeclaredField(ANNOTATIONS); | ||
| annotations.setAccessible(true); | ||
| Map<Class<? extends Annotation>, Annotation> map = | ||
| (Map<Class<? extends Annotation>, Annotation>) annotations | ||
| .get(annotationData); | ||
| map.put(ANNOTATION_TO_ALTER, annotationValue); | ||
| } catch (Exception e) { | ||
| LOG.error("Update Metrics annotation failed. ", e); | ||
| } | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/metrics/package-info.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,22 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * metrics registeration util. | ||
| */ | ||
| package org.apache.hadoop.hdds.metrics; |
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
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.
Instead of creating a new package, please move this class to org.apache.hadoop.hdds.utils package.
The rest looks good to me.