use of org.apache.flink.runtime.rest.RestClient in project flink by apache.
the class MetricQuerier method getAggregatedMetricsByRestAPI.
public Double getAggregatedMetricsByRestAPI(TestEnvironment.Endpoint endpoint, JobID jobId, String sourceOrSinkName, String metricName, String filter) throws Exception {
// get job details, including the vertex id
JobDetailsInfo jobDetailsInfo = getJobDetails(restClient, endpoint, jobId);
// get the vertex id for source/sink operator
JobDetailsInfo.JobVertexDetailsInfo vertex = jobDetailsInfo.getJobVertexInfos().stream().filter(v -> v.getName().contains(sourceOrSinkName)).findAny().orElse(null);
assertThat(vertex).isNotNull();
JobVertexID vertexId = vertex.getJobVertexID();
// get the metric list
AggregatedMetricsResponseBody metricsResponseBody = getMetricList(endpoint, jobId, vertexId);
// get the metric query filters
String queryParam = metricsResponseBody.getMetrics().stream().filter(m -> filterByMetricName(m.getId(), sourceOrSinkName, metricName, filter)).map(m -> m.getId()).collect(Collectors.joining(","));
if (StringUtils.isNullOrWhitespaceOnly(queryParam)) {
throw new IllegalStateException(String.format("Cannot find metric[%s] for operator [%s].", metricName, sourceOrSinkName));
}
AggregatedMetricsResponseBody metricsResponse = getMetrics(endpoint, jobId, vertexId, queryParam);
Collection<AggregatedMetric> metrics = metricsResponse.getMetrics();
if (metrics == null || metrics.isEmpty()) {
throw new IllegalStateException(String.format("Cannot find metric[%s] for operator [%s] with filter [%s].", metricName, sourceOrSinkName, filter));
}
return metrics.iterator().next().getSum();
}
use of org.apache.flink.runtime.rest.RestClient in project flink by apache.
the class LocalRecoveryITCase method waitUntilCheckpointCompleted.
private void waitUntilCheckpointCompleted(Configuration configuration, int restPort, JobID jobId, Deadline deadline) throws Exception {
final RestClient restClient = new RestClient(configuration, Executors.directExecutor());
final JobMessageParameters messageParameters = new JobMessageParameters();
messageParameters.jobPathParameter.resolve(jobId);
CommonTestUtils.waitUntilCondition(() -> {
final CheckpointingStatistics checkpointingStatistics = restClient.sendRequest("localhost", restPort, CheckpointingStatisticsHeaders.getInstance(), messageParameters, EmptyRequestBody.getInstance()).join();
return checkpointingStatistics.getCounts().getNumberCompletedCheckpoints() > 0;
}, deadline);
}
Aggregations