@Override public void finishBundle() { try (Closeable ignored = MetricsEnvironment.scopedMetricsContainer(metricsContainer())) { delegate.finishBundle(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public PipelineResult run(Pipeline pipeline) { logWarningIfPCollectionViewHasNonDeterministicKeyCoder(pipeline); MetricsEnvironment.setMetricsSupported(true); LOG.info("Executing pipeline using FlinkRunner."); FlinkPipelineExecutionEnvironment env = new FlinkPipelineExecutionEnvironment(options); LOG.info("Translating pipeline to Flink program."); env.translate(pipeline); JobExecutionResult result; try { LOG.info("Starting execution of Flink program."); result = env.executePipeline(); } catch (Exception e) { LOG.error("Pipeline execution failed", e); throw new RuntimeException("Pipeline execution failed", e); } return createPipelineResult(result, options); }
@Override public void close() throws IOException { setCurrentContainer(oldContainer); } }
@Override public void set(long value) { MetricsContainer container = MetricsEnvironment.getCurrentContainer(); if (container != null) { container.getGauge(name).set(value); } }
if (MetricsEnvironment.isMetricsSupported()) { long expectedNumberOfAssertions = (long) PAssert.countAsserts(pipeline);
/** Increment the counter by the given amount. */ @Override public void inc(long n) { MetricsContainer container = MetricsEnvironment.getCurrentContainer(); if (container != null) { container.getCounter(name).inc(n); } }
@Override public void processElement(final WindowedValue<InputT> elem) { try (Closeable ignored = MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer(stepName))) { delegate.processElement(elem); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public PipelineResult run(Pipeline pipeline) { logWarningIfPCollectionViewHasNonDeterministicKeyCoder(pipeline); MetricsEnvironment.setMetricsSupported(true); LOG.info("Executing pipeline using FlinkRunner."); FlinkPipelineExecutionEnvironment env = new FlinkPipelineExecutionEnvironment(options); LOG.info("Translating pipeline to Flink program."); env.translate(pipeline); JobExecutionResult result; try { LOG.info("Starting execution of Flink program."); result = env.executePipeline(); } catch (Exception e) { LOG.error("Pipeline execution failed", e); throw new RuntimeException("Pipeline execution failed", e); } return createPipelineResult(result, options); }
private ScopedContainer(MetricsContainer newContainer) { this.oldContainer = setCurrentContainer(newContainer); }
@Override public void update(long value) { MetricsContainer container = MetricsEnvironment.getCurrentContainer(); if (container != null) { container.getDistribution(name).update(value); } }
@Override public void processElement(final WindowedValue<InputT> elem) { try (Closeable ignored = MetricsEnvironment.scopedMetricsContainer(metricsContainer())) { delegate.processElement(elem); } catch (IOException e) { throw new RuntimeException(e); } }
logWarningIfPCollectionViewHasNonDeterministicKeyCoder(pipeline); MetricsEnvironment.setMetricsSupported(true);
@After public void teardown() { MetricsEnvironment.setCurrentContainer(null); }
@Test public void testBehavesWithoutMetricsContainer() { assertNull(MetricsEnvironment.getCurrentContainer()); } }
@Override public void startBundle() { try (Closeable ignored = MetricsEnvironment.scopedMetricsContainer(container.getMetricsContainer(stepName))) { delegate.startBundle(); } catch (IOException e) { throw new RuntimeException(e); } }
private PipelineResult runPipeline() throws Exception { MetricsEnvironment.setMetricsSupported(false); FlinkPortablePipelineTranslator<?> translator; if (!pipelineOptions.isStreaming() && !hasUnboundedPCollections(pipeline)) { // TODO: Do we need to inspect for unbounded sources before fusing? translator = FlinkBatchPortablePipelineTranslator.createTranslator(); } else { translator = new FlinkStreamingPortablePipelineTranslator(); } return runPipelineWithTranslator(translator); }
@After public void tearDown() { MetricsEnvironment.setCurrentContainer(null); }
@Test public void testDistributionWithoutContainer() { assertNull(MetricsEnvironment.getCurrentContainer()); // Should not fail even though there is no metrics container. Metrics.distribution(NS, NAME).update(5L); }
@Override public void startBundle() { try (Closeable ignored = MetricsEnvironment.scopedMetricsContainer(metricsContainer())) { delegate.startBundle(); } catch (IOException e) { throw new RuntimeException(e); } }
MetricsEnvironment.setMetricsSupported(true);