mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add support for Prometheus api prefix
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
8d2e8bbe62
commit
496c9c62b5
@ -46,6 +46,7 @@ export type ClusterPreferences = {
|
|||||||
namespace: string;
|
namespace: string;
|
||||||
service: string;
|
service: string;
|
||||||
port: number;
|
port: number;
|
||||||
|
prefix: string;
|
||||||
};
|
};
|
||||||
prometheusProvider?: {
|
prometheusProvider?: {
|
||||||
type: string;
|
type: string;
|
||||||
@ -154,6 +155,13 @@ export class Cluster implements ClusterInfo {
|
|||||||
this.save()
|
this.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getPrometheusApiPrefix() {
|
||||||
|
if (!this.preferences.prometheus?.prefix) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return this.preferences.prometheus.prefix
|
||||||
|
}
|
||||||
|
|
||||||
public save() {
|
public save() {
|
||||||
clusterStore.storeCluster(this)
|
clusterStore.storeCluster(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { LensApiRequest } from "../router"
|
|||||||
import { LensApi } from "../lens-api"
|
import { LensApi } from "../lens-api"
|
||||||
import * as requestPromise from "request-promise-native"
|
import * as requestPromise from "request-promise-native"
|
||||||
import { PrometheusProviderRegistry, PrometheusProvider, PrometheusNodeQuery, PrometheusClusterQuery, PrometheusPodQuery, PrometheusPvcQuery, PrometheusIngressQuery, PrometheusQueryOpts} from "../prometheus/provider-registry"
|
import { PrometheusProviderRegistry, PrometheusProvider, PrometheusNodeQuery, PrometheusClusterQuery, PrometheusPodQuery, PrometheusPvcQuery, PrometheusIngressQuery, PrometheusQueryOpts} from "../prometheus/provider-registry"
|
||||||
|
import logger from "../logger"
|
||||||
|
|
||||||
type MetricsQuery = string | string[] | {
|
type MetricsQuery = string | string[] | {
|
||||||
[metricName: string]: string;
|
[metricName: string]: string;
|
||||||
@ -13,7 +14,8 @@ class MetricsRoute extends LensApi {
|
|||||||
const { response, cluster} = request
|
const { response, cluster} = request
|
||||||
const query: MetricsQuery = request.payload;
|
const query: MetricsQuery = request.payload;
|
||||||
const serverUrl = `http://127.0.0.1:${cluster.port}/api-kube`
|
const serverUrl = `http://127.0.0.1:${cluster.port}/api-kube`
|
||||||
const metricsUrl = `${serverUrl}/api/v1/namespaces/${cluster.contextHandler.getPrometheusPath()}/proxy/api/v1/query_range`
|
const metricsUrl = `${serverUrl}/api/v1/namespaces/${cluster.contextHandler.getPrometheusPath()}/proxy${cluster.getPrometheusApiPrefix()}/api/v1/query_range`
|
||||||
|
logger.info(metricsUrl)
|
||||||
const headers = {
|
const headers = {
|
||||||
"Host": `${cluster.id}.localhost:${cluster.port}`,
|
"Host": `${cluster.id}.localhost:${cluster.port}`,
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
|
|||||||
@ -97,7 +97,7 @@ export default {
|
|||||||
updateValues: function(){
|
updateValues: function(){
|
||||||
if (this.cluster.preferences.prometheus) {
|
if (this.cluster.preferences.prometheus) {
|
||||||
const prom = this.cluster.preferences.prometheus;
|
const prom = this.cluster.preferences.prometheus;
|
||||||
this.prometheusPath = `${prom.namespace}/${prom.service}:${prom.port}`
|
this.prometheusPath = `${prom.namespace}/${prom.service}:${prom.port}${prom.prefix}`
|
||||||
} else {
|
} else {
|
||||||
this.prometheusPath = ""
|
this.prometheusPath = ""
|
||||||
}
|
}
|
||||||
@ -112,7 +112,8 @@ export default {
|
|||||||
return {
|
return {
|
||||||
namespace: parsed[0],
|
namespace: parsed[0],
|
||||||
service: parsed[1],
|
service: parsed[1],
|
||||||
port: parsed[2]
|
port: parsed[2],
|
||||||
|
prefix: parsed[3] ? `/${parsed[3]}` : ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
expandPath: function(value, event) {
|
expandPath: function(value, event) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user