org.apache.flink.runtime.metrics.dump.MetricQueryService Java Examples

The following examples show how to use org.apache.flink.runtime.metrics.dump.MetricQueryService. 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: MetricRegistryImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the MetricQueryService.
 *
 * @param actorSystem ActorSystem to create the MetricQueryService on
 * @param resourceID resource ID used to disambiguate the actor name
    */
public void startQueryService(ActorSystem actorSystem, ResourceID resourceID) {
	synchronized (lock) {
		Preconditions.checkState(!isShutdown(), "The metric registry has already been shut down.");

		try {
			queryService = MetricQueryService.startMetricQueryService(actorSystem, resourceID, maximumFramesize);
			metricQueryServicePath = AkkaUtils.getAkkaURL(actorSystem, queryService);
		} catch (Exception e) {
			LOG.warn("Could not start MetricDumpActor. No metrics will be submitted to the WebInterface.", e);
		}
	}
}
 
Example #2
Source File: AkkaQueryServiceGateway.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<MetricDumpSerialization.MetricSerializationResult> queryMetrics(Time timeout) {
	return FutureUtils.toJava(
		Patterns.ask(queryServiceActorRef, MetricQueryService.getCreateDump(), timeout.toMilliseconds())
			.mapTo(ClassTag$.MODULE$.apply(MetricDumpSerialization.MetricSerializationResult.class))
	);
}
 
Example #3
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the MetricQueryService.
 *
 * @param rpcService RpcService to create the MetricQueryService on
 * @param resourceID resource ID used to disambiguate the actor name
    */
public void startQueryService(RpcService rpcService, ResourceID resourceID) {
	synchronized (lock) {
		Preconditions.checkState(!isShutdown(), "The metric registry has already been shut down.");

		try {
			metricQueryServiceRpcService = rpcService;
			queryService = MetricQueryService.createMetricQueryService(rpcService, resourceID, maximumFramesize);
			queryService.start();
		} catch (Exception e) {
			LOG.warn("Could not start MetricDumpActor. No metrics will be submitted to the WebInterface.", e);
		}
	}
}
 
Example #4
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the MetricQueryService.
 *
 * @param rpcService RpcService to create the MetricQueryService on
 * @param resourceID resource ID used to disambiguate the actor name
    */
public void startQueryService(RpcService rpcService, ResourceID resourceID) {
	synchronized (lock) {
		Preconditions.checkState(!isShutdown(), "The metric registry has already been shut down.");

		try {
			metricQueryServiceRpcService = rpcService;
			queryService = MetricQueryService.createMetricQueryService(rpcService, resourceID, maximumFramesize);
			queryService.start();
		} catch (Exception e) {
			LOG.warn("Could not start MetricDumpActor. No metrics will be submitted to the WebInterface.", e);
		}
	}
}
 
Example #5
Source File: MetricFetcherTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testUpdate() {
	final Time timeout = Time.seconds(10L);

	// ========= setup TaskManager =================================================================================
	JobID jobID = new JobID();
	ResourceID tmRID = ResourceID.generate();

	// ========= setup JobManager ==================================================================================

	final String jmMetricQueryServicePath = "/jm/" + MetricQueryService.METRIC_QUERY_SERVICE_NAME;
	final String tmMetricQueryServicePath = "/tm/" + MetricQueryService.METRIC_QUERY_SERVICE_NAME + "_" + tmRID.getResourceIdString();

	final TestingRestfulGateway restfulGateway = new TestingRestfulGateway.Builder()
		.setRequestMultipleJobDetailsSupplier(() -> CompletableFuture.completedFuture(new MultipleJobsDetails(Collections.emptyList())))
		.setRequestMetricQueryServicePathsSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(jmMetricQueryServicePath)))
		.setRequestTaskManagerMetricQueryServicePathsSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(Tuple2.of(tmRID, tmMetricQueryServicePath))))
		.build();

	final GatewayRetriever<RestfulGateway> retriever = () -> CompletableFuture.completedFuture(restfulGateway);

	// ========= 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();

	final MetricQueryServiceRetriever queryServiceRetriever = (path) -> {
		if (path.equals(jmMetricQueryServicePath))  {
			return CompletableFuture.completedFuture(jmQueryService);
		} else if (path.equals(tmMetricQueryServicePath)) {
			return CompletableFuture.completedFuture(tmQueryService);
		} else {
			throw new IllegalArgumentException("Unexpected argument.");
		}
	};

	// ========= start MetricFetcher testing =======================================================================
	MetricFetcher fetcher = new MetricFetcherImpl<>(
		retriever,
		queryServiceRetriever,
		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"));
	}
}
 
Example #6
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
@Nullable
MetricQueryService getQueryService() {
	return queryService;
}
 
Example #7
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the query actor will be stopped when the MetricRegistry is shut down.
 */
@Test
public void testQueryActorShutdown() throws Exception {
	final FiniteDuration timeout = new FiniteDuration(10L, TimeUnit.SECONDS);

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());

	final RpcService rpcService = new TestingRpcService();

	registry.startQueryService(rpcService, null);

	MetricQueryService queryService = checkNotNull(registry.getQueryService());

	registry.shutdown().get();

	queryService.getTerminationFuture().get(timeout.toMillis(), TimeUnit.MILLISECONDS);
}
 
Example #8
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
@Nullable
MetricQueryService getQueryService() {
	return queryService;
}
 
Example #9
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the query actor will be stopped when the MetricRegistry is shut down.
 */
@Test
public void testQueryActorShutdown() throws Exception {
	final Duration timeout = Duration.ofSeconds(10L);

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.defaultMetricRegistryConfiguration());

	final RpcService rpcService = new TestingRpcService();

	registry.startQueryService(rpcService, null);

	MetricQueryService queryService = checkNotNull(registry.getQueryService());

	registry.shutdown().get();

	queryService.getTerminationFuture().get(timeout.toMillis(), TimeUnit.MILLISECONDS);
}