1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add support for Prometheus api prefix (#341)

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-05-06 20:37:32 +03:00 committed by GitHub
parent 5c1974f07b
commit bba6eb743d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -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;
@ -153,6 +154,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)
} }

View File

@ -26,7 +26,7 @@ class MetricsRoute extends LensApi {
let prometheusProvider: PrometheusProvider let prometheusProvider: PrometheusProvider
try { try {
const prometheusPath = await cluster.contextHandler.getPrometheusPath() const prometheusPath = await cluster.contextHandler.getPrometheusPath()
metricsUrl = `${serverUrl}/api/v1/namespaces/${prometheusPath}/proxy/api/v1/query_range` metricsUrl = `${serverUrl}/api/v1/namespaces/${prometheusPath}/proxy${cluster.getPrometheusApiPrefix()}/api/v1/query_range`
prometheusProvider = await cluster.contextHandler.getPrometheusProvider() prometheusProvider = await cluster.contextHandler.getPrometheusProvider()
} catch { } catch {
this.respondJson(response, {}) this.respondJson(response, {})

View File

@ -111,7 +111,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 = ""
} }
@ -122,11 +122,13 @@ export default {
} }
}, },
parsePrometheusPath: function(path) { parsePrometheusPath: function(path) {
let parsed = path.split(/\/|:/) const parsed = path.split(/\/|:/, 3)
const apiPrefix = path.substring(parsed.join("/").length)
return { return {
namespace: parsed[0], namespace: parsed[0],
service: parsed[1], service: parsed[1],
port: parsed[2] port: parsed[2],
prefix: apiPrefix
} }
}, },
expandPath: function(value, event) { expandPath: function(value, event) {