diff --git a/src/clusterfuzz/_internal/build_management/build_manager.py b/src/clusterfuzz/_internal/build_management/build_manager.py index 67f3b1d945..4397e7610a 100644 --- a/src/clusterfuzz/_internal/build_management/build_manager.py +++ b/src/clusterfuzz/_internal/build_management/build_manager.py @@ -1227,6 +1227,17 @@ def _emit_build_age_metric(gcs_path): logs.error(f'Failed to emit build age metric for {gcs_path}: {e}') +def _emit_build_revision_metric(revision): + """Emits a gauge metric to track the build revision.""" + monitoring_metrics.JOB_BUILD_REVISION.set( + revision, + labels={ + 'job': os.getenv('JOB_NAME'), + 'platform': environment.platform(), + 'task': os.getenv('TASK_NAME'), + }) + + def _get_build_url(bucket_path: Optional[str], revision: int, job_type: Optional[str]): """Returns the GCS url for a build, given a bucket path and revision""" @@ -1297,6 +1308,7 @@ def setup_regular_build(revision, if revision == latest_revision: _emit_build_age_metric(build_url) + _emit_build_revision_metric(revision) # build_url points to a GCP bucket, and we're only converting it to its HTTP # endpoint so that we can use remote unzipping. diff --git a/src/clusterfuzz/_internal/metrics/monitoring_metrics.py b/src/clusterfuzz/_internal/metrics/monitoring_metrics.py index eff05fe3fc..58489eae45 100644 --- a/src/clusterfuzz/_internal/metrics/monitoring_metrics.py +++ b/src/clusterfuzz/_internal/metrics/monitoring_metrics.py @@ -44,6 +44,17 @@ ], ) +JOB_BUILD_REVISION = monitor.GaugeMetric( + 'job/build_revision', + description=('Gauge for revision of trunk build ' + '(grouped by job/platform/task).'), + field_spec=[ + monitor.StringField('job'), + monitor.StringField('platform'), + monitor.StringField('task'), + ], +) + JOB_BUILD_RETRIEVAL_TIME = monitor.CumulativeDistributionMetric( 'task/build_retrieval_time', bucketer=monitor.GeometricBucketer(),