1u0 commented on a change in pull request #9870: [FLINK-14350][metrics]
Introduce dedicated MetricScope
URL: https://github.com/apache/flink/pull/9870#discussion_r335734768
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/metrics/scope/InternalMetricScope.java
##########
@@ -0,0 +1,89 @@
+package org.apache.flink.runtime.metrics.scope;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.metrics.CharacterFilter;
+import org.apache.flink.metrics.MetricScope;
+import org.apache.flink.runtime.metrics.DelimiterProvider;
+
+import java.util.Map;
+import java.util.function.Supplier;
+
+/**
+ * Default scope implementation. Contains additional methods assembling
identifiers based on reporter-specific delimiters.
+ */
+@Internal
+public class InternalMetricScope implements MetricScope {
+
+ private final DelimiterProvider delimiterProvider;
+ private final Supplier<Map<String, String>> variablesProvider;
+
+ /**
+ * The map containing all variables and their associated values, lazily
computed.
+ */
+ protected volatile Map<String, String> variables;
+
+ /**
+ * The metrics scope represented by this group.
+ * For example ["host-7", "taskmanager-2", "window_word_count",
"my-mapper" ].
+ */
+ private final String[] scopeComponents;
+
+ /**
+ * Array containing the metrics scope represented by this group for
each reporter, as a concatenated string, lazily computed.
+ * For example: "host-7.taskmanager-2.window_word_count.my-mapper"
+ */
+ private final String[] scopeStrings;
+
+ public InternalMetricScope(DelimiterProvider delimiterProvider,
String[] scopeComponents, Supplier<Map<String, String>> variablesProvider) {
+ this.delimiterProvider = delimiterProvider;
+ this.variablesProvider = variablesProvider;
+ this.scopeComponents = scopeComponents;
+ this.scopeStrings = new
String[delimiterProvider.getNumberReporters()];
+ }
+
+ @Override
+ public Map<String, String> getAllVariables() {
+ if (variables == null) { // avoid synchronization for common
case
+ synchronized (this) {
+ if (variables == null) {
+ variables = variablesProvider.get();
+ }
+ }
+ }
+ return variables;
+ }
+
+ public String[] geScopeComponents() {
+ return scopeStrings;
+ }
+
+ @Override
+ public String getMetricIdentifier(String metricName) {
+ return getMetricIdentifier(metricName, s -> s,
delimiterProvider.getDelimiter(), -1);
+ }
+
+ @Override
+ public String getMetricIdentifier(String metricName, CharacterFilter
filter) {
+ return getMetricIdentifier(metricName, filter,
delimiterProvider.getDelimiter(), -1);
+ }
+
+ @Internal
+ public String getMetricIdentifier(String metricName, CharacterFilter
filter, int reporterIndex) {
+ return getMetricIdentifier(metricName, filter,
delimiterProvider.getDelimiter(reporterIndex), reporterIndex);
Review comment:
I'm fine to keep it as it's now.
Or just add a comment note instead, that would tell that this method should
be limited in usage.
As a reader of this code, I find `@Internal` at class level as already
telling me that I should be using it only internally. But I understand your
intend.
`@deprecated` would be a little offtopic here, unless you really plan to
remove it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services