@Override public GaugeResult extractResult() { return GaugeResult.empty(); } }
public static Map<String, Long> getMetrics(PipelineResult result) { final MetricQueryResults metricQueryResults = result.metrics().queryMetrics(MetricsFilter.builder().build()); final Map<String, Long> gauges = StreamSupport.stream(metricQueryResults.getGauges().spliterator(), false) .collect(Collectors.groupingBy( MetricResult::getName, Collectors.reducing(GaugeResult.empty(), GET_COMMITTED_GAUGE, BinaryOperator.maxBy( Comparator.comparing(GaugeResult::getTimestamp))))) .entrySet().stream() .collect(Collectors.toMap(e -> e.getKey().getName(), e -> e.getValue().getValue())); final Map<String, Long> counters = StreamSupport.stream( metricQueryResults.getCounters().spliterator(), false) .collect(Collectors.groupingBy(m -> m.getName().getName(), Collectors.summingLong(GET_COMMITTED_COUNTER))); Map<String, Long> ret = new HashMap<>(); ret.putAll(gauges); ret.putAll(counters); return Collections.unmodifiableMap(ret); }
@Test public void testGauge() { FlinkMetricContainer.FlinkGauge flinkGauge = new FlinkMetricContainer.FlinkGauge(GaugeResult.empty()); when(metricGroup.gauge(eq("namespace.name"), anyObject())).thenReturn(flinkGauge); FlinkMetricContainer container = new FlinkMetricContainer(runtimeContext); MetricsContainer step = container.getMetricsContainer("step"); MetricName metricName = MetricName.named("namespace", "name"); Gauge gauge = step.getGauge(metricName); assertThat(flinkGauge.getValue(), is(GaugeResult.empty())); // first set will install the mocked gauge container.updateMetrics("step"); gauge.set(1); gauge.set(42); container.updateMetrics("step"); assertThat(flinkGauge.getValue().getValue(), is(42L)); }
@Test public void testGaugeCommittedUnsupportedInAttemptedAccumulatedMetricResults() { MetricsContainerStepMap attemptedMetrics = new MetricsContainerStepMap(); attemptedMetrics.update(STEP1, metricsContainer); MetricResults metricResults = asAttemptedOnlyMetricResults(attemptedMetrics); MetricQueryResults step1res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP1).build()); thrown.expect(UnsupportedOperationException.class); thrown.expectMessage("This runner does not currently support committed metrics results."); assertGauge(GAUGE_NAME, step1res, STEP1, GaugeResult.empty(), true); }
assertThat( results.getGauges(), contains(attemptedMetricsResult("ns2", "name2", "step1", GaugeResult.empty()))); assertThat( results.getGauges(),
assertThat( results.getGauges(), contains(attemptedMetricsResult("ns2", "name2", "step1", GaugeResult.empty()))); assertThat( results.getGauges(),