use of org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway in project flink by apache.
the class MetricRegistryImplTest method testMetricQueryServiceSetup.
@Test
public void testMetricQueryServiceSetup() throws Exception {
MetricRegistryImpl metricRegistry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration());
Assert.assertNull(metricRegistry.getMetricQueryServiceGatewayRpcAddress());
metricRegistry.startQueryService(new TestingRpcService(), new ResourceID("mqs"));
MetricQueryServiceGateway metricQueryServiceGateway = metricRegistry.getMetricQueryServiceGateway();
Assert.assertNotNull(metricQueryServiceGateway);
metricRegistry.register(new SimpleCounter(), "counter", UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup());
boolean metricsSuccessfullyQueried = false;
for (int x = 0; x < 10; x++) {
MetricDumpSerialization.MetricSerializationResult metricSerializationResult = metricQueryServiceGateway.queryMetrics(Time.seconds(5)).get(5, TimeUnit.SECONDS);
if (metricSerializationResult.numCounters == 1) {
metricsSuccessfullyQueried = true;
} else {
Thread.sleep(50);
}
}
Assert.assertTrue("metrics query did not return expected result", metricsSuccessfullyQueried);
}
use of org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway in project flink by apache.
the class MetricFetcherTest method testUpdate.
@Test
public void testUpdate() {
final Time timeout = Time.seconds(10L);
// ========= setup TaskManager
// =================================================================================
JobID jobID = new JobID();
ResourceID tmRID = ResourceID.generate();
// ========= setup QueryServices
// ================================================================================
final MetricQueryServiceGateway jmQueryService = new TestingMetricQueryServiceGateway.Builder().setQueryMetricsSupplier(() -> CompletableFuture.completedFuture(new MetricDumpSerialization.MetricSerializationResult(new byte[0], new byte[0], new byte[0], new byte[0], 0, 0, 0, 0))).build();
MetricDumpSerialization.MetricSerializationResult requestMetricsAnswer = createRequestDumpAnswer(tmRID, jobID);
final MetricQueryServiceGateway tmQueryService = new TestingMetricQueryServiceGateway.Builder().setQueryMetricsSupplier(() -> CompletableFuture.completedFuture(requestMetricsAnswer)).build();
// ========= setup JobManager
// ==================================================================================
final TestingRestfulGateway restfulGateway = new TestingRestfulGateway.Builder().setRequestMultipleJobDetailsSupplier(() -> CompletableFuture.completedFuture(new MultipleJobsDetails(Collections.emptyList()))).setRequestMetricQueryServiceGatewaysSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(jmQueryService.getAddress()))).setRequestTaskManagerMetricQueryServiceGatewaysSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(Tuple2.of(tmRID, tmQueryService.getAddress())))).build();
final GatewayRetriever<RestfulGateway> retriever = () -> CompletableFuture.completedFuture(restfulGateway);
// ========= start MetricFetcher testing
// =======================================================================
MetricFetcher fetcher = new MetricFetcherImpl<>(retriever, address -> CompletableFuture.completedFuture(tmQueryService), Executors.directExecutor(), timeout, MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
// verify that update fetches metrics and updates the store
fetcher.update();
MetricStore store = fetcher.getMetricStore();
synchronized (store) {
assertEquals("7", store.getJobManagerMetricStore().getMetric("abc.hist_min"));
assertEquals("6", store.getJobManagerMetricStore().getMetric("abc.hist_max"));
assertEquals("4.0", store.getJobManagerMetricStore().getMetric("abc.hist_mean"));
assertEquals("0.5", store.getJobManagerMetricStore().getMetric("abc.hist_median"));
assertEquals("5.0", store.getJobManagerMetricStore().getMetric("abc.hist_stddev"));
assertEquals("0.75", store.getJobManagerMetricStore().getMetric("abc.hist_p75"));
assertEquals("0.9", store.getJobManagerMetricStore().getMetric("abc.hist_p90"));
assertEquals("0.95", store.getJobManagerMetricStore().getMetric("abc.hist_p95"));
assertEquals("0.98", store.getJobManagerMetricStore().getMetric("abc.hist_p98"));
assertEquals("0.99", store.getJobManagerMetricStore().getMetric("abc.hist_p99"));
assertEquals("0.999", store.getJobManagerMetricStore().getMetric("abc.hist_p999"));
assertEquals("x", store.getTaskManagerMetricStore(tmRID.toString()).metrics.get("abc.gauge"));
assertEquals("5.0", store.getJobMetricStore(jobID.toString()).metrics.get("abc.jc"));
assertEquals("2", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.abc.tc"));
assertEquals("1", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.opname.abc.oc"));
}
}
Aggregations