diff --git a/src/main/prometheus/helm-14.ts b/src/main/prometheus/helm-14.ts new file mode 100644 index 0000000000..7ffac4560b --- /dev/null +++ b/src/main/prometheus/helm-14.ts @@ -0,0 +1,36 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { PrometheusLens } from "./lens"; +import type { CoreV1Api } from "@kubernetes/client-node"; +import type { PrometheusService } from "./provider-registry"; +import { isRequestError } from "../../common/utils"; + +export class PrometheusHelm14 extends PrometheusLens { + readonly id: string = "helm14"; + readonly name: string = "Helm 14.x"; + readonly rateAccuracy: string = "5m"; + readonly isConfigurable: boolean = true; + + public async getPrometheusService(client: CoreV1Api): Promise { + try { + const selector = "app=prometheus,component=server,heritage=Helm"; + const { body: { items: [service] }} = await client.listServiceForAllNamespaces(undefined, undefined, undefined, selector); + + if (service?.metadata?.namespace && service.metadata.name && service.spec?.ports && service.metadata?.labels?.chart?.startsWith("prometheus-14")) { + return { + id: this.id, + namespace: service.metadata.namespace, + service: service.metadata.name, + port: service.spec.ports[0].port, + }; + } + } catch (error) { + throw new Error(`Failed to list services for Prometheus ${this.name} in all namespaces: ${isRequestError(error) ? error.response?.body.message : error}`); + } + + throw new Error(`No service found for Prometheus ${this.name} from any namespace`); + } +} diff --git a/src/main/start-main-application/runnables/setup-prometheus-registry.injectable.ts b/src/main/start-main-application/runnables/setup-prometheus-registry.injectable.ts index c3756bb1b1..28b410889d 100644 --- a/src/main/start-main-application/runnables/setup-prometheus-registry.injectable.ts +++ b/src/main/start-main-application/runnables/setup-prometheus-registry.injectable.ts @@ -5,6 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { PrometheusLens } from "../../prometheus/lens"; import { PrometheusHelm } from "../../prometheus/helm"; +import { PrometheusHelm14 } from "../../prometheus/helm-14"; import { PrometheusOperator } from "../../prometheus/operator"; import { PrometheusStacklight } from "../../prometheus/stacklight"; import prometheusProviderRegistryInjectable from "../../prometheus/prometheus-provider-registry.injectable"; @@ -20,6 +21,7 @@ const setupPrometheusRegistryInjectable = getInjectable({ run: () => { prometheusProviderRegistry .registerProvider(new PrometheusLens()) + .registerProvider(new PrometheusHelm14()) .registerProvider(new PrometheusHelm()) .registerProvider(new PrometheusOperator()) .registerProvider(new PrometheusStacklight());