Skip to content

Commit 6c2275d

Browse files
committed
.withImplicitZero
1 parent bfc0198 commit 6c2275d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

ydb/core/persqueue/pqtablet/metering_sink.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,19 @@ const TMeteringSink::FlushParameters TMeteringSink::GetFlushParameters(const EMe
167167
case EMeteringJson::UsedStorageV1: {
168168
ui64 duration = (now - lastFlush).MilliSeconds();
169169
ui64 avgUsage = duration > 0 ? CurrentUsedStorage_ * 1_MB * 1000 / duration : 0;
170+
ui64 quantity = (avgUsage > 0) ? 1 : 0;
170171

171172
CurrentUsedStorage_ = 0;
172173

173174
return TMeteringSink::FlushParameters(
174175
"used_storage",
175176
"ydb.serverless.v1",
176-
"byte*second"
177+
"byte*second",
178+
quantity
177179
).withTags({
178180
{"ydb_size", avgUsage}
179181
})
182+
.withImplicitZero()
180183
.withVersion("1.0.0");
181184
}
182185

@@ -195,7 +198,7 @@ void TMeteringSink::Flush(TInstant now, bool force) {
195198
continue;
196199
}
197200

198-
auto parameters = GetFlushParameters(whichOne, now, lastFlush);
201+
const auto parameters = GetFlushParameters(whichOne, now, lastFlush);
199202

200203
if (parameters.OneFlush) {
201204
const auto isTimeToFlushUnits = now.Hours() > lastFlush.Hours();
@@ -218,13 +221,15 @@ void TMeteringSink::Flush(TInstant now, bool force) {
218221
auto interval = TInstant::Hours(lastFlush.Hours()) + Parameters_.FlushLimit;
219222

220223
auto tryFlush = [&](TInstant start, TInstant finish) {
221-
const auto metricsJson = GetMeteringJson(
222-
parameters,
223-
parameters.Quantity * (finish.Seconds() - start.Seconds()),
224-
start,
225-
finish,
226-
now);
227-
FlushFunction_(metricsJson);
224+
if (parameters.Quantity > 0 || !parameters.ImplicitZero) {
225+
const auto metricsJson = GetMeteringJson(
226+
parameters,
227+
parameters.Quantity * (finish.Seconds() - start.Seconds()),
228+
start,
229+
finish,
230+
now);
231+
FlushFunction_(metricsJson);
232+
}
228233

229234
lastFlush = finish;
230235
};

ydb/core/persqueue/pqtablet/metering_sink.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,19 @@ class TMeteringSink {
7979
return *this;
8080
}
8181

82+
// skip flush, if quantity is zero
83+
FlushParameters& withImplicitZero() {
84+
ImplicitZero = true;
85+
return *this;
86+
}
87+
8288
TString Name;
8389
TString Schema;
8490
TString Units;
8591
ui64 Quantity;
8692
THashMap<TString, ui64> Tags;
8793
bool OneFlush = false;
94+
bool ImplicitZero = false;
8895
TString Version = "v1";
8996
};
9097

0 commit comments

Comments
 (0)