mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow to select Prometheus query style (#312)
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
1 parent
29cd171d0f
commit
724cf0c687
15 files changed
+333
-90
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { LensApiRequest } from "../router"
|
||||
import { LensApi } from "../lens-api"
|
||||
import * as requestPromise from "request-promise-native"
|
||||
import { PrometheusProviderRegistry, PrometheusProvider, PrometheusNodeQuery, PrometheusClusterQuery, PrometheusPodQuery, PrometheusPvcQuery, PrometheusIngressQuery, PrometheusQueryOpts} from "../prometheus/provider-registry"
|
||||
|
||||
type MetricsQuery = string | string[] | {
|
||||
[metricName: string]: string;
|
||||
@@ -22,6 +23,14 @@ class MetricsRoute extends LensApi {
|
||||
queryParams[key] = value
|
||||
})
|
||||
|
||||
const prometheusInstallationSource = cluster.preferences.prometheusProvider?.type || "lens"
|
||||
let prometheusProvider: PrometheusProvider
|
||||
try {
|
||||
prometheusProvider = PrometheusProviderRegistry.getProvider(prometheusInstallationSource)
|
||||
} catch {
|
||||
this.respondJson(response, {})
|
||||
return
|
||||
}
|
||||
// prometheus metrics loader
|
||||
const attempts: { [query: string]: number } = {};
|
||||
const maxAttempts = 5;
|
||||
@@ -61,7 +70,13 @@ class MetricsRoute extends LensApi {
|
||||
else {
|
||||
data = {};
|
||||
const result = await Promise.all(
|
||||
Object.values(query).map(loadMetrics)
|
||||
Object.entries(query).map((queryEntry: any) => {
|
||||
const queryName: string = queryEntry[0]
|
||||
const queryOpts: PrometheusQueryOpts = queryEntry[1]
|
||||
const queries = prometheusProvider.getQueries(queryOpts)
|
||||
const q = queries[queryName as keyof (PrometheusNodeQuery | PrometheusClusterQuery | PrometheusPodQuery | PrometheusPvcQuery | PrometheusIngressQuery)]
|
||||
return loadMetrics(q)
|
||||
})
|
||||
);
|
||||
Object.keys(query).forEach((metricName, index) => {
|
||||
data[metricName] = result[index];
|
||||
|
||||
Reference in new issue
Block a user