mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactoring
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
40dcbdbf67
commit
c6cd1a066a
@ -47,7 +47,9 @@ export type ClusterPreferences = {
|
||||
service: string;
|
||||
port: number;
|
||||
};
|
||||
prometheusSource?: string;
|
||||
prometheusProvider?: {
|
||||
type: string;
|
||||
};
|
||||
icon?: string;
|
||||
httpsProxy?: string;
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ import { shellSync } from "./shell-sync"
|
||||
import { getFreePort } from "./port"
|
||||
import { mangleProxyEnv } from "./proxy-env"
|
||||
import { findMainWebContents } from "./webcontents"
|
||||
import { helmCli } from "./helm-cli"
|
||||
import "./prometheus/index"
|
||||
|
||||
mangleProxyEnv()
|
||||
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
||||
|
||||
9
src/main/prometheus/index.ts
Normal file
9
src/main/prometheus/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { PrometheusLens } from "./lens";
|
||||
import { PrometheusHelm } from "./helm";
|
||||
import { PrometheusOperator } from "./operator";
|
||||
import { PrometheusProviderRegistry } from "./provider";
|
||||
|
||||
|
||||
PrometheusProviderRegistry.registerProvider("lens", new PrometheusLens())
|
||||
PrometheusProviderRegistry.registerProvider("helm", new PrometheusHelm())
|
||||
PrometheusProviderRegistry.registerProvider("operator", new PrometheusOperator())
|
||||
@ -1,4 +1,5 @@
|
||||
import { PrometheusProvider, PrometheusQuery, PrometheusQueryOpts } from "./provider";
|
||||
|
||||
export class PrometheusLens implements PrometheusProvider {
|
||||
rateAccuracy = "1m"
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { PrometheusProvider, PrometheusQuery, PrometheusQueryOpts } from "./provider";
|
||||
|
||||
export class PrometheusOperator implements PrometheusProvider {
|
||||
rateAccuracy = "1m"
|
||||
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import { PrometheusHelm } from "./helm"
|
||||
import { PrometheusLens } from "./lens"
|
||||
import { PrometheusOperator } from "./operator";
|
||||
import logger from "../logger";
|
||||
|
||||
export type PrometheusQuery = {
|
||||
[key: string]: string;
|
||||
@ -14,16 +12,19 @@ export interface PrometheusProvider {
|
||||
getQueries(opts: PrometheusQueryOpts): PrometheusQuery;
|
||||
}
|
||||
|
||||
export class PrometheusProviderFactory {
|
||||
static createProvider(type: string): PrometheusProvider {
|
||||
if (type == "lens") {
|
||||
return new PrometheusLens()
|
||||
} else if (type == "helm") {
|
||||
return new PrometheusHelm()
|
||||
} else if (type == "operator") {
|
||||
return new PrometheusOperator()
|
||||
} else {
|
||||
export class PrometheusProviderRegistry {
|
||||
private static prometheusProviders: {
|
||||
[key: string]: PrometheusProvider;
|
||||
} = {}
|
||||
|
||||
static getProvider(type: string): PrometheusProvider {
|
||||
if (!this.prometheusProviders[type]) {
|
||||
throw "Unknown Prometheus provider";
|
||||
}
|
||||
return this.prometheusProviders[type]
|
||||
}
|
||||
|
||||
static registerProvider(key: string, provider: PrometheusProvider) {
|
||||
this.prometheusProviders[key] = provider
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import { LensApiRequest } from "../router"
|
||||
import { LensApi } from "../lens-api"
|
||||
import * as requestPromise from "request-promise-native"
|
||||
import { PrometheusProviderFactory, PrometheusProvider} from "../prometheus/provider"
|
||||
import { PrometheusProviderRegistry, PrometheusProvider} from "../prometheus/provider"
|
||||
|
||||
type MetricsQuery = string | string[] | {
|
||||
[metricName: string]: string;
|
||||
@ -23,12 +23,13 @@ class MetricsRoute extends LensApi {
|
||||
queryParams[key] = value
|
||||
})
|
||||
|
||||
const prometheusInstallationSource = cluster.preferences.prometheusSource || "lens"
|
||||
const prometheusInstallationSource = cluster.preferences.prometheusProvider?.type || "lens"
|
||||
let prometheusProvider: PrometheusProvider
|
||||
try {
|
||||
prometheusProvider = PrometheusProviderFactory.createProvider(prometheusInstallationSource)
|
||||
prometheusProvider = PrometheusProviderRegistry.getProvider(prometheusInstallationSource)
|
||||
} catch {
|
||||
this.respondJson(response, {})
|
||||
return
|
||||
}
|
||||
// prometheus metrics loader
|
||||
const attempts: { [query: string]: number } = {};
|
||||
|
||||
@ -36,9 +36,9 @@
|
||||
description="What query format is used to fetch metrics from Prometheus"
|
||||
>
|
||||
<b-form-select
|
||||
v-model="prometheusSource"
|
||||
:options="prometheusSources"
|
||||
@change="onPrometheusSourceSave"
|
||||
v-model="prometheusProvider"
|
||||
:options="prometheusProviders"
|
||||
@change="onPrometheusProviderSave"
|
||||
/>
|
||||
</b-form-group>
|
||||
</div>
|
||||
@ -81,8 +81,8 @@ export default {
|
||||
terminalcwd: null
|
||||
},
|
||||
prometheusPath: "",
|
||||
prometheusSource: "",
|
||||
prometheusSources: [
|
||||
prometheusProvider: "",
|
||||
prometheusProviders: [
|
||||
{ text: "Lens", value: "lens"},
|
||||
{ text: "Helm", value: "helm"},
|
||||
{ text: "Prometheus Operator", value: "operator"}
|
||||
@ -102,7 +102,11 @@ export default {
|
||||
} else {
|
||||
this.prometheusPath = ""
|
||||
}
|
||||
this.prometheusSource = this.cluster.preferences.prometheusSource || "lens"
|
||||
if (this.cluster.preferences.prometheusProvider) {
|
||||
this.prometheusProvider = this.cluster.preferences.prometheusProvider.type
|
||||
} else {
|
||||
this.prometheusProvider = "lens"
|
||||
}
|
||||
},
|
||||
parsePrometheusPath: function(path) {
|
||||
let parsed = path.split(/\/|:/)
|
||||
@ -143,11 +147,11 @@ export default {
|
||||
}
|
||||
this.$store.dispatch("storeCluster", this.cluster);
|
||||
},
|
||||
onPrometheusSourceSave: function() {
|
||||
if (this.prometheusSource === "") {
|
||||
this.cluster.preferences.prometheusSource = null;
|
||||
onPrometheusProviderSave: function() {
|
||||
if (this.prometheusProvider === "") {
|
||||
this.cluster.preferences.prometheusProvider = null;
|
||||
} else {
|
||||
this.cluster.preferences.prometheusSource = this.prometheusSource
|
||||
this.cluster.preferences.prometheusProvider = { type: this.prometheusProvider }
|
||||
}
|
||||
this.$store.dispatch("storeCluster", this.cluster);
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user