Search in sources :

Example 11 with RestClient

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();
}
Also used : AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) MessagePathParameter(org.apache.flink.runtime.rest.messages.MessagePathParameter) ConfigurationException(org.apache.flink.util.ConfigurationException) LoggerFactory(org.slf4j.LoggerFactory) JobVertexIdPathParameter(org.apache.flink.runtime.rest.messages.JobVertexIdPathParameter) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) AggregatedMetricsResponseBody(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody) JobDetailsHeaders(org.apache.flink.runtime.rest.messages.job.JobDetailsHeaders) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) Nullable(javax.annotation.Nullable) TestEnvironment(org.apache.flink.connector.testframe.environment.TestEnvironment) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MetricsFilterParameter(org.apache.flink.runtime.rest.messages.job.metrics.MetricsFilterParameter) JobDetailsInfo(org.apache.flink.runtime.rest.messages.job.JobDetailsInfo) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) StringUtils(org.apache.flink.util.StringUtils) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) AggregatedSubtaskMetricsParameters(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedSubtaskMetricsParameters) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) AggregatedSubtaskMetricsHeaders(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedSubtaskMetricsHeaders) RestClient(org.apache.flink.runtime.rest.RestClient) AggregatedMetric(org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) JobDetailsInfo(org.apache.flink.runtime.rest.messages.job.JobDetailsInfo)

Example 12 with RestClient

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);
}
Also used : CheckpointingStatistics(org.apache.flink.runtime.rest.messages.checkpoints.CheckpointingStatistics) RestClient(org.apache.flink.runtime.rest.RestClient) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters)

Aggregations

RestClient (org.apache.flink.runtime.rest.RestClient)12 Configuration (org.apache.flink.configuration.Configuration)10 ExecutorService (java.util.concurrent.ExecutorService)3 DEFAULT_COLLECT_DATA_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_COLLECT_DATA_TIMEOUT)3 DEFAULT_JOB_STATUS_CHANGE_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_JOB_STATUS_CHANGE_TIMEOUT)3 JobClient (org.apache.flink.core.execution.JobClient)3 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)3 Test (org.junit.Test)3 TestAbortedException (org.opentest4j.TestAbortedException)3 ExecutionException (java.util.concurrent.ExecutionException)2 TestingSinkSettings (org.apache.flink.connector.testframe.external.sink.TestingSinkSettings)2 FromElementsSource (org.apache.flink.connector.testframe.source.FromElementsSource)2 MetricQuerier (org.apache.flink.connector.testframe.utils.MetricQuerier)2 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)2 JobMessageParameters (org.apache.flink.runtime.rest.messages.JobMessageParameters)2 TaskManagersInfo (org.apache.flink.runtime.rest.messages.taskmanager.TaskManagersInfo)2 ConfigurationException (org.apache.flink.util.ConfigurationException)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 DisplayName (org.junit.jupiter.api.DisplayName)2 TestTemplate (org.junit.jupiter.api.TestTemplate)2