mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Store prometheus cluster metadata based on metrics request responses (#1438)
* Store prometheus metadata for clusters based on metrics requests Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Use ClusterMetadataKey.PROMETEHUS as key Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Update metadata only if it is changed Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Use structural comparer as default for store sync reaction Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * No need to compare metadata as json anymore Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Use structural comparer only in cluster-store Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Refactoring Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * React only prometeheus preference changes to re-initialise prometheus connection Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Add missing semicolons Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Fix imports Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Report metrics status in cluster-report (#1443) Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Apply suggestions from code review Co-authored-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Fix logger reference Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
4e02e086a9
commit
badabff90e
5 files changed
+60
-29
No files matched your search
+12
-3
@@ -1,8 +1,8 @@
|
||||
import { ipcMain } from "electron";
|
||||
import type { ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences } from "../common/cluster-store";
|
||||
import type { ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences } from "../common/cluster-store";
|
||||
import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api";
|
||||
import type { WorkspaceId } from "../common/workspace-store";
|
||||
import { action, computed, observable, reaction, toJS, when } from "mobx";
|
||||
import { action, comparer, computed, observable, reaction, toJS, when } from "mobx";
|
||||
import { apiKubePrefix } from "../common/vars";
|
||||
import { broadcastMessage } from "../common/ipc";
|
||||
import { ContextHandler } from "./context-handler";
|
||||
@@ -27,7 +27,8 @@ export enum ClusterMetadataKey {
|
||||
CLUSTER_ID = "id",
|
||||
DISTRIBUTION = "distribution",
|
||||
NODES_COUNT = "nodes",
|
||||
LAST_SEEN = "lastSeen"
|
||||
LAST_SEEN = "lastSeen",
|
||||
PROMETHEUS = "prometheus"
|
||||
}
|
||||
|
||||
export type ClusterRefreshOptions = {
|
||||
@@ -87,6 +88,13 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
return this.preferences.clusterName || this.contextName;
|
||||
}
|
||||
|
||||
@computed get prometheusPreferences(): ClusterPrometheusPreferences {
|
||||
const { prometheus, prometheusProvider } = this.preferences;
|
||||
return toJS({ prometheus, prometheusProvider }, {
|
||||
recurseEverything: true,
|
||||
});
|
||||
}
|
||||
|
||||
get version(): string {
|
||||
return String(this.metadata?.version) || "";
|
||||
}
|
||||
@@ -136,6 +144,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
if (ipcMain) {
|
||||
this.eventDisposers.push(
|
||||
reaction(() => this.getState(), () => this.pushState()),
|
||||
reaction(() => this.prometheusPreferences, (prefs) => this.contextHandler.setupPrometheus(prefs), { equals: comparer.structural, }),
|
||||
() => {
|
||||
clearInterval(refreshTimer);
|
||||
clearInterval(refreshMetadataTimer);
|
||||
|
||||
Reference in new issue
Block a user