Search in sources :

Example 56 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class MetricUtils method instantiateMetaspaceMemoryMetrics.

@VisibleForTesting
static void instantiateMetaspaceMemoryMetrics(final MetricGroup parentMetricGroup) {
    final List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans().stream().filter(bean -> "Metaspace".equals(bean.getName())).collect(Collectors.toList());
    if (memoryPoolMXBeans.isEmpty()) {
        LOG.info("The '{}' metrics will not be exposed because no pool named 'Metaspace' could be found. This might be caused by the used JVM.", METRIC_GROUP_METASPACE_NAME);
        return;
    }
    final MetricGroup metricGroup = parentMetricGroup.addGroup(METRIC_GROUP_METASPACE_NAME);
    final Iterator<MemoryPoolMXBean> beanIterator = memoryPoolMXBeans.iterator();
    final MemoryPoolMXBean firstPool = beanIterator.next();
    instantiateMemoryUsageMetrics(metricGroup, firstPool::getUsage);
    if (beanIterator.hasNext()) {
        LOG.debug("More than one memory pool named 'Metaspace' is present. Only the first pool was used for instantiating the '{}' metrics.", METRIC_GROUP_METASPACE_NAME);
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LoggerFactory(org.slf4j.LoggerFactory) Supplier(java.util.function.Supplier) RpcService(org.apache.flink.runtime.rpc.RpcService) TaskSlotTable(org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) MBeanServer(javax.management.MBeanServer) Gauge(org.apache.flink.metrics.Gauge) ManagementFactory(java.lang.management.ManagementFactory) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) InstanceNotFoundException(javax.management.InstanceNotFoundException) Nullable(javax.annotation.Nullable) ReflectionException(javax.management.ReflectionException) MemoryUsage(java.lang.management.MemoryUsage) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) SlotNotFoundException(org.apache.flink.runtime.taskexecutor.slot.SlotNotFoundException) Configuration(org.apache.flink.configuration.Configuration) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) Set(java.util.Set) MetricOptions(org.apache.flink.configuration.MetricOptions) ObjectName(javax.management.ObjectName) ThreadMXBean(java.lang.management.ThreadMXBean) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) MalformedObjectNameException(javax.management.MalformedObjectNameException) MetricNames(org.apache.flink.runtime.metrics.MetricNames) MBeanException(javax.management.MBeanException) MetricGroup(org.apache.flink.metrics.MetricGroup) List(java.util.List) RpcSystem(org.apache.flink.runtime.rpc.RpcSystem) Optional(java.util.Optional) ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) SystemResourcesMetricsInitializer.instantiateSystemMetrics(org.apache.flink.runtime.metrics.util.SystemResourcesMetricsInitializer.instantiateSystemMetrics) ProcessMetricGroup(org.apache.flink.runtime.metrics.groups.ProcessMetricGroup) Time(org.apache.flink.api.common.time.Time) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) ProcessMetricGroup(org.apache.flink.runtime.metrics.groups.ProcessMetricGroup) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 57 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class Execution method registerProducedPartitions.

