Skip to content

Commit

Permalink
advance time of metrics aggregates
Browse files Browse the repository at this point in the history
  • Loading branch information
vporyadke committed May 13, 2024
1 parent 2631f5b commit 9bfec73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ydb/core/mind/hive/tablet_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,35 @@ 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 (Find(allowedMetricIds, NKikimrTabletBase::TMetrics::kMemoryFieldNumber) != allowedMetricIds.end()) {
if (metrics.HasMemory()) {
if (metrics.GetMemory() > static_cast<ui64>(std::get<NMetrics::EResource::Memory>(maximum))) {
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 (Find(allowedMetricIds, NKikimrTabletBase::TMetrics::kNetworkFieldNumber) != allowedMetricIds.end()) {
if (metrics.HasNetwork()) {
if (metrics.GetNetwork() > static_cast<ui64>(std::get<NMetrics::EResource::Network>(maximum))) {
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());
Expand Down
9 changes: 9 additions & 0 deletions ydb/core/util/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9bfec73

Please sign in to comment.