Search in sources :

Example 26 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class BeamFnMapTaskExecutor method extractMetricUpdates.

/**
 * {@inheritDoc}
 *
 * @return User-defined Beam metrics reported over the Fn API.
 */
@Override
public Iterable<CounterUpdate> extractMetricUpdates() {
    List<CounterUpdate> result = progressTracker.extractCounterUpdates();
    if ((result != null) && (result.size() > 0)) {
        return result;
    }
    // todo(BEAM-6189): Remove this fallback once Metrics is deprecated from SDKs.
    MetricUpdates updates = progressTracker.extractMetricUpdates();
    Iterable<CounterUpdate> deprecatedMetrics = Iterables.concat(StreamSupport.stream(updates.counterUpdates().spliterator(), false).map(update -> MetricsToCounterUpdateConverter.fromCounter(update.getKey(), true, update.getUpdate())).collect(Collectors.toList()), StreamSupport.stream(updates.distributionUpdates().spliterator(), false).map(update -> MetricsToCounterUpdateConverter.fromDistribution(update.getKey(), true, update.getUpdate())).collect(Collectors.toList()));
    return deprecatedMetrics;
}
Also used : MetricUpdates(org.apache.beam.runners.core.metrics.MetricUpdates) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate)

Example 27 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class UserMonitoringInfoToCounterUpdateTransformer method transform.

/**
 * Transforms user counter MonitoringInfo to relevant CounterUpdate.
 *
 * @return Relevant CounterUpdate or null if transformation failed.
 */
