-
Notifications
You must be signed in to change notification settings - Fork 589
HDDS-9438. Improve ProtocolMessageMetrics #9600
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
Conversation
szetszwo
left a comment
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.
@Russole , thanks a lot for working on this! Please see the comments inlined.
| MetricsRecordBuilder builder = | ||
| collector.addRecord(name); | ||
| builder.add( | ||
| new MetricsTag(Interns.info("type", "Message type"), key.toString())); | ||
| builder.addCounter(new MetricName("counter", "Number of distinct calls"), | ||
| value.longValue()); | ||
| new MetricsTag(TYPE_TAG_INFO, key.toString())); | ||
| builder.addCounter(COUNTER_INFO, | ||
| stat.counter()); | ||
| builder.addCounter( | ||
| new MetricName("time", "Sum of the duration of the calls"), | ||
| elapsedTimes.get(key).longValue()); | ||
| TIME_INFO, | ||
| stat.time()); | ||
| builder.endRecord(); |
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.
Let's combine the short lines:
collector.addRecord(name)
.add(new MetricsTag(TYPE_TAG_INFO, key.toString()))
.addCounter(COUNTER_INFO, stat.counter())
.addCounter(TIME_INFO, stat.time())
.endRecord();| MetricsRecordBuilder builder = collector.addRecord(name); | ||
| builder.addCounter(new MetricName("concurrency", | ||
| "Number of requests processed concurrently"), concurrency.get()); | ||
| builder.addCounter(CONCURRENCY_INFO, concurrency.get()); |
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.
Similarly,
collector.addRecord(name)
.addCounter(CONCURRENCY_INFO, concurrency.get());BTW, do we need .endRecord();?
| * Metrics to count all the subtypes of a specific message. | ||
| */ | ||
| public class ProtocolMessageMetrics<KEY> implements MetricsSource { | ||
| public class ProtocolMessageMetrics<KEY extends Enum<KEY>> implements MetricsSource { |
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.
👍 the generic type should extend Enum.
| private static final MetricsInfo TYPE_TAG_INFO = | ||
| Interns.info("type", "Message type"); | ||
|
|
||
| private static final MetricsInfo COUNTER_INFO = | ||
| Interns.info("counter", "Number of distinct calls"); | ||
|
|
||
| private static final MetricsInfo TIME_INFO = | ||
| Interns.info("time", "Sum of the duration of the calls"); | ||
|
|
||
| private static final MetricsInfo CONCURRENCY_INFO = | ||
| Interns.info("concurrency", | ||
| "Number of requests processed concurrently"); |
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.
The line width is 120 characters. Let's avoid the short lines.
private static final MetricsInfo TYPE_TAG_INFO = Interns.info("type", "Message type");
private static final MetricsInfo COUNTER_INFO = Interns.info("counter", "Number of distinct calls");
private static final MetricsInfo TIME_INFO = Interns.info("time", "Sum of the duration of the calls");
private static final MetricsInfo CONCURRENCY_INFO = Interns.info("concurrency",
"Number of requests processed concurrently");| public static <KEY extends Enum<KEY>> ProtocolMessageMetrics<KEY> create(String name, | ||
| String description, KEY[] types) { | ||
| return new ProtocolMessageMetrics<KEY>(name, description, types); | ||
| return new ProtocolMessageMetrics<>(name, description, types); | ||
| } | ||
|
|
||
| public ProtocolMessageMetrics(String name, String description, | ||
| KEY[] values) { | ||
| this.name = name; | ||
| this.description = description; | ||
| final Class<KEY> enumClass = values[0].getDeclaringClass(); | ||
| final EnumMap<KEY, Stats> map = new EnumMap<>(enumClass); | ||
| for (KEY value : values) { | ||
| counters.put(value, new AtomicLong(0)); | ||
| elapsedTimes.put(value, new AtomicLong(0)); | ||
| map.put(value, new Stats()); | ||
| } | ||
| this.stats = Collections.unmodifiableMap(map); | ||
| } |
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.
- Pass the class instead of values.
- Change the constructor to private.
public static <KEY extends Enum<KEY>> ProtocolMessageMetrics<KEY> create(String name,
String description, Class<KEY> enumClass) {
return new ProtocolMessageMetrics<>(name, description, enumClass);
}
private ProtocolMessageMetrics(String name, String description, Class<KEY> enumClass) {
this.name = name;
this.description = description;
final EnumMap<KEY, Stats> map = new EnumMap<>(enumClass);
for (KEY value : enumClass.getEnumConstants()) {
map.put(value, new Stats());
}
this.stats = Collections.unmodifiableMap(map);
}
szetszwo
left a comment
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.
+1 the change looks good.
|
Thanks @szetszwo for the reviews. |
What changes were proposed in this pull request?
ProtocolMessageMetricsto use a single unmodifiableEnumMapfor per-message metrics.MetricsInfo) and removed dynamic creation of metric definitions.KEY extends Enum<KEY>) required by the new implementation.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-9438
How was this patch tested?
All CI checks passed.
https://github.com/Russole/ozone/actions/runs/20752706566