dmvk commented on a change in pull request #18566:
URL: https://github.com/apache/flink/pull/18566#discussion_r799434873
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/InternalExecutionGraphAccessor.java
##########
@@ -92,7 +92,10 @@
*/
void failGlobal(Throwable t);
- void notifyExecutionChange(final Execution execution, final ExecutionState
newExecutionState);
+ void notifyExecutionChange(
+ final Execution execution,
+ ExecutionState previousState,
+ final ExecutionState newExecutionState);
Review comment:
nit: it looks bit weird that some params are final here and some not (I
guess we can remove these completely)
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/ExecutionGraphFactory.java
##########
@@ -44,6 +45,7 @@
* attempts of previous runs
* @param vertexParallelismStore vertexMaxParallelismStore keeping
information about the vertex
* max parallelism settings
+ * @param executionStateUpdateListener
Review comment:
```suggestion
* @param executionStateUpdateListener listener for state transitions of
the individual executions
```
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/metrics/StateTimeMetric.java
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.metrics;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.metrics.MetricGroup;
+
+/** Utility to define metrics that capture the time that some component spends
in a state. */
+public interface StateTimeMetric {
+
+ /**
+ * Returns the time, in milliseconds, that have elapsed since we
transitioned to the targeted
+ * state. Returns 0 if we are not in the targeted state.
+ */
+ public long getCurrentTime();
+
+ /** Returns the total time, in milliseconds, that we have spent in the
targeted state. */
+ public long getTotalTime();
+
+ /** Returns 1 if we are in the targeted state, otherwise 0. */
+ public long getBinary();
+
+ public static void register(
Review comment:
```suggestion
long getCurrentTime();
/** Returns the total time, in milliseconds, that we have spent in the
targeted state. */
long getTotalTime();
/** Returns 1 if we are in the targeted state, otherwise 0. */
long getBinary();
static void register(
```
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/metrics/DeploymentStateTimeMetrics.java
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.metrics;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.ExecutionStateUpdateListener;
+import org.apache.flink.runtime.jobgraph.JobType;
+import org.apache.flink.util.clock.Clock;
+import org.apache.flink.util.clock.SystemClock;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Predicate;
+
+/**
+ * Metrics that capture how long a job was deploying tasks.
+ *
+ * <p>These metrics differentiate between batch & streaming use-cases:
+ *
+ * <p>Batch: Measures from the start of the first deployment until the first
task has been deployed.
+ * From that point the job is making progress.
+ *
+ * <p>Streaming: Measures from the start of the first deployment until all
tasks have been deployed.
+ * From that point on checkpoints can be triggered, and thus progress be made.
+ */
+public class DeploymentStateTimeMetrics
+ implements ExecutionStateUpdateListener, StateTimeMetric,
MetricsRegistrar {
+
+ private static final long NOT_STARTED = -1L;
+
+ private final Predicate<Integer> deploymentStartPredicate;
+ private final Predicate<Integer> deploymentEndPredicate;
+ private final MetricOptions.JobStatusMetricsSettings
stateTimeMetricsSettings;
+ private final Clock clock;
+
+ // deployment book-keeping
+ private final Set<ExecutionAttemptID> expectedDeployments = new
HashSet<>();
+ private int pendingDeployments = 0;
+ private int completedDeployments = 0;
+
+ // metrics state
+ private long deploymentStart = NOT_STARTED;
+ private long deploymentTimeTotal = 0L;
+
+ public DeploymentStateTimeMetrics(
+ JobType semantic, MetricOptions.JobStatusMetricsSettings
stateTimeMetricsSettings) {
+ this(semantic, stateTimeMetricsSettings, SystemClock.getInstance());
+ }
+
+ @VisibleForTesting
+ DeploymentStateTimeMetrics(
+ JobType semantic,
+ MetricOptions.JobStatusMetricsSettings stateTimeMetricsSettings,
+ Clock clock) {
+ this.stateTimeMetricsSettings = stateTimeMetricsSettings;
+ this.clock = clock;
+
+ switch (semantic) {
+ case BATCH:
+ deploymentStartPredicate = completedDeployments ->
completedDeployments == 0;
+ deploymentEndPredicate = completedDeployments ->
completedDeployments > 0;
+ break;
+ default:
+ deploymentStartPredicate = completedDeployments -> true;
+ deploymentEndPredicate =
+ completedDeployments -> completedDeployments ==
expectedDeployments.size();
+ break;
+ }
+ }
+
+ @Override
+ public long getCurrentTime() {
+ return deploymentStart == NOT_STARTED
+ ? 0L
+ : Math.max(0, clock.absoluteTimeMillis() - deploymentStart);
+ }
+
+ @Override
+ public long getTotalTime() {
+ return getCurrentTime() + deploymentTimeTotal;
+ }
+
+ @Override
+ public long getBinary() {
+ return deploymentStart == NOT_STARTED ? 0L : 1L;
+ }
+
+ @Override
+ public void registerMetrics(MetricGroup metricGroup) {
+ StateTimeMetric.register(stateTimeMetricsSettings, metricGroup, this,
"deploying");
+ }
+
+ @Override
+ public void onStateUpdate(
+ ExecutionAttemptID execution, ExecutionState previousState,
ExecutionState newState) {
Review comment:
🤔 should we have some guards against invalid transitions?
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/metrics/StateTimeMetric.java
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.metrics;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.metrics.MetricGroup;
+
+/** Utility to define metrics that capture the time that some component spends
in a state. */
+public interface StateTimeMetric {
+
+ /**
+ * Returns the time, in milliseconds, that have elapsed since we
transitioned to the targeted
+ * state. Returns 0 if we are not in the targeted state.
+ */
+ public long getCurrentTime();
+
+ /** Returns the total time, in milliseconds, that we have spent in the
targeted state. */
+ public long getTotalTime();
+
+ /** Returns 1 if we are in the targeted state, otherwise 0. */
+ public long getBinary();
Review comment:
I'm always wondering, what's the threading model for reading metrics?
Does it differ between reporters? Is it synchronized?
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/metrics/DeploymentStateTimeMetrics.java
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.metrics;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.ExecutionStateUpdateListener;
+import org.apache.flink.runtime.jobgraph.JobType;
+import org.apache.flink.util.clock.Clock;
+import org.apache.flink.util.clock.SystemClock;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Predicate;
+
+/**
+ * Metrics that capture how long a job was deploying tasks.
+ *
+ * <p>These metrics differentiate between batch & streaming use-cases:
+ *
+ * <p>Batch: Measures from the start of the first deployment until the first
task has been deployed.
+ * From that point the job is making progress.
+ *
+ * <p>Streaming: Measures from the start of the first deployment until all
tasks have been deployed.
+ * From that point on checkpoints can be triggered, and thus progress be made.
+ */
+public class DeploymentStateTimeMetrics
+ implements ExecutionStateUpdateListener, StateTimeMetric,
MetricsRegistrar {
+
+ private static final long NOT_STARTED = -1L;
+
+ private final Predicate<Integer> deploymentStartPredicate;
+ private final Predicate<Integer> deploymentEndPredicate;
+ private final MetricOptions.JobStatusMetricsSettings
stateTimeMetricsSettings;
+ private final Clock clock;
+
+ // deployment book-keeping
+ private final Set<ExecutionAttemptID> expectedDeployments = new
HashSet<>();
+ private int pendingDeployments = 0;
+ private int completedDeployments = 0;
+
+ // metrics state
+ private long deploymentStart = NOT_STARTED;
+ private long deploymentTimeTotal = 0L;
+
+ public DeploymentStateTimeMetrics(
+ JobType semantic, MetricOptions.JobStatusMetricsSettings
stateTimeMetricsSettings) {
+ this(semantic, stateTimeMetricsSettings, SystemClock.getInstance());
+ }
+
+ @VisibleForTesting
+ DeploymentStateTimeMetrics(
+ JobType semantic,
+ MetricOptions.JobStatusMetricsSettings stateTimeMetricsSettings,
+ Clock clock) {
+ this.stateTimeMetricsSettings = stateTimeMetricsSettings;
+ this.clock = clock;
+
+ switch (semantic) {
+ case BATCH:
+ deploymentStartPredicate = completedDeployments ->
completedDeployments == 0;
+ deploymentEndPredicate = completedDeployments ->
completedDeployments > 0;
+ break;
+ default:
+ deploymentStartPredicate = completedDeployments -> true;
+ deploymentEndPredicate =
+ completedDeployments -> completedDeployments ==
expectedDeployments.size();
+ break;
+ }
Review comment:
could be replaced by simple if - else;
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]