use of com.google.api.services.dataflow.model.CounterStructuredName in project beam by apache.
the class WorkItemStatusClientTest method populateCounterUpdatesWithMsecCounter.
@Test
public void populateCounterUpdatesWithMsecCounter() throws Exception {
final CounterUpdate expectedMsec = new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin("SYSTEM").setName("start-msecs").setOriginalStepName("step")).setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()))).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(42));
BatchModeExecutionContext context = mock(BatchModeExecutionContext.class);
when(context.extractMetricUpdates(anyBoolean())).thenReturn(ImmutableList.of());
when(context.extractMsecCounters(anyBoolean())).thenReturn(ImmutableList.of(expectedMsec));
WorkItemStatus status = new WorkItemStatus();
when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
statusClient.setWorker(worker, context);
statusClient.populateCounterUpdates(status);
assertThat(status.getCounterUpdates(), containsInAnyOrder(expectedMsec));
}
use of com.google.api.services.dataflow.model.CounterStructuredName in project beam by apache.
the class WorkItemStatusClientTest method populateCounterUpdatesWithMetricsAndCounters.
/**
* Validates that Beam Metrics and "internal" Counters are merged in the update.
*/
@Test
public void populateCounterUpdatesWithMetricsAndCounters() throws Exception {
final CounterUpdate expectedCounter = new CounterUpdate().setNameAndKind(new NameAndKind().setName("some-counter").setKind(Kind.SUM.toString())).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(42));
CounterSet counterSet = new CounterSet();
counterSet.intSum(CounterName.named("some-counter")).addValue(42);
final CounterUpdate expectedMetric = new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin("USER").setOriginNamespace("namespace").setName("some-counter").setOriginalStepName("step")).setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()))).setCumulative(true).setInteger(DataflowCounterUpdateExtractor.longToSplitInt(42));
MetricsContainerImpl metricsContainer = new MetricsContainerImpl("step");
BatchModeExecutionContext context = mock(BatchModeExecutionContext.class);
when(context.extractMetricUpdates(anyBoolean())).thenReturn(ImmutableList.of(expectedMetric));
when(context.extractMsecCounters(anyBoolean())).thenReturn(Collections.emptyList());
CounterCell counter = metricsContainer.getCounter(MetricName.named("namespace", "some-counter"));
counter.inc(1);
counter.inc(41);
counter.inc(1);
counter.inc(-1);
WorkItemStatus status = new WorkItemStatus();
when(worker.getOutputCounters()).thenReturn(counterSet);
when(worker.extractMetricUpdates()).thenReturn(Collections.emptyList());
statusClient.setWorker(worker, context);
statusClient.populateCounterUpdates(status);
assertThat(status.getCounterUpdates(), containsInAnyOrder(expectedCounter, expectedMetric));
}
use of com.google.api.services.dataflow.model.CounterStructuredName in project beam by apache.
the class DataflowCounterUpdateExtractor method getStructuredName.
private CounterStructuredNameAndMetadata getStructuredName(CounterName name, String kind) {
CounterMetadata metadata = new CounterMetadata();
metadata.setKind(kind);
CounterStructuredName structuredName = new CounterStructuredName();
structuredName.setName(name.name());
if (name.usesContextOriginalName()) {
structuredName.setOriginalStepName(name.contextOriginalName());
} else if (name.usesContextSystemName()) {
structuredName.setComponentStepName(name.contextSystemName());
}
if (name.originalRequestingStepName() != null) {
structuredName.setOriginalRequestingStepName(name.originalRequestingStepName());
}
if (name.inputIndex() != null && name.inputIndex() > 0) {
structuredName.setInputIndex(name.inputIndex());
}
CounterStructuredNameAndMetadata nameAndMetadata = new CounterStructuredNameAndMetadata();
nameAndMetadata.setMetadata(metadata);
nameAndMetadata.setName(structuredName);
return nameAndMetadata;
}
use of com.google.api.services.dataflow.model.CounterStructuredName 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));
}
use of com.google.api.services.dataflow.model.CounterStructuredName 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));
}
Aggregations