From 3b27379ce7ffeb04586c4f3429a9ef7403426a29 Mon Sep 17 00:00:00 2001 From: Alexander Zalyalov Date: Thu, 9 May 2024 19:53:38 +0000 Subject: [PATCH] advance time of metrics aggregates --- ydb/core/mind/hive/tablet_info.cpp | 12 +++++++++--- ydb/core/util/metrics.h | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ydb/core/mind/hive/tablet_info.cpp b/ydb/core/mind/hive/tablet_info.cpp index 88facc69ba09..20c64065a5b5 100644 --- a/ydb/core/mind/hive/tablet_info.cpp +++ b/ydb/core/mind/hive/tablet_info.cpp @@ -346,9 +346,11 @@ void TTabletInfo::UpdateResourceUsage(const NKikimrTabletBase::TMetrics& metrics BLOG_W("Ignoring too high CPU metric (" << metrics.GetCPU() << ") for tablet " << ToString()); } else { ResourceMetricsAggregates.MaximumCPU.SetValue(metrics.GetCPU(), now); - ResourceValues.SetCPU(ResourceMetricsAggregates.MaximumCPU.GetValue()); } + } else { + ResourceMetricsAggregates.MaximumCPU.AdvanceTime(now); } + ResourceValues.SetCPU(ResourceMetricsAggregates.MaximumCPU.GetValue()); } if (HasAllowedMetric(allowedMetricIds, EResourceToBalance::Memory)) { if (metrics.HasMemory()) { @@ -356,9 +358,11 @@ void TTabletInfo::UpdateResourceUsage(const NKikimrTabletBase::TMetrics& metrics BLOG_W("Ignoring too high Memory metric (" << metrics.GetMemory() << ") for tablet " << ToString()); } else { ResourceMetricsAggregates.MaximumMemory.SetValue(metrics.GetMemory(), now); - ResourceValues.SetMemory(ResourceMetricsAggregates.MaximumMemory.GetValue()); } + } else { + ResourceMetricsAggregates.MaximumMemory.AdvanceTime(now); } + ResourceValues.SetMemory(ResourceMetricsAggregates.MaximumMemory.GetValue()); } if (HasAllowedMetric(allowedMetricIds, EResourceToBalance::Network)) { if (metrics.HasNetwork()) { @@ -366,9 +370,11 @@ void TTabletInfo::UpdateResourceUsage(const NKikimrTabletBase::TMetrics& metrics BLOG_W("Ignoring too high Network metric (" << metrics.GetNetwork() << ") for tablet " << ToString()); } else { ResourceMetricsAggregates.MaximumNetwork.SetValue(metrics.GetNetwork(), now); - ResourceValues.SetNetwork(ResourceMetricsAggregates.MaximumNetwork.GetValue()); } + } else { + ResourceMetricsAggregates.MaximumNetwork.AdvanceTime(now); } + ResourceValues.SetNetwork(ResourceMetricsAggregates.MaximumNetwork.GetValue()); } if (metrics.HasStorage()) { ResourceValues.SetStorage(metrics.GetStorage()); diff --git a/ydb/core/util/metrics.h b/ydb/core/util/metrics.h index cae931733faf..c58a7d65c4cf 100644 --- a/ydb/core/util/metrics.h +++ b/ydb/core/util/metrics.h @@ -436,6 +436,15 @@ class TMaximumValueVariableWindowUI64 : public NKikimrMetricsProto::TMaximumValu } } + void AdvanceTime(TInstant now) { + // Nothing changed, last value is stiil relevant + TType lastValue = {}; + if (!TProto::GetValues().empty()) { + lastValue = *std::prev(TProto::MutableValues()->end()); + } + SetValue(lastValue, now); + } + TType GetValue() const { return MaximumValue; }