1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use Cluster instead of clusterId

Signed-off-by: Juho Heikka <juho.heikka@gmail.com>
This commit is contained in:
Juho Heikka 2023-06-01 16:25:08 +03:00
parent ca0b23eee8
commit ebbd6ab40b
5 changed files with 9 additions and 27 deletions

View File

@ -5,8 +5,8 @@
import { getRequestChannel } from "@k8slens/messaging"; import { getRequestChannel } from "@k8slens/messaging";
import type { PrometheusDetails } from "../../../../main/cluster/prometheus-handler/prometheus-handler"; import type { PrometheusDetails } from "../../../../main/cluster/prometheus-handler/prometheus-handler";
import type { ClusterId } from "../../../cluster-types";
import type { PrometheusProvider } from "../../../../main/prometheus/provider"; import type { PrometheusProvider } from "../../../../main/prometheus/provider";
import type { Cluster } from "../../../cluster/cluster";
type PrometheusProviderData = Pick<PrometheusProvider, "kind" | "name" | "isConfigurable">; type PrometheusProviderData = Pick<PrometheusProvider, "kind" | "name" | "isConfigurable">;
@ -14,4 +14,4 @@ export type PrometheusDetailsData = Pick<PrometheusDetails, "prometheusPath"> &
provider: PrometheusProviderData; provider: PrometheusProviderData;
}; };
export const prometheusDetailsChannel = getRequestChannel<ClusterId, PrometheusDetailsData>("prometheus-details"); export const prometheusDetailsChannel = getRequestChannel<Cluster, PrometheusDetailsData>("prometheus-details");

View File

@ -5,25 +5,16 @@
import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging";
import { prometheusDetailsChannel } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel"; import { prometheusDetailsChannel } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel";
import prometheusHandlerInjectable from "./prometheus-handler.injectable"; import prometheusHandlerInjectable from "./prometheus-handler.injectable";
import clustersInjectable from "../../../features/cluster/storage/common/clusters.injectable";
const prometheusDetailsChannelListener = const prometheusDetailsChannelListener =
getRequestChannelListenerInjectable({ getRequestChannelListenerInjectable({
id: "add-helm-repository-channel-listener", id: "add-helm-repository-channel-listener",
channel: prometheusDetailsChannel, channel: prometheusDetailsChannel,
getHandler: (di) => { getHandler: (di) => {
return async (clusterId) => { return async (cluster) => {
const clusters = di.inject(clustersInjectable);
const cluster = clusters.get().find((c) => c.id === clusterId);
if (!cluster) {
throw new Error(`Cluster with id "${clusterId}" not found`);
}
const prometheusHandler = di.inject(prometheusHandlerInjectable, cluster); const prometheusHandler = di.inject(prometheusHandlerInjectable, cluster);
const details = await prometheusHandler.getPrometheusDetails(); const details = await prometheusHandler.getPrometheusDetails();
console.log(details);
return { return {
prometheusPath: details.prometheusPath, prometheusPath: details.prometheusPath,
provider: { provider: {

View File

@ -3,21 +3,19 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { logInfoInjectionToken } from "@k8slens/logger";
import { requestFromChannelInjectionToken } from "@k8slens/messaging"; import { requestFromChannelInjectionToken } from "@k8slens/messaging";
import { prometheusDetailsChannel } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel"; import { prometheusDetailsChannel } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel";
import type { Cluster } from "../../../common/cluster/cluster";
const getPrometheusDetailsRouteInjectable = getInjectable({ const getPrometheusDetailsRouteInjectable = getInjectable({
id: "get-prometheus-details-route", id: "get-prometheus-details-route",
instantiate: (di) => { instantiate: (di) => {
const logger = di.inject(logInfoInjectionToken);
const requestFromChannel = di.inject(requestFromChannelInjectionToken); const requestFromChannel = di.inject(requestFromChannelInjectionToken);
return (async (clusterId: string) => { return (async (cluster: Cluster) => {
logger("requestFromChannel"); const prometheusDetails = await requestFromChannel(prometheusDetailsChannel, cluster);
const prometheusDetails = await requestFromChannel(prometheusDetailsChannel, clusterId);
return prometheusDetails; return prometheusDetails;
}); });

View File

@ -4,8 +4,7 @@
*/ */
import React from "react"; import React from "react";
import { SubTitle } from "../layout/sub-title"; import { SubTitle } from "../layout/sub-title";
import { Icon } from "../icon"; import { Icon } from "@k8slens/icon";
export const NoPrometheusProviderDetected = () => ( export const NoPrometheusProviderDetected = () => (
<section> <section>

View File

@ -18,8 +18,6 @@ import requestMetricsProvidersInjectable from "../../../common/k8s-api/endpoints
import productNameInjectable from "../../../common/vars/product-name.injectable"; import productNameInjectable from "../../../common/vars/product-name.injectable";
import getPrometheusDetailsRouteInjectable from "./get-prometheus-details.injectable"; import getPrometheusDetailsRouteInjectable from "./get-prometheus-details.injectable";
import type { PrometheusDetailsData } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel"; import type { PrometheusDetailsData } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel";
import { loggerInjectionToken } from "@k8slens/logger";
import type { Logger } from "@k8slens/logger";
import { PrometheusDetails } from "./prometheus-details"; import { PrometheusDetails } from "./prometheus-details";
import { NoPrometheusProviderDetected } from "./no-prometheus-provider-detectec"; import { NoPrometheusProviderDetected } from "./no-prometheus-provider-detectec";
@ -34,8 +32,7 @@ type ProviderValue = typeof autoDetectPrometheus | string;
interface Dependencies { interface Dependencies {
productName: string; productName: string;
requestMetricsProviders: RequestMetricsProviders; requestMetricsProviders: RequestMetricsProviders;
requestPrometheusDetails: (clusterId: string) => Promise<PrometheusDetailsData>; requestPrometheusDetails: (cluster: Cluster) => Promise<PrometheusDetailsData>;
logger: Logger;
} }
interface PrometheusDetailsDataResult { interface PrometheusDetailsDataResult {
@ -136,15 +133,13 @@ class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometh
loadPrometheusDetails = async () => { loadPrometheusDetails = async () => {
try { try {
const details = await this.props.requestPrometheusDetails(this.props.cluster.id); const details = await this.props.requestPrometheusDetails(this.props.cluster);
this.prometheusDetails = { this.prometheusDetails = {
type: "success", type: "success",
details, details,
}; };
this.props.logger.info(`[CLUSTER-SETTINGS]: Prometheus details loaded: ${JSON.stringify(this.prometheusDetails)}`);
} catch (error) { } catch (error) {
this.props.logger.error(`[CLUSTER-SETTINGS]: Failed to load prometheus details: ${error}`);
this.prometheusDetails = { this.prometheusDetails = {
type: "error", type: "error",
details: undefined, details: undefined,
@ -233,6 +228,5 @@ export const ClusterPrometheusSetting = withInjectables<Dependencies, ClusterPro
productName: di.inject(productNameInjectable), productName: di.inject(productNameInjectable),
requestMetricsProviders: di.inject(requestMetricsProvidersInjectable), requestMetricsProviders: di.inject(requestMetricsProvidersInjectable),
requestPrometheusDetails: di.inject(getPrometheusDetailsRouteInjectable), requestPrometheusDetails: di.inject(getPrometheusDetailsRouteInjectable),
logger: di.inject(loggerInjectionToken),
}), }),
}); });