You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/10/16 12:00:11 UTC

[GitHub] [flink] zentol commented on a change in pull request #9870: [FLINK-14350][metrics] Introduce dedicated MetricScope

zentol commented on a change in pull request #9870: [FLINK-14350][metrics] Introduce dedicated MetricScope
URL: https://github.com/apache/flink/pull/9870#discussion_r335431341
 
 

 ##########
 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:
   Generally yes, this is more or less a misappropriation of this annotation. This method _shouldn't_ be public, and only is so to enable backwards-compatibility with the deprecated scope-related methods in the `MetricGroup`.
   
   I wanted to mark it in some way, maybe @Deprecated would be more appropriate.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services