-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-9717. Add P99 quantiles and Min/Max Metrics for S3G Performance Metrics #5627
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
20 commits
Select commit
Hold shift + click to select a range
804c016
Add P99 quantiles and Min/Max Metrics for S3G Performance Metrics
62d2db0
Fix Test
xichen01 eb339a6
rename AggregatedMetrics to PerformanceMetrics
xichen01 75da05f
add OZONE_S3G_METRICS_PERCENTILES_INTERVALS_SECONDS_KEY to addPropert…
xichen01 c169127
Merge branch 'master' into HDDS-9717
xichen01 1589e17
Add documentation for initializeMetrics() intervals
xichen01 f0df615
findbugs
xichen01 1afb269
revert findbugs excluding
xichen01 2287165
Merge branch 'master' into HDDS-9717
xichen01 fe9191e
Fix thread safety issues for MutableMinMax
xichen01 56f944e
Fix unit test
xichen01 0c4fe0c
Fix test
xichen01 aa783c6
Merge branch 'master' into HDDS-9717
xichen01 ea68e18
Merge branch 'master' into HDDS-9717
xichen01 5f66dab
Fix compile issue
xichen01 e943d56
Merge remote-tracking branch 'origin/master' into HDDS-9717
adoroszlai 6fbaaa7
Merge branch 'cxozone' into HDDS-9717
be15e46
Add a default value for configuration
bbc179b
Merge branch 'cxozone' into HDDS-9717
a38d7e5
Merge remote-tracking branch 'origin/master' into HDDS-9717
adoroszlai 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
93 changes: 93 additions & 0 deletions
93
hadoop-hdds/common/src/main/java/org/apache/hadoop/util/MutableMinMax.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,93 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.hadoop.util; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.classification.InterfaceStability; | ||
| import org.apache.hadoop.metrics2.MetricsInfo; | ||
| import org.apache.hadoop.metrics2.MetricsRecordBuilder; | ||
| import org.apache.hadoop.metrics2.lib.MetricsRegistry; | ||
| import org.apache.hadoop.metrics2.lib.MutableMetric; | ||
| import org.apache.hadoop.metrics2.util.SampleStat.MinMax; | ||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import static org.apache.hadoop.metrics2.lib.Interns.info; | ||
|
|
||
| /** | ||
| * A mutable metric that tracks the minimum and maximum | ||
| * values of a dataset over time. | ||
| */ | ||
| @InterfaceAudience.Public | ||
| @InterfaceStability.Evolving | ||
| public class MutableMinMax extends MutableMetric { | ||
| private final MinMax intervalMinMax = new MinMax(); | ||
| private final MinMax prevMinMax = new MinMax(); | ||
| private final MetricsInfo iMinInfo; | ||
| private final MetricsInfo iMaxInfo; | ||
|
|
||
| /** | ||
| * Construct a minMax metric. | ||
| * @param registry MetricsRegistry of the metric | ||
| * @param name of the metric | ||
| * @param description of the metric | ||
| * @param valueName of the metric (e.g. "Time", "Latency") | ||
| */ | ||
| public MutableMinMax(MetricsRegistry registry, | ||
| String name, String description, String valueName) { | ||
| String ucName = StringUtils.capitalize(name); | ||
| String desc = StringUtils.uncapitalize(description); | ||
| String uvName = StringUtils.capitalize(valueName); | ||
| String lvName = StringUtils.uncapitalize(valueName); | ||
| iMinInfo = info(ucName + "IMin" + uvName, | ||
| "Min " + lvName + " for " + desc + "in the last reporting interval"); | ||
| iMaxInfo = info(ucName + "IMax" + uvName, | ||
| "Max " + lvName + " for " + desc + "in the last reporting interval"); | ||
| // hadoop.metrics2 only supports standard types of Metrics registered | ||
| // with annotations, but not custom types of metrics. | ||
| // Registering here is for compatibility with metric classes | ||
| // that are only registered with annotations and do not override getMetrics. | ||
| registry.newGauge(iMinInfo, 0); | ||
| registry.newGauge(iMaxInfo, 0); | ||
| } | ||
|
|
||
| /** | ||
| * Add a snapshot to the metric. | ||
| * @param value of the metric | ||
| */ | ||
| public synchronized void add(long value) { | ||
| intervalMinMax.add(value); | ||
| setChanged(); | ||
| } | ||
|
|
||
| private MinMax lastMinMax() { | ||
| return changed() ? intervalMinMax : prevMinMax; | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void snapshot(MetricsRecordBuilder builder, boolean all) { | ||
| if (all || this.changed()) { | ||
| builder.addGauge(iMinInfo, lastMinMax().min()); | ||
| builder.addGauge(iMaxInfo, lastMinMax().max()); | ||
| if (changed()) { | ||
| prevMinMax.reset(intervalMinMax); | ||
| intervalMinMax.reset(); | ||
| clearChanged(); | ||
| } | ||
| } | ||
| } | ||
| } |
97 changes: 97 additions & 0 deletions
97
hadoop-hdds/common/src/main/java/org/apache/hadoop/util/PerformanceMetrics.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,97 @@ | ||
| /** | ||
| * 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.util; | ||
|
|
||
| import org.apache.hadoop.metrics2.MetricsRecordBuilder; | ||
| import org.apache.hadoop.metrics2.lib.MetricsRegistry; | ||
| import org.apache.hadoop.metrics2.lib.MutableQuantiles; | ||
| import org.apache.hadoop.metrics2.lib.MutableStat; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * The {@code PerformanceMetrics} class encapsulates a collection of related | ||
| * metrics including a MutableStat, MutableQuantiles, and a MutableMinMax. | ||
| * This class provides methods to update these metrics and to | ||
| * snapshot their values for reporting. | ||
| */ | ||
| public class PerformanceMetrics { | ||
| private final MutableStat stat; | ||
| private final List<MutableQuantiles> quantiles; | ||
| private final MutableMinMax minMax; | ||
|
|
||
| /** | ||
| * Initializes aggregated metrics for the specified metrics source. | ||
| * | ||
| * @param source the metrics source | ||
| * @param registry the metrics registry | ||
| * @param intervals the intervals for quantiles computation. Note, each | ||
| * interval in 'intervals' increases memory usage, as it corresponds | ||
| * to a separate quantile calculator. | ||
| */ | ||
| public static synchronized <T> void initializeMetrics(T source, | ||
| MetricsRegistry registry, String sampleName, String valueName, | ||
| int[] intervals) { | ||
| try { | ||
| PerformanceMetricsInitializer.initialize( | ||
| source, registry, sampleName, valueName, intervals); | ||
| } catch (IllegalAccessException e) { | ||
| throw new RuntimeException("Failed to initialize PerformanceMetrics", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Construct an instance of PerformanceMetrics with the specified MutableStat, | ||
| * MutableQuantiles, and MutableMinMax. | ||
| * | ||
| * @param stat the stat metric | ||
| * @param quantiles the quantiles metrics | ||
| * @param minMax the min/max tracker | ||
| */ | ||
| public PerformanceMetrics(MutableStat stat, | ||
| List<MutableQuantiles> quantiles, MutableMinMax minMax) { | ||
| this.stat = stat; | ||
| this.quantiles = quantiles; | ||
| this.minMax = minMax; | ||
| } | ||
|
|
||
| /** | ||
| * Adds a value to all the aggregated metrics. | ||
| * | ||
| * @param value the value to add | ||
| */ | ||
| public void add(long value) { | ||
| this.stat.add(value); | ||
| this.quantiles.forEach(quantile -> quantile.add(value)); | ||
| this.minMax.add(value); | ||
| } | ||
|
|
||
| /** | ||
| * Snapshots the values of all the aggregated metrics for reporting. | ||
| * | ||
| * @param recordBuilder the metrics record builder | ||
| * @param all flag to indicate whether to snapshot all metrics or only changed | ||
| */ | ||
| public void snapshot(MetricsRecordBuilder recordBuilder, boolean all) { | ||
| this.stat.snapshot(recordBuilder, all); | ||
| this.quantiles.forEach(quantile -> quantile.snapshot(recordBuilder, all)); | ||
| this.minMax.snapshot(recordBuilder, all); | ||
| } | ||
|
|
||
| } | ||
|
|
83 changes: 83 additions & 0 deletions
83
hadoop-hdds/common/src/main/java/org/apache/hadoop/util/PerformanceMetricsInitializer.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,83 @@ | ||
| /** | ||
| * 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.util; | ||
|
|
||
| import org.apache.hadoop.metrics2.annotation.Metric; | ||
| import org.apache.hadoop.metrics2.lib.MetricsRegistry; | ||
|
|
||
| import java.lang.reflect.Field; | ||
|
|
||
| /** | ||
| * Utility class for initializing PerformanceMetrics in a MetricsSource. | ||
| */ | ||
| public final class PerformanceMetricsInitializer { | ||
| private PerformanceMetricsInitializer() { } | ||
|
|
||
| /** | ||
| * Initializes aggregated metrics in the given metrics source. | ||
| * | ||
| * @param source the metrics source | ||
| * @param registry the metrics registry | ||
| * @param sampleName sample name | ||
| * @param valueName value name | ||
| * @param intervals intervals for quantiles | ||
| * @throws IllegalAccessException if unable to access the field | ||
| */ | ||
| public static <T> void initialize(T source, MetricsRegistry registry, | ||
| String sampleName, String valueName, int[] intervals) | ||
| throws IllegalAccessException { | ||
| Field[] fields = source.getClass().getDeclaredFields(); | ||
|
|
||
| for (Field field : fields) { | ||
| if (field.getType() == PerformanceMetrics.class) { | ||
| Metric annotation = field.getAnnotation(Metric.class); | ||
| if (annotation != null) { | ||
| String description = annotation.about(); | ||
| String name = field.getName(); | ||
| PerformanceMetrics performanceMetrics = | ||
| getMetrics(registry, name, description, | ||
| sampleName, valueName, intervals); | ||
| field.setAccessible(true); | ||
| field.set(source, performanceMetrics); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to create PerformanceMetrics. | ||
| * | ||
| * @param registry the metrics registry | ||
| * @param name metric name | ||
| * @param description metric description | ||
| * @param sampleName sample name | ||
| * @param valueName value name | ||
| * @param intervals intervals for quantiles | ||
| * @return an instance of PerformanceMetrics | ||
| */ | ||
| private static PerformanceMetrics getMetrics( | ||
| MetricsRegistry registry, String name, String description, | ||
| String sampleName, String valueName, int[] intervals) { | ||
| return new PerformanceMetrics( | ||
| registry.newStat( | ||
| name, description, sampleName, valueName, false), | ||
| MetricUtil.createQuantiles( | ||
| registry, name, description, sampleName, valueName, intervals), | ||
| new MutableMinMax(registry, name, description, valueName)); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.