Search in sources :

Example 1 with INFO_CATEGORY_JOB

use of org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_JOB in project flink by apache.

the class MetricStore method add.

@VisibleForTesting
public void add(MetricDump metric) {
    try {
        QueryScopeInfo info = metric.scopeInfo;
        TaskManagerMetricStore tm;
        JobMetricStore job;
        TaskMetricStore task;
        ComponentMetricStore subtask;
        String name = info.scope.isEmpty() ? metric.name : info.scope + "." + metric.name;
        if (name.isEmpty()) {
            // malformed transmission
            return;
        }
        switch(info.getCategory()) {
            case INFO_CATEGORY_JM:
                addMetric(jobManager.metrics, name, metric);
                break;
            case INFO_CATEGORY_TM:
                String tmID = ((QueryScopeInfo.TaskManagerQueryScopeInfo) info).taskManagerID;
                tm = taskManagers.computeIfAbsent(tmID, k -> new TaskManagerMetricStore());
                if (name.contains("GarbageCollector")) {
                    String gcName = name.substring("Status.JVM.GarbageCollector.".length(), name.lastIndexOf('.'));
                    tm.addGarbageCollectorName(gcName);
                }
                addMetric(tm.metrics, name, metric);
                break;
            case INFO_CATEGORY_JOB:
                QueryScopeInfo.JobQueryScopeInfo jobInfo = (QueryScopeInfo.JobQueryScopeInfo) info;
                job = jobs.computeIfAbsent(jobInfo.jobID, k -> new JobMetricStore());
                addMetric(job.metrics, name, metric);
                break;
            case INFO_CATEGORY_TASK:
                QueryScopeInfo.TaskQueryScopeInfo taskInfo = (QueryScopeInfo.TaskQueryScopeInfo) info;
                job = jobs.computeIfAbsent(taskInfo.jobID, k -> new JobMetricStore());
                task = job.tasks.computeIfAbsent(taskInfo.vertexID, k -> new TaskMetricStore());
                subtask = task.subtasks.computeIfAbsent(taskInfo.subtaskIndex, k -> new ComponentMetricStore());
                /**
                 * The duplication is intended. Metrics scoped by subtask are useful for several
                 * job/task handlers, while the WebInterface task metric queries currently do
                 * not account for subtasks, so we don't divide by subtask and instead use the
                 * concatenation of subtask index and metric name as the name for those.
                 */
                addMetric(subtask.metrics, name, metric);
                addMetric(task.metrics, taskInfo.subtaskIndex + "." + name, metric);
                break;
            case INFO_CATEGORY_OPERATOR:
                QueryScopeInfo.OperatorQueryScopeInfo operatorInfo = (QueryScopeInfo.OperatorQueryScopeInfo) info;
                job = jobs.computeIfAbsent(operatorInfo.jobID, k -> new JobMetricStore());
                task = job.tasks.computeIfAbsent(operatorInfo.vertexID, k -> new TaskMetricStore());
                subtask = task.subtasks.computeIfAbsent(operatorInfo.subtaskIndex, k -> new ComponentMetricStore());
                /**
                 * As the WebInterface does not account for operators (because it can't) we
                 * don't divide by operator and instead use the concatenation of subtask index,
                 * operator name and metric name as the name.
                 */
                addMetric(subtask.metrics, operatorInfo.operatorName + "." + name, metric);
                addMetric(task.metrics, operatorInfo.subtaskIndex + "." + operatorInfo.operatorName + "." + name, metric);
                break;
            default:
                LOG.debug("Invalid metric dump category: " + info.getCategory());
        }
    } catch (Exception e) {
        LOG.debug("Malformed metric dump.", e);
    }
}
Also used : METRIC_CATEGORY_METER(org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_METER) INFO_CATEGORY_JM(org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_JM) Logger(org.slf4j.Logger) METRIC_CATEGORY_HISTOGRAM(org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_HISTOGRAM) INFO_CATEGORY_JOB(org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_JOB) MetricDump(org.apache.flink.runtime.metrics.dump.MetricDump) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) INFO_CATEGORY_OPERATOR(org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_OPERATOR) List(java.util.List) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) Map(java.util.Map) INFO_CATEGORY_TASK(org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_TASK) INFO_CATEGORY_TM(org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_TM) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) QueryScopeInfo(org.apache.flink.runtime.metrics.dump.QueryScopeInfo) METRIC_CATEGORY_COUNTER(org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_COUNTER) METRIC_CATEGORY_GAUGE(org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_GAUGE) QueryScopeInfo(org.apache.flink.runtime.metrics.dump.QueryScopeInfo) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 Collections.unmodifiableSet (java.util.Collections.unmodifiableSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadSafe (javax.annotation.concurrent.ThreadSafe)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 MetricDump (org.apache.flink.runtime.metrics.dump.MetricDump)1 METRIC_CATEGORY_COUNTER (org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_COUNTER)1 METRIC_CATEGORY_GAUGE (org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_GAUGE)1 METRIC_CATEGORY_HISTOGRAM (org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_HISTOGRAM)1 METRIC_CATEGORY_METER (org.apache.flink.runtime.metrics.dump.MetricDump.METRIC_CATEGORY_METER)1 QueryScopeInfo (org.apache.flink.runtime.metrics.dump.QueryScopeInfo)1 INFO_CATEGORY_JM (org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_JM)1 INFO_CATEGORY_JOB (org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_JOB)1 INFO_CATEGORY_OPERATOR (org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_OPERATOR)1 INFO_CATEGORY_TASK (org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_TASK)1 INFO_CATEGORY_TM (org.apache.flink.runtime.metrics.dump.QueryScopeInfo.INFO_CATEGORY_TM)1 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)1