From 6bbbed4617d1d22fecb0237c073de506e7d2773b Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:32:28 -0700 Subject: [PATCH] feat(PodMetrics): optimize startup (#736) --- src/KubeUI/App.axaml.cs | 5 +++-- src/KubeUI/Controls/PodMetricCPUCell.cs | 14 ++------------ src/KubeUI/Controls/PodMetricMemoryCell.cs | 14 ++------------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/KubeUI/App.axaml.cs b/src/KubeUI/App.axaml.cs index 85c50253..b1aa3117 100644 --- a/src/KubeUI/App.axaml.cs +++ b/src/KubeUI/App.axaml.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; using System.Runtime.InteropServices; using Avalonia.Data.Core.Plugins; using Avalonia.Logging; @@ -112,7 +113,7 @@ public override void Initialize() .AddMeter(Instrumentation.MeterName) .AddOtlpExporter((e, b) => { - b.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 60 * 1000; // 1 min + b.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = (int)TimeSpan.FromMinutes(1).TotalMilliseconds; e.Endpoint = new Uri("https://otel.kubeui.com/v1/metrics"); e.Headers = $"key={key}"; e.Protocol = OtlpExportProtocol.HttpProtobuf; diff --git a/src/KubeUI/Controls/PodMetricCPUCell.cs b/src/KubeUI/Controls/PodMetricCPUCell.cs index 0fbcedba..306c9bd5 100644 --- a/src/KubeUI/Controls/PodMetricCPUCell.cs +++ b/src/KubeUI/Controls/PodMetricCPUCell.cs @@ -15,18 +15,7 @@ public PodMetricCPUCell() { s_timer.Tick += Timer_Tick; s_timer.Interval = TimeSpan.FromSeconds(1); - } - - protected override void OnDataContextChanged(EventArgs e) - { - base.OnDataContextChanged(e); - - Update(); - - if (!s_timer.IsEnabled) - { - s_timer.Start(); - } + s_timer.Start(); } private void Timer_Tick(object? sender, EventArgs e) @@ -80,5 +69,6 @@ protected override void OnUnloaded(RoutedEventArgs e) public void Initialize(ICluster cluster) { Cluster = cluster; + Update(); } } diff --git a/src/KubeUI/Controls/PodMetricMemoryCell.cs b/src/KubeUI/Controls/PodMetricMemoryCell.cs index 5c66f28b..3f7f2868 100644 --- a/src/KubeUI/Controls/PodMetricMemoryCell.cs +++ b/src/KubeUI/Controls/PodMetricMemoryCell.cs @@ -16,18 +16,7 @@ public PodMetricMemoryCell() { s_timer.Tick += Timer_Tick; s_timer.Interval = TimeSpan.FromSeconds(1); - } - - protected override void OnDataContextChanged(EventArgs e) - { - base.OnDataContextChanged(e); - - Update(); - - if (!s_timer.IsEnabled) - { - s_timer.Start(); - } + s_timer.Start(); } private void Timer_Tick(object? sender, EventArgs e) @@ -81,5 +70,6 @@ protected override void OnUnloaded(RoutedEventArgs e) public void Initialize(ICluster cluster) { Cluster = cluster; + Update(); } }