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:
parent
ca0b23eee8
commit
ebbd6ab40b
@ -5,8 +5,8 @@
|
||||
|
||||
import { getRequestChannel } from "@k8slens/messaging";
|
||||
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 { Cluster } from "../../../cluster/cluster";
|
||||
|
||||
type PrometheusProviderData = Pick<PrometheusProvider, "kind" | "name" | "isConfigurable">;
|
||||
|
||||
@ -14,4 +14,4 @@ export type PrometheusDetailsData = Pick<PrometheusDetails, "prometheusPath"> &
|
||||
provider: PrometheusProviderData;
|
||||
};
|
||||
|
||||
export const prometheusDetailsChannel = getRequestChannel<ClusterId, PrometheusDetailsData>("prometheus-details");
|
||||
export const prometheusDetailsChannel = getRequestChannel<Cluster, PrometheusDetailsData>("prometheus-details");
|
||||
|
||||
@ -5,25 +5,16 @@
|
||||
import { getRequestChannelListenerInjectable } from "@k8slens/messaging";
|
||||
import { prometheusDetailsChannel } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel";
|
||||
import prometheusHandlerInjectable from "./prometheus-handler.injectable";
|
||||
import clustersInjectable from "../../../features/cluster/storage/common/clusters.injectable";
|
||||
|
||||
const prometheusDetailsChannelListener =
|
||||
getRequestChannelListenerInjectable({
|
||||
id: "add-helm-repository-channel-listener",
|
||||
channel: prometheusDetailsChannel,
|
||||
getHandler: (di) => {
|
||||
return async (clusterId) => {
|
||||
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`);
|
||||
}
|
||||
return async (cluster) => {
|
||||
const prometheusHandler = di.inject(prometheusHandlerInjectable, cluster);
|
||||
const details = await prometheusHandler.getPrometheusDetails();
|
||||
|
||||
console.log(details);
|
||||
|
||||
return {
|
||||
prometheusPath: details.prometheusPath,
|
||||
provider: {
|
||||
|
||||
@ -3,21 +3,19 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { logInfoInjectionToken } from "@k8slens/logger";
|
||||
import { requestFromChannelInjectionToken } from "@k8slens/messaging";
|
||||
import { prometheusDetailsChannel } from "../../../common/k8s-api/endpoints/metrics.api/prometheus-details.channel";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
|
||||
|
||||
const getPrometheusDetailsRouteInjectable = getInjectable({
|
||||
id: "get-prometheus-details-route",
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(logInfoInjectionToken);
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
||||
|
||||
return (async (clusterId: string) => {
|
||||
logger("requestFromChannel");
|
||||
const prometheusDetails = await requestFromChannel(prometheusDetailsChannel, clusterId);
|
||||
return (async (cluster: Cluster) => {
|
||||
const prometheusDetails = await requestFromChannel(prometheusDetailsChannel, cluster);
|
||||
|
||||
return prometheusDetails;
|
||||
});
|
||||
|
||||
@ -4,8 +4,7 @@
|
||||
*/
|
||||
import React from "react";
|
||||
import { SubTitle } from "../layout/sub-title";
|
||||
import { Icon } from "../icon";
|
||||
|
||||
import { Icon } from "@k8slens/icon";
|
||||
|
||||
export const NoPrometheusProviderDetected = () => (
|
||||
<section>
|
||||
|
||||
@ -18,8 +18,6 @@ import requestMetricsProvidersInjectable from "../../../common/k8s-api/endpoints
|
||||
import productNameInjectable from "../../../common/vars/product-name.injectable";
|
||||
import getPrometheusDetailsRouteInjectable from "./get-prometheus-details.injectable";
|
||||
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 { NoPrometheusProviderDetected } from "./no-prometheus-provider-detectec";
|
||||
|
||||
@ -34,8 +32,7 @@ type ProviderValue = typeof autoDetectPrometheus | string;
|
||||
interface Dependencies {
|
||||
productName: string;
|
||||
requestMetricsProviders: RequestMetricsProviders;
|
||||
requestPrometheusDetails: (clusterId: string) => Promise<PrometheusDetailsData>;
|
||||
logger: Logger;
|
||||
requestPrometheusDetails: (cluster: Cluster) => Promise<PrometheusDetailsData>;
|
||||
}
|
||||
|
||||
interface PrometheusDetailsDataResult {
|
||||
@ -136,15 +133,13 @@ class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometh
|
||||
|
||||
loadPrometheusDetails = async () => {
|
||||
try {
|
||||
const details = await this.props.requestPrometheusDetails(this.props.cluster.id);
|
||||
const details = await this.props.requestPrometheusDetails(this.props.cluster);
|
||||
|
||||
this.prometheusDetails = {
|
||||
type: "success",
|
||||
details,
|
||||
};
|
||||
this.props.logger.info(`[CLUSTER-SETTINGS]: Prometheus details loaded: ${JSON.stringify(this.prometheusDetails)}`);
|
||||
} catch (error) {
|
||||
this.props.logger.error(`[CLUSTER-SETTINGS]: Failed to load prometheus details: ${error}`);
|
||||
this.prometheusDetails = {
|
||||
type: "error",
|
||||
details: undefined,
|
||||
@ -233,6 +228,5 @@ export const ClusterPrometheusSetting = withInjectables<Dependencies, ClusterPro
|
||||
productName: di.inject(productNameInjectable),
|
||||
requestMetricsProviders: di.inject(requestMetricsProvidersInjectable),
|
||||
requestPrometheusDetails: di.inject(getPrometheusDetailsRouteInjectable),
|
||||
logger: di.inject(loggerInjectionToken),
|
||||
}),
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user