Search in sources :

Example 1 with MetricStructuredName

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

the class WorkItemStatusClient method populateMetricUpdates.

@VisibleForTesting
synchronized void populateMetricUpdates(WorkItemStatus status) {
    List<MetricUpdate> updates = new ArrayList<>();
    if (executionContext != null && executionContext.getExecutionStateTracker() != null) {
        ExecutionStateTracker tracker = executionContext.getExecutionStateTracker();
        MetricUpdate update = new MetricUpdate();
        update.setKind("internal");
        MetricStructuredName name = new MetricStructuredName();
        name.setName("state-sampler");
        update.setName(name);
        Map<String, Object> metric = new HashMap<>();
        ExecutionState state = tracker.getCurrentState();
        if (state != null) {
            metric.put("last-state-name", state.getDescription());
        }
        metric.put("num-transitions", tracker.getNumTransitions());
        metric.put("last-state-duration-ms", tracker.getMillisSinceLastTransition());
        update.setInternal(metric);
        updates.add(update);
    }
    status.setMetricUpdates(updates);
}
Also used : ExecutionState(org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState) ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetricStructuredName(com.google.api.services.dataflow.model.MetricStructuredName) MetricUpdate(com.google.api.services.dataflow.model.MetricUpdate) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)

Example 2 with MetricStructuredName

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

the class DataflowMetricsTest method setStructuredName.

private MetricUpdate setStructuredName(MetricUpdate update, String name, String namespace, String step, boolean tentative) {
    MetricStructuredName structuredName = new MetricStructuredName();
    structuredName.setName(name);
    structuredName.setOrigin("user");
    ImmutableMap.Builder contextBuilder = new ImmutableMap.Builder<>();
    contextBuilder.put("step", step).put("namespace", namespace);
    if (tentative) {
        contextBuilder.put("tentative", "true");
    }
    structuredName.setContext(contextBuilder.build());
    update.setName(structuredName);
    return update;
}
Also used : MetricStructuredName(com.google.api.services.dataflow.model.MetricStructuredName) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap)

Example 3 with MetricStructuredName

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

the class TestDataflowRunnerTest method generateMockStreamingMetrics.

private List<MetricUpdate> generateMockStreamingMetrics(Map<String, BigDecimal> metricMap) {
    List<MetricUpdate> metrics = Lists.newArrayList();
    for (Map.Entry<String, BigDecimal> entry : metricMap.entrySet()) {
        MetricStructuredName name = new MetricStructuredName();
        name.setName(entry.getKey());
        MetricUpdate metric = new MetricUpdate();
        metric.setName(name);
        metric.setScalar(entry.getValue());
        metrics.add(metric);
    }
    return metrics;
}
Also used : MetricStructuredName(com.google.api.services.dataflow.model.MetricStructuredName) MetricUpdate(com.google.api.services.dataflow.model.MetricUpdate) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 4 with MetricStructuredName

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

the class TestDataflowRunnerTest method generateMockMetrics.

private List<MetricUpdate> generateMockMetrics(boolean success, boolean tentative) {
    MetricStructuredName name = new MetricStructuredName();
    name.setName(success ? "PAssertSuccess" : "PAssertFailure");
    name.setContext(tentative ? ImmutableMap.of("tentative", "") : ImmutableMap.of());
    MetricUpdate metric = new MetricUpdate();
    metric.setName(name);
    metric.setScalar(BigDecimal.ONE);
    return Lists.newArrayList(metric);
}
Also used : MetricStructuredName(com.google.api.services.dataflow.model.MetricStructuredName) MetricUpdate(com.google.api.services.dataflow.model.MetricUpdate)

Aggregations

MetricStructuredName (com.google.api.services.dataflow.model.MetricStructuredName)4 MetricUpdate (com.google.api.services.dataflow.model.MetricUpdate)3 ImmutableMap (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionStateTracker (org.apache.beam.runners.core.metrics.ExecutionStateTracker)1 ExecutionState (org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState)1 VisibleForTesting (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1