@Override
@Nullable
public CounterUpdate transform(MonitoringInfo monitoringInfo) {
    Optional<String> validationResult = validate(monitoringInfo);
    if (validationResult.isPresent()) {
        LOG.debug(validationResult.get());
        return null;
    }
    long value = decodeInt64Counter(monitoringInfo.getPayload());
    Map<String, String> miLabels = monitoringInfo.getLabelsMap();
    final String ptransform = miLabels.get(MonitoringInfoConstants.Labels.PTRANSFORM);
    final String counterName = miLabels.get(MonitoringInfoConstants.Labels.NAME);
    final String counterNamespace = miLabels.get(MonitoringInfoConstants.Labels.NAMESPACE);
    CounterStructuredNameAndMetadata name = new CounterStructuredNameAndMetadata();
    DataflowStepContext stepContext = transformIdMapping.get(ptransform);
    name.setName(new CounterStructuredName().setOrigin(Origin.USER.toString()).setName(counterName).setOriginalStepName(stepContext.getNameContext().originalName()).setOriginNamespace(counterNamespace)).setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()));
    return new CounterUpdate().setStructuredNameAndMetadata(name).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(value));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) DataflowStepContext(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 28 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class ExecutionTimeMonitoringInfoToCounterUpdateTransformer method transform.

@Override
@Nullable
public CounterUpdate transform(MonitoringInfo monitoringInfo) {
    Optional<String> validationResult = validate(monitoringInfo);
    if (validationResult.isPresent()) {
        LOG.debug(validationResult.get());
        return null;
    }
    long value = decodeInt64Counter(monitoringInfo.getPayload());
    String urn = monitoringInfo.getUrn();
    final String ptransform = monitoringInfo.getLabelsMap().get(MonitoringInfoConstants.Labels.PTRANSFORM);
    DataflowStepContext stepContext = transformIdMapping.get(ptransform);
    String counterName = URN_TO_COUNTER_NAME_MAPPING.get(urn);
    CounterStructuredNameAndMetadata name = new CounterStructuredNameAndMetadata();
    name.setName(new CounterStructuredName().setOrigin("SYSTEM").setName(counterName).setOriginalStepName(stepContext.getNameContext().originalName()).setExecutionStepName(stepContext.getNameContext().stageName())).setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()));
    return new CounterUpdate().setStructuredNameAndMetadata(name).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(value));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) DataflowStepContext(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 29 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class MeanByteCountMonitoringInfoToCounterUpdateTransformer method transform.

/**
 * Generates CounterUpdate to send to DFE based on ElementCount MonitoringInfo.
 *
 * @param monitoringInfo Monitoring info to transform.
 * @return CounterUpdate generated based on provided monitoringInfo
 */
@Override
@Nullable
public CounterUpdate transform(MonitoringInfo monitoringInfo) {
    Optional<String> validationResult = validate(monitoringInfo);
    if (validationResult.isPresent()) {
        LOG.debug(validationResult.get());
        return null;
    }
    DistributionData data = decodeInt64Distribution(monitoringInfo.getPayload());
    final String pcollectionId = monitoringInfo.getLabelsMap().get(MonitoringInfoConstants.Labels.PCOLLECTION);
    final String pcollectionName = pcollectionIdToNameContext.get(pcollectionId).userName();
    String counterName = pcollectionName + "-MeanByteCount";
    NameAndKind name = new NameAndKind();
    name.setName(counterName).setKind(Kind.MEAN.toString());
    return new CounterUpdate().setNameAndKind(name).setCumulative(true).setIntegerMean(new IntegerMean().setSum(longToSplitInt(data.sum())).setCount(longToSplitInt(data.count())));
}
Also used : DistributionData(org.apache.beam.runners.core.metrics.DistributionData) IntegerMean(com.google.api.services.dataflow.model.IntegerMean) NameAndKind(com.google.api.services.dataflow.model.NameAndKind) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 30 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class UserDistributionMonitoringInfoToCounterUpdateTransformer method transform.

/**
 * Transforms user counter MonitoringInfo to relevant CounterUpdate.
 *
 * @return Relevant CounterUpdate or null if transformation failed.
 */
@Override
@Nullable
public CounterUpdate transform(MonitoringInfo monitoringInfo) {
    Optional<String> validationResult = validate(monitoringInfo);
    if (validationResult.isPresent()) {
        LOG.debug(validationResult.get());
        return null;
    }
    DistributionData data = decodeInt64Distribution(monitoringInfo.getPayload());
    Map<String, String> miLabels = monitoringInfo.getLabelsMap();
    final String ptransform = miLabels.get(MonitoringInfoConstants.Labels.PTRANSFORM);
    final String counterName = miLabels.get(MonitoringInfoConstants.Labels.NAME);
    final String counterNamespace = miLabels.get(MonitoringInfoConstants.Labels.NAMESPACE);
    CounterStructuredNameAndMetadata name = new CounterStructuredNameAndMetadata();
    DataflowStepContext stepContext = transformIdMapping.get(ptransform);
    name.setName(new CounterStructuredName().setOrigin(Origin.USER.toString()).setName(counterName).setOriginalStepName(stepContext.getNameContext().originalName()).setOriginNamespace(counterNamespace)).setMetadata(new CounterMetadata().setKind(Kind.DISTRIBUTION.toString()));
    return new CounterUpdate().setStructuredNameAndMetadata(name).setCumulative(true).setDistribution(new DistributionUpdate().setMax(DataflowCounterUpdateExtractor.longToSplitInt(data.max())).setMin(DataflowCounterUpdateExtractor.longToSplitInt(data.min())).setSum(DataflowCounterUpdateExtractor.longToSplitInt(data.sum())).setCount(DataflowCounterUpdateExtractor.longToSplitInt(data.count())));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) DistributionData(org.apache.beam.runners.core.metrics.DistributionData) CounterStructuredName(com.google.api.services.dataflow.model.CounterStructuredName) DistributionUpdate(com.google.api.services.dataflow.model.DistributionUpdate) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) DataflowStepContext(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)51 Test (org.junit.Test)33 CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)18 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)16 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)12 HashMap (java.util.HashMap)10 WorkItemStatus (com.google.api.services.dataflow.model.WorkItemStatus)9 ArrayList (java.util.ArrayList)9 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)7 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)7 DistributionUpdate (com.google.api.services.dataflow.model.DistributionUpdate)6 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 NameAndKind (com.google.api.services.dataflow.model.NameAndKind)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 DataflowCounterUpdateExtractor.splitIntToLong (org.apache.beam.runners.dataflow.worker.counters.DataflowCounterUpdateExtractor.splitIntToLong)5 WorkItemCommitRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.WorkItemCommitRequest)4 IntegerMean (com.google.api.services.dataflow.model.IntegerMean)3 List (java.util.List)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3