mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Improve the injectability of cluster metadata detection - Remove unnecessary and complex base class Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of request in our code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove more deps Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lensFetch Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import type { Cluster } from "../common/cluster/cluster";
|
|
import nodeFetchModuleInjectable from "../common/fetch/fetch-module.injectable";
|
|
import type { RequestMetricsParams } from "../common/k8s-api/endpoints/metrics.api/request-metrics.injectable";
|
|
import { object } from "../common/utils";
|
|
import k8sRequestInjectable from "./k8s-request.injectable";
|
|
|
|
export type GetMetrics = (cluster: Cluster, prometheusPath: string, queryParams: RequestMetricsParams & { query: string }) => Promise<unknown>;
|
|
|
|
const getMetricsInjectable = getInjectable({
|
|
id: "get-metrics",
|
|
|
|
instantiate: (di): GetMetrics => {
|
|
const k8sRequest = di.inject(k8sRequestInjectable);
|
|
const { FormData } = di.inject(nodeFetchModuleInjectable);
|
|
|
|
return async (
|
|
cluster,
|
|
prometheusPath,
|
|
queryParams,
|
|
) => {
|
|
const prometheusPrefix = cluster.preferences.prometheus?.prefix || "";
|
|
const metricsPath = `/api/v1/namespaces/${prometheusPath}/proxy${prometheusPrefix}/api/v1/query_range`;
|
|
const body = new FormData();
|
|
|
|
for (const [key, value] of object.entries(queryParams)) {
|
|
body.set(key, value.toString());
|
|
}
|
|
|
|
return k8sRequest(cluster, metricsPath, {
|
|
timeout: 0,
|
|
method: "POST",
|
|
body,
|
|
});
|
|
};
|
|
},
|
|
});
|
|
|
|
export default getMetricsInjectable;
|