From 6b9317018ec7c9ca3c3dd9d8b846c1628b075973 Mon Sep 17 00:00:00 2001 From: Keiko Oda Date: Tue, 3 Dec 2024 15:34:31 +0900 Subject: [PATCH 1/3] Make getFirstMetricValue to return the first value This function was previously returning the last value instead of the first value. This fix changes it and returns the value as soon as reading it. --- input/system/azure/system.go | 1 + 1 file changed, 1 insertion(+) diff --git a/input/system/azure/system.go b/input/system/azure/system.go index 107ba5fb2..30901f3c0 100644 --- a/input/system/azure/system.go +++ b/input/system/azure/system.go @@ -286,6 +286,7 @@ func getFirstMetricValue(metric *azquery.Metric) (metricValue *azquery.MetricVal for _, timeSeriesElement := range metric.TimeSeries { for _, mValue := range timeSeriesElement.Data { metricValue = mValue + return } } return From 50026b73eb1b98911e43d50b53265835f5d5fd1c Mon Sep 17 00:00:00 2001 From: Keiko Oda Date: Tue, 3 Dec 2024 17:21:01 +0900 Subject: [PATCH 2/3] Update input/system/azure/system.go Co-authored-by: Maciek Sakrejda --- input/system/azure/system.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/input/system/azure/system.go b/input/system/azure/system.go index 30901f3c0..a2a8d59b6 100644 --- a/input/system/azure/system.go +++ b/input/system/azure/system.go @@ -283,11 +283,8 @@ func GetSystemState(ctx context.Context, server *state.Server, logger *util.Logg // getFirstMetricValue gets the first data from the time series metric and returns the value func getFirstMetricValue(metric *azquery.Metric) (metricValue *azquery.MetricValue) { - for _, timeSeriesElement := range metric.TimeSeries { - for _, mValue := range timeSeriesElement.Data { - metricValue = mValue - return - } - } - return + if len(metric.TimeSeries) == 0 || len(metric.TimeSeries[0].timeSeriesElement.Data) == 0 { + return + } + return metric.TimeSeries[0].timeSeriesElement.Data[0] } From c52816089b129a770c48b81ca44a660a3afc1bb5 Mon Sep 17 00:00:00 2001 From: Keiko Oda Date: Tue, 3 Dec 2024 17:25:51 +0900 Subject: [PATCH 3/3] Tweak code --- input/system/azure/system.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/input/system/azure/system.go b/input/system/azure/system.go index a2a8d59b6..0b95b3779 100644 --- a/input/system/azure/system.go +++ b/input/system/azure/system.go @@ -283,8 +283,8 @@ func GetSystemState(ctx context.Context, server *state.Server, logger *util.Logg // getFirstMetricValue gets the first data from the time series metric and returns the value func getFirstMetricValue(metric *azquery.Metric) (metricValue *azquery.MetricValue) { - if len(metric.TimeSeries) == 0 || len(metric.TimeSeries[0].timeSeriesElement.Data) == 0 { - return - } - return metric.TimeSeries[0].timeSeriesElement.Data[0] + if len(metric.TimeSeries) == 0 || len(metric.TimeSeries[0].Data) == 0 { + return + } + return metric.TimeSeries[0].Data[0] }