All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.runtime.executiongraph.metrics.RestartTimeGauge Maven / Gradle / Ivy

There is a newer version: 1.13.6
Show newest version
/*
 * 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.executiongraph.metrics;

import org.apache.flink.api.common.JobStatus;
import org.apache.flink.metrics.Gauge;
import org.apache.flink.runtime.executiongraph.JobStatusProvider;

import static org.apache.flink.util.Preconditions.checkNotNull;

/**
 * Gauge which returns the last restarting time.
 *
 * 

Restarting time is the time between {@link JobStatus#RESTARTING} and {@link * JobStatus#RUNNING}, or a terminal state if {@link JobStatus#RUNNING} was not reached. * *

If the job has not yet reached either of these states, then the time is measured since * reaching {@link JobStatus#RESTARTING}. If it is still the initial job execution, then the gauge * will return 0. */ public class RestartTimeGauge implements Gauge { public static final String METRIC_NAME = "restartingTime"; // ------------------------------------------------------------------------ private final JobStatusProvider jobStatusProvider; public RestartTimeGauge(JobStatusProvider jobStatusProvider) { this.jobStatusProvider = checkNotNull(jobStatusProvider); } // ------------------------------------------------------------------------ @Override public Long getValue() { final JobStatus status = jobStatusProvider.getState(); final long restartingTimestamp = jobStatusProvider.getStatusTimestamp(JobStatus.RESTARTING); final long switchToRunningTimestamp; final long lastRestartTime; if (restartingTimestamp <= 0) { // we haven't yet restarted our job return 0L; } else if ((switchToRunningTimestamp = jobStatusProvider.getStatusTimestamp(JobStatus.RUNNING)) >= restartingTimestamp) { // we have transitioned to RUNNING since the last restart lastRestartTime = switchToRunningTimestamp - restartingTimestamp; } else if (status.isTerminalState()) { // since the last restart we've switched to a terminal state without touching // the RUNNING state (e.g. failing from RESTARTING) lastRestartTime = jobStatusProvider.getStatusTimestamp(status) - restartingTimestamp; } else { // we're still somewhere between RESTARTING and RUNNING lastRestartTime = System.currentTimeMillis() - restartingTimestamp; } // we guard this with 'Math.max' to avoid negative timestamps when clocks re-sync return Math.max(lastRestartTime, 0); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy