setIsExpanded(!isExpanded)} />
|
- {name} {isProvisioned && }{' '}
+ {name} {isProvisioned && }{' '}
{missing && !isGrafanaAlertmanager && (
)}
- {contactPoint?.provisioned && hasLegacyIntegrations(contactPoint, grafanaNotifiers) && (
-
- )}
- {contactPoint?.provisioned && !hasLegacyIntegrations(contactPoint, grafanaNotifiers) && (
+ {isProvisioned && hasLegacyIntegrations(contactPoint, grafanaNotifiers) && }
+ {isProvisioned && !hasLegacyIntegrations(contactPoint, grafanaNotifiers) && (
)}
diff --git a/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx b/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx
index 6134ace8fbb..866f489e6fa 100644
--- a/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx
+++ b/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx
@@ -7,8 +7,8 @@ import { grantUserPermissions } from 'app/features/alerting/unified/mocks';
import { getAlertmanagerConfig } from 'app/features/alerting/unified/mocks/server/entities/alertmanagers';
import { AlertmanagerProvider } from 'app/features/alerting/unified/state/AlertmanagerContext';
import { NotificationChannelOption } from 'app/features/alerting/unified/types/alerting';
+import { KnownProvenance } from 'app/features/alerting/unified/types/knownProvenance';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
-import { PROVENANCE_NONE } from 'app/features/alerting/unified/utils/k8s/constants';
import { DEFAULT_TEMPLATES } from 'app/features/alerting/unified/utils/template-constants';
import { AccessControlAction } from 'app/types/accessControl';
@@ -68,7 +68,7 @@ describe('getTemplateOptions function', () => {
uid: title,
title,
content,
- provenance: PROVENANCE_NONE,
+ provenance: KnownProvenance.None,
};
});
const defaultTemplates = parseTemplates(DEFAULT_TEMPLATES);
diff --git a/public/app/features/alerting/unified/mocks/server/entities/k8s/routingtrees.ts b/public/app/features/alerting/unified/mocks/server/entities/k8s/routingtrees.ts
index 9babb1332bf..1005267badf 100644
--- a/public/app/features/alerting/unified/mocks/server/entities/k8s/routingtrees.ts
+++ b/public/app/features/alerting/unified/mocks/server/entities/k8s/routingtrees.ts
@@ -4,7 +4,8 @@ import {
ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Route,
ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1RoutingTree,
} from 'app/features/alerting/unified/openapi/routesApi.gen';
-import { K8sAnnotations, PROVENANCE_NONE, ROOT_ROUTE_NAME } from 'app/features/alerting/unified/utils/k8s/constants';
+import { KnownProvenance } from 'app/features/alerting/unified/types/knownProvenance';
+import { K8sAnnotations, ROOT_ROUTE_NAME } from 'app/features/alerting/unified/utils/k8s/constants';
import { AlertManagerCortexConfig, MatcherOperator, Route } from 'app/plugins/datasource/alertmanager/types';
/**
@@ -66,7 +67,7 @@ export const getUserDefinedRoutingTree: (
name: ROOT_ROUTE_NAME,
namespace: 'default',
annotations: {
- [K8sAnnotations.Provenance]: PROVENANCE_NONE,
+ [K8sAnnotations.Provenance]: KnownProvenance.None,
},
// Resource versions are much shorter than this in reality, but this is an easy way
// for us to mock the concurrency logic and check if the policies have updated since the last fetch
diff --git a/public/app/features/alerting/unified/mocks/server/handlers/k8s/receivers.k8s.ts b/public/app/features/alerting/unified/mocks/server/handlers/k8s/receivers.k8s.ts
index a620fe528c2..177b5c23499 100644
--- a/public/app/features/alerting/unified/mocks/server/handlers/k8s/receivers.k8s.ts
+++ b/public/app/features/alerting/unified/mocks/server/handlers/k8s/receivers.k8s.ts
@@ -6,8 +6,9 @@ import {
} from 'app/features/alerting/unified/mocks/server/entities/alertmanagers';
import { ALERTING_API_SERVER_BASE_URL, getK8sResponse } from 'app/features/alerting/unified/mocks/server/utils';
import { ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1Receiver } from 'app/features/alerting/unified/openapi/receiversApi.gen';
+import { KnownProvenance } from 'app/features/alerting/unified/types/knownProvenance';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
-import { K8sAnnotations, PROVENANCE_NONE } from 'app/features/alerting/unified/utils/k8s/constants';
+import { K8sAnnotations } from 'app/features/alerting/unified/utils/k8s/constants';
const usedByPolicies = ['grafana-default-email'];
const usedByRules = ['grafana-default-email'];
@@ -23,7 +24,7 @@ const getReceiversList = () => {
const provenance =
contactPoint.grafana_managed_receiver_configs?.find((integration) => {
return integration.provenance;
- })?.provenance || PROVENANCE_NONE;
+ })?.provenance || KnownProvenance.None;
return {
metadata: {
// This isn't exactly accurate, but its the cleanest way to use the same data for AM config and K8S responses
diff --git a/public/app/features/alerting/unified/mocks/server/handlers/k8s/templates.k8s.ts b/public/app/features/alerting/unified/mocks/server/handlers/k8s/templates.k8s.ts
index f3baa318342..fff0d120629 100644
--- a/public/app/features/alerting/unified/mocks/server/handlers/k8s/templates.k8s.ts
+++ b/public/app/features/alerting/unified/mocks/server/handlers/k8s/templates.k8s.ts
@@ -3,8 +3,9 @@ import { HttpResponse, http } from 'msw';
import { getAlertmanagerConfig } from 'app/features/alerting/unified/mocks/server/entities/alertmanagers';
import { ALERTING_API_SERVER_BASE_URL, getK8sResponse } from 'app/features/alerting/unified/mocks/server/utils';
import { ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1TemplateGroup } from 'app/features/alerting/unified/openapi/templatesApi.gen';
+import { KnownProvenance } from 'app/features/alerting/unified/types/knownProvenance';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
-import { PROVENANCE_ANNOTATION, PROVENANCE_NONE } from 'app/features/alerting/unified/utils/k8s/constants';
+import { PROVENANCE_ANNOTATION } from 'app/features/alerting/unified/utils/k8s/constants';
const config = getAlertmanagerConfig(GRAFANA_RULES_SOURCE_NAME);
@@ -14,7 +15,7 @@ const mappedTemplates = Object.entries(
).map(([title, template]) => ({
metadata: {
name: titleToK8sResourceName(title), // K8s uses unique identifiers for resources
- annotations: { [PROVENANCE_ANNOTATION]: config.template_file_provenances?.[title] || PROVENANCE_NONE },
+ annotations: { [PROVENANCE_ANNOTATION]: config.template_file_provenances?.[title] || KnownProvenance.None },
},
spec: {
title: title,
diff --git a/public/app/features/alerting/unified/mocks/server/handlers/k8s/timeIntervals.k8s.ts b/public/app/features/alerting/unified/mocks/server/handlers/k8s/timeIntervals.k8s.ts
index 84503c2ce13..77f6eef9f50 100644
--- a/public/app/features/alerting/unified/mocks/server/handlers/k8s/timeIntervals.k8s.ts
+++ b/public/app/features/alerting/unified/mocks/server/handlers/k8s/timeIntervals.k8s.ts
@@ -4,7 +4,8 @@ import { base64UrlEncode } from '@grafana/alerting';
import { filterBySelector } from 'app/features/alerting/unified/mocks/server/handlers/k8s/utils';
import { ALERTING_API_SERVER_BASE_URL, getK8sResponse } from 'app/features/alerting/unified/mocks/server/utils';
import { ComGithubGrafanaGrafanaPkgApisAlertingNotificationsV0Alpha1TimeInterval } from 'app/features/alerting/unified/openapi/timeIntervalsApi.gen';
-import { K8sAnnotations, PROVENANCE_NONE } from 'app/features/alerting/unified/utils/k8s/constants';
+import { KnownProvenance } from 'app/features/alerting/unified/types/knownProvenance';
+import { K8sAnnotations } from 'app/features/alerting/unified/utils/k8s/constants';
/** UID of a time interval that we expect to follow all happy paths within tests/mocks */
export const TIME_INTERVAL_UID_HAPPY_PATH = 'f4eae7a4895fa786';
@@ -21,7 +22,7 @@ const allTimeIntervals = getK8sResponse {
it('should escape backslashes', () => {
@@ -25,3 +27,29 @@ describe('encodeFieldSelector', () => {
expect(encodeFieldSelector('foo=bar,bar=baz,qux\\foo')).toBe('foo\\=bar\\,bar\\=baz\\,qux\\\\foo');
});
});
+
+describe('isProvisionedResource', () => {
+ it('should return true when provenance is API', () => {
+ expect(isProvisionedResource(KnownProvenance.API)).toBe(true);
+ });
+
+ it('should return true when provenance is File', () => {
+ expect(isProvisionedResource(KnownProvenance.File)).toBe(true);
+ });
+
+ it('should return true when provenance is ConvertedPrometheus', () => {
+ expect(isProvisionedResource(KnownProvenance.ConvertedPrometheus)).toBe(true);
+ });
+
+ it('should return false when provenance is none', () => {
+ expect(isProvisionedResource(KnownProvenance.None)).toBe(false);
+ });
+
+ it('should return false when provenance is undefined', () => {
+ expect(isProvisionedResource(undefined)).toBe(false);
+ });
+
+ it('should return true for any other non-empty string', () => {
+ expect(isProvisionedResource('custom-provenance')).toBe(true);
+ });
+});
diff --git a/public/app/features/alerting/unified/utils/k8s/utils.ts b/public/app/features/alerting/unified/utils/k8s/utils.ts
index 48ec5685a69..015ba8f17a2 100644
--- a/public/app/features/alerting/unified/utils/k8s/utils.ts
+++ b/public/app/features/alerting/unified/utils/k8s/utils.ts
@@ -1,6 +1,8 @@
import { IoK8SApimachineryPkgApisMetaV1ObjectMeta } from 'app/features/alerting/unified/openapi/receiversApi.gen';
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
-import { K8sAnnotations, PROVENANCE_NONE } from 'app/features/alerting/unified/utils/k8s/constants';
+import { K8sAnnotations } from 'app/features/alerting/unified/utils/k8s/constants';
+
+import { KnownProvenance } from '../../types/knownProvenance';
/**
* Should we call the kubernetes-style API for managing alertmanager entities?
@@ -22,7 +24,7 @@ type EntityToCheck = {
*/
export const isK8sEntityProvisioned = (k8sEntity: EntityToCheck) => {
const provenance = getAnnotation(k8sEntity, K8sAnnotations.Provenance);
- return Boolean(provenance && provenance !== PROVENANCE_NONE);
+ return isProvisionedResource(provenance);
};
export const ANNOTATION_PREFIX_ACCESS = 'grafana.com/access/';
@@ -59,3 +61,7 @@ export const stringifyFieldSelector = (fieldSelectors: FieldSelector[]): string
.map(([key, value, operator = '=']) => `${key}${operator}${encodeFieldSelector(value)}`)
.join(',');
};
+
+export function isProvisionedResource(provenance?: string): boolean {
+ return Boolean(provenance && provenance !== KnownProvenance.None);
+}
diff --git a/public/app/plugins/datasource/alertmanager/types.ts b/public/app/plugins/datasource/alertmanager/types.ts
index 3fb512c88c6..1f964e6b664 100644
--- a/public/app/plugins/datasource/alertmanager/types.ts
+++ b/public/app/plugins/datasource/alertmanager/types.ts
@@ -108,7 +108,7 @@ export interface GrafanaManagedContactPoint {
/** If parsed from k8s API, we'll have an ID property */
id?: string;
metadata?: IoK8SApimachineryPkgApisMetaV1ObjectMeta;
- provisioned?: boolean;
+ provenance?: string;
grafana_managed_receiver_configs?: GrafanaManagedReceiverConfig[];
}
@@ -148,7 +148,7 @@ export type Route = {
provenance?: string;
/** this is used to add additional metadata to the routes without interfering with original route definition (symbols aren't iterable) */
[ROUTES_META_SYMBOL]?: {
- provisioned?: boolean;
+ provenance?: string;
resourceVersion?: string;
name?: string;
};
diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json
index 0725626911c..5bf71d4e7f8 100644
--- a/public/locales/en-US/grafana.json
+++ b/public/locales/en-US/grafana.json
@@ -2184,6 +2184,7 @@
},
"provisioning-badge": {
"badge": {
+ "text-converted-prometheus": "Imported",
"text-provisioned": "Provisioned"
}
},
|