Java Code Examples for org.apache.beam.sdk.metrics.MetricQueryResults#create()

The following examples show how to use org.apache.beam.sdk.metrics.MetricQueryResults#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataflowMetrics.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
  List<MetricUpdate> metricUpdates;
  ImmutableList<MetricResult<Long>> counters = ImmutableList.of();
  ImmutableList<MetricResult<DistributionResult>> distributions = ImmutableList.of();
  ImmutableList<MetricResult<GaugeResult>> gauges = ImmutableList.of();
  JobMetrics jobMetrics;
  try {
    jobMetrics = getJobMetrics();
  } catch (IOException e) {
    LOG.warn("Unable to query job metrics.\n");
    return MetricQueryResults.create(counters, distributions, gauges);
  }
  metricUpdates = firstNonNull(jobMetrics.getMetrics(), Collections.emptyList());
  return populateMetricQueryResults(metricUpdates, filter);
}
 
Example 2
Source File: DataflowMetrics.java    From beam with Apache License 2.0 6 votes vote down vote up
public MetricQueryResults build() {
  buildMetricsIndex();

  DataflowMetricResultExtractor extractor =
      new DataflowMetricResultExtractor(dataflowPipelineJob.getDataflowOptions().isStreaming());
  for (MetricKey metricKey : metricHashKeys) {
    String metricName = metricKey.metricName().getName();
    if (metricName.endsWith("[MIN]")
        || metricName.endsWith("[MAX]")
        || metricName.endsWith("[MEAN]")
        || metricName.endsWith("[COUNT]")) {
      // Skip distribution metrics, as these are not yet properly supported.
      // TODO: remove this when distributions stop being broken up for the UI.
      continue;
    }

    extractor.addMetricResult(
        metricKey, committedByName.get(metricKey), tentativeByName.get(metricKey));
  }
  return MetricQueryResults.create(
      extractor.getCounterResults(),
      extractor.getDistributionResults(),
      extractor.getGaugeResults());
}
 
Example 3
Source File: DirectMetrics.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
  ImmutableList.Builder<MetricResult<Long>> counterResults = ImmutableList.builder();
  for (Entry<MetricKey, DirectMetric<Long, Long>> counter : counters.entries()) {
    maybeExtractResult(filter, counterResults, counter);
  }
  ImmutableList.Builder<MetricResult<DistributionResult>> distributionResults =
      ImmutableList.builder();
  for (Entry<MetricKey, DirectMetric<DistributionData, DistributionResult>> distribution :
      distributions.entries()) {
    maybeExtractResult(filter, distributionResults, distribution);
  }
  ImmutableList.Builder<MetricResult<GaugeResult>> gaugeResults = ImmutableList.builder();
  for (Entry<MetricKey, DirectMetric<GaugeData, GaugeResult>> gauge : gauges.entries()) {
    maybeExtractResult(filter, gaugeResults, gauge);
  }

  return MetricQueryResults.create(
      counterResults.build(), distributionResults.build(), gaugeResults.build());
}
 
Example 4
Source File: DefaultMetricResults.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public MetricQueryResults queryMetrics(@Nullable MetricsFilter filter) {
  return MetricQueryResults.create(
      Iterables.filter(counters, counter -> MetricFiltering.matches(filter, counter.getKey())),
      Iterables.filter(
          distributions, distribution -> MetricFiltering.matches(filter, distribution.getKey())),
      Iterables.filter(gauges, gauge -> MetricFiltering.matches(filter, gauge.getKey())));
}
 
Example 5
Source File: PortableMetrics.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public MetricQueryResults queryMetrics(MetricsFilter filter) {
  return MetricQueryResults.create(
      Iterables.filter(
          this.counters, (counter) -> MetricFiltering.matches(filter, counter.getKey())),
      Iterables.filter(
          this.distributions,
          (distribution) -> MetricFiltering.matches(filter, distribution.getKey())),
      Iterables.filter(this.gauges, (gauge) -> MetricFiltering.matches(filter, gauge.getKey())));
}