mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Use provider registry also on cluster settings preferences
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
06bbf8d8d6
commit
4daff194ab
13
src/common/prometheus-providers.ts
Normal file
13
src/common/prometheus-providers.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { PrometheusLens } from "../main/prometheus/lens";
|
||||||
|
import { PrometheusHelm } from "../main/prometheus/helm";
|
||||||
|
import { PrometheusOperator } from "../main/prometheus/operator";
|
||||||
|
import { PrometheusProviderRegistry } from "../main/prometheus/provider-registry";
|
||||||
|
import logger from "../main/logger";
|
||||||
|
|
||||||
|
[PrometheusLens, PrometheusHelm, PrometheusOperator].forEach(providerClass => {
|
||||||
|
const provider = new providerClass()
|
||||||
|
logger.info(provider.id)
|
||||||
|
PrometheusProviderRegistry.registerProvider(provider.id, provider)
|
||||||
|
});
|
||||||
|
|
||||||
|
export const prometheusProviders = PrometheusProviderRegistry.getProviders()
|
||||||
@ -15,7 +15,7 @@ import { shellSync } from "./shell-sync"
|
|||||||
import { getFreePort } from "./port"
|
import { getFreePort } from "./port"
|
||||||
import { mangleProxyEnv } from "./proxy-env"
|
import { mangleProxyEnv } from "./proxy-env"
|
||||||
import { findMainWebContents } from "./webcontents"
|
import { findMainWebContents } from "./webcontents"
|
||||||
import "./prometheus/index"
|
import "../common/prometheus-providers"
|
||||||
|
|
||||||
mangleProxyEnv()
|
mangleProxyEnv()
|
||||||
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import { PrometheusLens } from "./lens"
|
|||||||
export class PrometheusHelm extends PrometheusLens {
|
export class PrometheusHelm extends PrometheusLens {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
|
this.id = "helm"
|
||||||
|
this.name = "Helm"
|
||||||
this.rateAccuracy = "5m"
|
this.rateAccuracy = "5m"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,9 +0,0 @@
|
|||||||
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,6 +1,8 @@
|
|||||||
import { PrometheusProvider, PrometheusQuery, PrometheusQueryOpts } from "./provider";
|
import { PrometheusProvider, PrometheusQuery, PrometheusQueryOpts } from "./provider-registry";
|
||||||
|
|
||||||
export class PrometheusLens implements PrometheusProvider {
|
export class PrometheusLens implements PrometheusProvider {
|
||||||
|
id = "lens"
|
||||||
|
name = "Lens"
|
||||||
rateAccuracy = "1m"
|
rateAccuracy = "1m"
|
||||||
|
|
||||||
public getQueries(opts: PrometheusQueryOpts): PrometheusQuery {
|
public getQueries(opts: PrometheusQueryOpts): PrometheusQuery {
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import { PrometheusProvider, PrometheusQuery, PrometheusQueryOpts } from "./provider";
|
import { PrometheusProvider, PrometheusQuery, PrometheusQueryOpts } from "./provider-registry";
|
||||||
|
|
||||||
export class PrometheusOperator implements PrometheusProvider {
|
export class PrometheusOperator implements PrometheusProvider {
|
||||||
rateAccuracy = "1m"
|
rateAccuracy = "1m"
|
||||||
|
id = "operator"
|
||||||
|
name = "Prometheus Operator"
|
||||||
|
|
||||||
public getQueries(opts: PrometheusQueryOpts): PrometheusQuery {
|
public getQueries(opts: PrometheusQueryOpts): PrometheusQuery {
|
||||||
switch(opts.category) {
|
switch(opts.category) {
|
||||||
|
|||||||
@ -10,10 +10,12 @@ export interface PrometheusProvider {
|
|||||||
getQueries(opts: PrometheusQueryOpts): PrometheusQuery;
|
getQueries(opts: PrometheusQueryOpts): PrometheusQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PrometheusProviderList = {
|
||||||
|
[key: string]: PrometheusProvider;
|
||||||
|
}
|
||||||
|
|
||||||
export class PrometheusProviderRegistry {
|
export class PrometheusProviderRegistry {
|
||||||
private static prometheusProviders: {
|
private static prometheusProviders: PrometheusProviderList = {}
|
||||||
[key: string]: PrometheusProvider;
|
|
||||||
} = {}
|
|
||||||
|
|
||||||
static getProvider(type: string): PrometheusProvider {
|
static getProvider(type: string): PrometheusProvider {
|
||||||
if (!this.prometheusProviders[type]) {
|
if (!this.prometheusProviders[type]) {
|
||||||
@ -25,4 +27,8 @@ export class PrometheusProviderRegistry {
|
|||||||
static registerProvider(key: string, provider: PrometheusProvider) {
|
static registerProvider(key: string, provider: PrometheusProvider) {
|
||||||
this.prometheusProviders[key] = provider
|
this.prometheusProviders[key] = provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getProviders(): PrometheusProvider[] {
|
||||||
|
return Object.values(this.prometheusProviders)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -67,6 +67,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { lstatSync } from "fs"
|
import { lstatSync } from "fs"
|
||||||
|
import { prometheusProviders } from '../../../../common/prometheus-providers';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ClusterSettingsPreferences',
|
name: 'ClusterSettingsPreferences',
|
||||||
props: {
|
props: {
|
||||||
@ -82,18 +84,15 @@ export default {
|
|||||||
},
|
},
|
||||||
prometheusPath: "",
|
prometheusPath: "",
|
||||||
prometheusProvider: "",
|
prometheusProvider: "",
|
||||||
prometheusProviders: [
|
prometheusProviders: [],
|
||||||
{ text: "Lens", value: "lens"},
|
|
||||||
{ text: "Helm", value: "helm"},
|
|
||||||
{ text: "Prometheus Operator", value: "operator"}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted: function() {
|
mounted: async function() {
|
||||||
|
this.prometheusProviders = prometheusProviders.map((provider) => {
|
||||||
|
return { text: provider.name, value: provider.id }
|
||||||
|
})
|
||||||
this.updateValues()
|
this.updateValues()
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
updateValues: function(){
|
updateValues: function(){
|
||||||
if (this.cluster.preferences.prometheus) {
|
if (this.cluster.preferences.prometheus) {
|
||||||
@ -158,7 +157,8 @@ export default {
|
|||||||
onTerminalCwdSave: function() {
|
onTerminalCwdSave: function() {
|
||||||
if(this.cluster.preferences.terminalCWD === "") this.cluster.preferences.terminalCWD = null
|
if(this.cluster.preferences.terminalCWD === "") this.cluster.preferences.terminalCWD = null
|
||||||
this.$store.dispatch("storeCluster", this.cluster);
|
this.$store.dispatch("storeCluster", this.cluster);
|
||||||
}
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
"cluster": "updateValues",
|
"cluster": "updateValues",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user