From aff56e0858a1cf1cb6ad4efe9b5deb67bbea9151 Mon Sep 17 00:00:00 2001 From: Joshna907 Date: Thu, 20 Aug 2026 15:34:59 +0530 Subject: [PATCH] prometheus: util: Support Argo CD Application metrics Signed-off-by: Joshna907 --- prometheus/src/util.test.ts | 36 +++++++++++++++++++++++++++++++++++- prometheus/src/util.ts | 12 ++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/prometheus/src/util.test.ts b/prometheus/src/util.test.ts index cd59395d85..7e145d45d1 100644 --- a/prometheus/src/util.test.ts +++ b/prometheus/src/util.test.ts @@ -1,4 +1,4 @@ -import { getTimeRangeAndStepSize, supportsPrometheusMetrics } from './util'; +import { getTimeRangeAndStepSize, isArgoCDApplication, supportsPrometheusMetrics } from './util'; beforeAll(async () => { global.TextEncoder = require('util').TextEncoder; @@ -138,9 +138,43 @@ describe('supportsPrometheusMetrics', () => { false, ], ['rejects Queues without apiVersion', { kind: 'Queue', jsonData: { kind: 'Queue' } }, false], + [ + 'does not show Application metrics before the chart UI is available', + { + kind: 'Application', + jsonData: { kind: 'Application', apiVersion: 'argoproj.io/v1alpha1' }, + }, + false, + ], + [ + 'rejects non-Argo Applications with the same kind', + { kind: 'Application', jsonData: { kind: 'Application', apiVersion: 'example.com/v1' } }, + false, + ], ['rejects unknown kinds', { kind: 'VolcanoJob', jsonData: { kind: 'VolcanoJob' } }, false], ['rejects missing resources', undefined, false], ])('%s', (_, resource, expected) => { expect(supportsPrometheusMetrics(resource)).toBe(expected); }); }); + +describe('isArgoCDApplication', () => { + test.each([ + [ + 'recognizes the Argo CD Application CRD', + { + kind: 'Application', + jsonData: { kind: 'Application', apiVersion: 'argoproj.io/v1alpha1' }, + }, + true, + ], + [ + 'rejects another Application kind', + { kind: 'Application', jsonData: { kind: 'Application', apiVersion: 'example.com/v1' } }, + false, + ], + ['rejects an Application without an API version', { kind: 'Application' }, false], + ])('%s', (_, resource, expected) => { + expect(isArgoCDApplication(resource)).toBe(expected); + }); +}); diff --git a/prometheus/src/util.ts b/prometheus/src/util.ts index 1e64c74eb3..321cba5de9 100644 --- a/prometheus/src/util.ts +++ b/prometheus/src/util.ts @@ -174,6 +174,18 @@ const resourceApiVersionRules: Record = { Revision: /^serving\.knative\.dev\/v1$/, }; +/** + * Returns whether a resource is the Argo CD Application CRD that exposes the + * Application-specific Prometheus metrics. This is deliberately separate from + * the chart allowlist: the chart UI is added by the follow-up feature. + */ +export function isArgoCDApplication(resource?: ResourceIdentity): boolean { + return ( + getResourceKind(resource) === 'Application' && + getResourceApiVersion(resource) === 'argoproj.io/v1alpha1' + ); +} + export function supportsPrometheusMetrics(resource?: ResourceIdentity): boolean { const kind = getResourceKind(resource);