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;
|
||||
}
|
||||
|
||||
export interface RequestMetrics {
|
||||
(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>>;
|
||||
}
|
||||
export type RequestMetrics = ReturnType<typeof requestMetricsInjectable["instantiate"]>;
|
||||
|
||||
const requestMetricsInjectable = getInjectable({
|
||||
id: "request-metrics",
|
||||
instantiate: (di) => {
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return (async (query: object, params: RequestMetricsParams = {}) => {
|
||||
const { range = 3600, step = 60, namespace } = params;
|
||||
let { start, end } = params;
|
||||
function requestMetrics(query: string, params?: RequestMetricsParams): Promise<MetricData>;
|
||||
function requestMetrics(query: string[], params?: RequestMetricsParams): Promise<MetricData[]>;
|
||||
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) {
|
||||
const now = getSecondsFromUnixEpoch();
|
||||
@ -59,14 +58,18 @@ const requestMetricsInjectable = getInjectable({
|
||||
end = now;
|
||||
}
|
||||
|
||||
return apiBase.post("/metrics", {
|
||||
const res = await apiBase.post("/metrics", {
|
||||
data: query,
|
||||
query: {
|
||||
start, end, step,
|
||||
"kubernetes_namespace": namespace,
|
||||
},
|
||||
});
|
||||
}) as RequestMetrics;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return requestMetrics;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user