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 { mangleProxyEnv } from "./proxy-env"
|
||||
import { findMainWebContents } from "./webcontents"
|
||||
import "./prometheus/index"
|
||||
import "../common/prometheus-providers"
|
||||
|
||||
mangleProxyEnv()
|
||||
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
||||
|
||||
@ -3,6 +3,8 @@ import { PrometheusLens } from "./lens"
|
||||
export class PrometheusHelm extends PrometheusLens {
|
||||
constructor() {
|
||||
super()
|
||||
this.id = "helm"
|
||||
this.name = "Helm"
|
||||
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 {
|
||||
id = "lens"
|
||||
name = "Lens"
|
||||
rateAccuracy = "1m"
|
||||
|
||||
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 {
|
||||
rateAccuracy = "1m"
|
||||
id = "operator"
|
||||
name = "Prometheus Operator"
|
||||
|
||||
public getQueries(opts: PrometheusQueryOpts): PrometheusQuery {
|
||||
switch(opts.category) {
|
||||
|
||||
@ -10,10 +10,12 @@ export interface PrometheusProvider {
|
||||
getQueries(opts: PrometheusQueryOpts): PrometheusQuery;
|
||||
}
|
||||
|
||||
export type PrometheusProviderList = {
|
||||
[key: string]: PrometheusProvider;
|
||||
}
|
||||
|
||||
export class PrometheusProviderRegistry {
|
||||
private static prometheusProviders: {
|
||||
[key: string]: PrometheusProvider;
|
||||
} = {}
|
||||
private static prometheusProviders: PrometheusProviderList = {}
|
||||
|
||||
static getProvider(type: string): PrometheusProvider {
|
||||
if (!this.prometheusProviders[type]) {
|
||||
@ -25,4 +27,8 @@ export class PrometheusProviderRegistry {
|
||||
static registerProvider(key: string, provider: PrometheusProvider) {
|
||||
this.prometheusProviders[key] = provider
|
||||
}
|
||||
|
||||
static getProviders(): PrometheusProvider[] {
|
||||
return Object.values(this.prometheusProviders)
|
||||
}
|
||||
}
|
||||
@ -67,6 +67,8 @@
|
||||
|
||||
<script>
|
||||
import { lstatSync } from "fs"
|
||||
import { prometheusProviders } from '../../../../common/prometheus-providers';
|
||||
|
||||
export default {
|
||||
name: 'ClusterSettingsPreferences',
|
||||
props: {
|
||||
@ -82,18 +84,15 @@ export default {
|
||||
},
|
||||
prometheusPath: "",
|
||||
prometheusProvider: "",
|
||||
prometheusProviders: [
|
||||
{ text: "Lens", value: "lens"},
|
||||
{ text: "Helm", value: "helm"},
|
||||
{ text: "Prometheus Operator", value: "operator"}
|
||||
]
|
||||
prometheusProviders: [],
|
||||
}
|
||||
},
|
||||
mounted: function() {
|
||||
mounted: async function() {
|
||||
this.prometheusProviders = prometheusProviders.map((provider) => {
|
||||
return { text: provider.name, value: provider.id }
|
||||
})
|
||||
this.updateValues()
|
||||
},
|
||||
computed: {
|
||||
},
|
||||
methods: {
|
||||
updateValues: function(){
|
||||
if (this.cluster.preferences.prometheus) {
|
||||
@ -158,7 +157,8 @@ export default {
|
||||
onTerminalCwdSave: function() {
|
||||
if(this.cluster.preferences.terminalCWD === "") this.cluster.preferences.terminalCWD = null
|
||||
this.$store.dispatch("storeCluster", this.cluster);
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
watch: {
|
||||
"cluster": "updateValues",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user