Skip to content

Commit 15e08e1

Browse files
authored
advance time of metrics aggregates (#4455)
1 parent 667353d commit 15e08e1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ydb/core/mind/hive/tablet_info.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -324,29 +324,35 @@ void TTabletInfo::UpdateResourceUsage(const NKikimrTabletBase::TMetrics& metrics
324324
BLOG_W("Ignoring too high CPU metric (" << metrics.GetCPU() << ") for tablet " << ToString());
325325
} else {
326326
ResourceMetricsAggregates.MaximumCPU.SetValue(metrics.GetCPU(), now);
327-
ResourceValues.SetCPU(ResourceMetricsAggregates.MaximumCPU.GetValue());
328327
}
328+
} else {
329+
ResourceMetricsAggregates.MaximumCPU.AdvanceTime(now);
329330
}
331+
ResourceValues.SetCPU(ResourceMetricsAggregates.MaximumCPU.GetValue());
330332
}
331333
if (Find(allowedMetricIds, NKikimrTabletBase::TMetrics::kMemoryFieldNumber) != allowedMetricIds.end()) {
332334
if (metrics.HasMemory()) {
333335
if (metrics.GetMemory() > static_cast<ui64>(std::get<NMetrics::EResource::Memory>(maximum))) {
334336
BLOG_W("Ignoring too high Memory metric (" << metrics.GetMemory() << ") for tablet " << ToString());
335337
} else {
336338
ResourceMetricsAggregates.MaximumMemory.SetValue(metrics.GetMemory(), now);
337-
ResourceValues.SetMemory(ResourceMetricsAggregates.MaximumMemory.GetValue());
338339
}
340+
} else {
341+
ResourceMetricsAggregates.MaximumMemory.AdvanceTime(now);
339342
}
343+
ResourceValues.SetMemory(ResourceMetricsAggregates.MaximumMemory.GetValue());
340344
}
341345
if (Find(allowedMetricIds, NKikimrTabletBase::TMetrics::kNetworkFieldNumber) != allowedMetricIds.end()) {
342346
if (metrics.HasNetwork()) {
343347
if (metrics.GetNetwork() > static_cast<ui64>(std::get<NMetrics::EResource::Network>(maximum))) {
344348
BLOG_W("Ignoring too high Network metric (" << metrics.GetNetwork() << ") for tablet " << ToString());
345349
} else {
346350
ResourceMetricsAggregates.MaximumNetwork.SetValue(metrics.GetNetwork(), now);
347-
ResourceValues.SetNetwork(ResourceMetricsAggregates.MaximumNetwork.GetValue());
348351
}
352+
} else {
353+
ResourceMetricsAggregates.MaximumNetwork.AdvanceTime(now);
349354
}
355+
ResourceValues.SetNetwork(ResourceMetricsAggregates.MaximumNetwork.GetValue());
350356
}
351357
if (metrics.HasStorage()) {
352358
ResourceValues.SetStorage(metrics.GetStorage());

ydb/core/util/metrics.h

+9
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ class TMaximumValueVariableWindowUI64 : public NKikimrMetricsProto::TMaximumValu
436436
}
437437
}
438438

439+
void AdvanceTime(TInstant now) {
440+
// Nothing changed, last value is stiil relevant
441+
TType lastValue = {};
442+
if (!TProto::GetValues().empty()) {
443+
lastValue = *std::prev(TProto::MutableValues()->end());
444+
}
445+
SetValue(lastValue, now);
446+
}
447+
439448
TType GetValue() const {
440449
return MaximumValue;
441450
}

0 commit comments

Comments
 (0)