Search in sources :

Example 1 with MetricQueryServiceGateway

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);
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricQueryServiceGateway(org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 2 with MetricQueryServiceGateway

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"));
    }
}
Also used : MetricQueryServiceGateway(org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway) TestingMetricQueryServiceGateway(org.apache.flink.runtime.metrics.dump.TestingMetricQueryServiceGateway) Time(org.apache.flink.api.common.time.Time) MultipleJobsDetails(org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) JobID(org.apache.flink.api.common.JobID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Aggregations

ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 MetricDumpSerialization (org.apache.flink.runtime.metrics.dump.MetricDumpSerialization)2 MetricQueryServiceGateway (org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway)2 Test (org.junit.Test)2 JobID (org.apache.flink.api.common.JobID)1 Time (org.apache.flink.api.common.time.Time)1 SimpleCounter (org.apache.flink.metrics.SimpleCounter)1 MultipleJobsDetails (org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails)1 TestingMetricQueryServiceGateway (org.apache.flink.runtime.metrics.dump.TestingMetricQueryServiceGateway)1 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)1 TestingRpcService (org.apache.flink.runtime.rpc.TestingRpcService)1 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)1 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)1