Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion prometheus/src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTimeRangeAndStepSize, supportsPrometheusMetrics } from './util';
import { getTimeRangeAndStepSize, isArgoCDApplication, supportsPrometheusMetrics } from './util';

beforeAll(async () => {
global.TextEncoder = require('util').TextEncoder;
Expand Down Expand Up @@ -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);
});
});
12 changes: 12 additions & 0 deletions prometheus/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ const resourceApiVersionRules: Record<string, RegExp> = {
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);

Expand Down
Loading