mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fixup typing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f2bd86a0de
commit
304d955e46
@ -37,20 +37,19 @@ export interface RequestMetricsParams {
|
|||||||
namespace?: string;
|
namespace?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RequestMetrics {
|
export type RequestMetrics = ReturnType<typeof requestMetricsInjectable["instantiate"]>;
|
||||||
(query: string, params?: RequestMetricsParams): Promise<MetricData>;
|
|
||||||
(query: string[], params?: RequestMetricsParams): Promise<MetricData[]>;
|
|
||||||
<Keys extends string>(query: Record<Keys, Partial<Record<string, string>>>, params?: RequestMetricsParams): Promise<Record<Keys, MetricData>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestMetricsInjectable = getInjectable({
|
const requestMetricsInjectable = getInjectable({
|
||||||
id: "request-metrics",
|
id: "request-metrics",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const apiBase = di.inject(apiBaseInjectable);
|
const apiBase = di.inject(apiBaseInjectable);
|
||||||
|
|
||||||
return (async (query: object, params: RequestMetricsParams = {}) => {
|
function requestMetrics(query: string, params?: RequestMetricsParams): Promise<MetricData>;
|
||||||
const { range = 3600, step = 60, namespace } = params;
|
function requestMetrics(query: string[], params?: RequestMetricsParams): Promise<MetricData[]>;
|
||||||
let { start, end } = params;
|
function requestMetrics<Keys extends string>(query: Record<Keys, Partial<Record<string, string>>>, params?: RequestMetricsParams): Promise<Record<Keys, MetricData>>;
|
||||||
|
async function requestMetrics(query: string | string[] | Partial<Record<string, Partial<Record<string, string>>>>, params?: RequestMetricsParams): Promise<MetricData | MetricData[] | Partial<Record<string, MetricData>>> {
|
||||||
|
const { range = 3600, step = 60, namespace } = params ?? {};
|
||||||
|
let { start, end } = params ?? {};
|
||||||
|
|
||||||
if (!start && !end) {
|
if (!start && !end) {
|
||||||
const now = getSecondsFromUnixEpoch();
|
const now = getSecondsFromUnixEpoch();
|
||||||
@ -59,14 +58,18 @@ const requestMetricsInjectable = getInjectable({
|
|||||||
end = now;
|
end = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiBase.post("/metrics", {
|
const res = await apiBase.post("/metrics", {
|
||||||
data: query,
|
data: query,
|
||||||
query: {
|
query: {
|
||||||
start, end, step,
|
start, end, step,
|
||||||
"kubernetes_namespace": namespace,
|
"kubernetes_namespace": namespace,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}) as RequestMetrics;
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestMetrics;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user