@VisibleForTesting
static CompletableFuture<Map<IntermediateResultPartitionID, ResultPartitionDeploymentDescriptor>> registerProducedPartitions(ExecutionVertex vertex, TaskManagerLocation location, ExecutionAttemptID attemptId, boolean notifyPartitionDataAvailable) {
    ProducerDescriptor producerDescriptor = ProducerDescriptor.create(location, attemptId);
    Collection<IntermediateResultPartition> partitions = vertex.getProducedPartitions().values();
    Collection<CompletableFuture<ResultPartitionDeploymentDescriptor>> partitionRegistrations = new ArrayList<>(partitions.size());
    for (IntermediateResultPartition partition : partitions) {
        PartitionDescriptor partitionDescriptor = PartitionDescriptor.from(partition);
        int maxParallelism = getPartitionMaxParallelism(partition);
        CompletableFuture<? extends ShuffleDescriptor> shuffleDescriptorFuture = vertex.getExecutionGraphAccessor().getShuffleMaster().registerPartitionWithProducer(vertex.getJobId(), partitionDescriptor, producerDescriptor);
        CompletableFuture<ResultPartitionDeploymentDescriptor> partitionRegistration = shuffleDescriptorFuture.thenApply(shuffleDescriptor -> new ResultPartitionDeploymentDescriptor(partitionDescriptor, shuffleDescriptor, maxParallelism, notifyPartitionDataAvailable));
        partitionRegistrations.add(partitionRegistration);
    }
    return FutureUtils.combineAll(partitionRegistrations).thenApply(rpdds -> {
        Map<IntermediateResultPartitionID, ResultPartitionDeploymentDescriptor> producedPartitions = new LinkedHashMap<>(partitions.size());
        rpdds.forEach(rpdd -> producedPartitions.put(rpdd.getPartitionId(), rpdd));
        return producedPartitions;
    });
}
Also used : ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PartitionDescriptor(org.apache.flink.runtime.shuffle.PartitionDescriptor) ProducerDescriptor(org.apache.flink.runtime.shuffle.ProducerDescriptor) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 58 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting 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)

Example 59 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class ThreadDumpInfo method stringifyThreadInfo.

/**
 * Custom stringify format of JVM thread info to bypass the MAX_FRAMES = 8 limitation.
 *
 * <p>This method is based on
 * https://github.com/openjdk/jdk/blob/master/src/java.management/share/classes/java/lang/management/ThreadInfo.java#L597
 */
@VisibleForTesting
protected static String stringifyThreadInfo(java.lang.management.ThreadInfo threadInfo, int maxDepth) {
    StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
    if (threadInfo.getLockName() != null) {
        sb.append(" on " + threadInfo.getLockName());
    }
    if (threadInfo.getLockOwnerName() != null) {
        sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
    }
    if (threadInfo.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (threadInfo.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    int i = 0;
    StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
    for (; i < stackTraceElements.length && i < maxDepth; i++) {
        StackTraceElement ste = stackTraceElements[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && threadInfo.getLockInfo() != null) {
            Thread.State ts = threadInfo.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    if (i < threadInfo.getStackTrace().length) {
        sb.append("\t...");
        sb.append('\n');
    }
    LockInfo[] locks = threadInfo.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 60 with VisibleForTesting

use of org.apache.flink.annotation.VisibleForTesting in project flink by apache.

the class SourceCoordinator method announceCombinedWatermark.

@VisibleForTesting
void announceCombinedWatermark() {
    checkState(watermarkAlignmentParams != WatermarkAlignmentParams.WATERMARK_ALIGNMENT_DISABLED);
    Watermark globalCombinedWatermark = coordinatorStore.apply(watermarkAlignmentParams.getWatermarkGroup(), (value) -> {
        WatermarkAggregator aggregator = (WatermarkAggregator) value;
        return new Watermark(aggregator.getAggregatedWatermark().getTimestamp());
    });
    long maxAllowedWatermark = globalCombinedWatermark.getTimestamp() + watermarkAlignmentParams.getMaxAllowedWatermarkDrift();
    Set<Integer> subTaskIds = combinedWatermark.keySet();
    LOG.info("Distributing maxAllowedWatermark={} to subTaskIds={}", maxAllowedWatermark, subTaskIds);
    for (Integer subtaskId : subTaskIds) {
        context.sendEventToSourceOperator(subtaskId, new WatermarkAlignmentEvent(maxAllowedWatermark));
    }
}
Also used : WatermarkAlignmentEvent(org.apache.flink.runtime.source.event.WatermarkAlignmentEvent) Watermark(org.apache.flink.api.common.eventtime.Watermark) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)64 HashMap (java.util.HashMap)11 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 Configuration (org.apache.flink.configuration.Configuration)7 Map (java.util.Map)6 File (java.io.File)5 URI (java.net.URI)4 List (java.util.List)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 Field (java.lang.reflect.Field)3 Set (java.util.Set)3 Nullable (javax.annotation.Nullable)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Matcher (java.util.regex.Matcher)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)2