From 28e44673c94ea40ef0fb337b4b52396b451cf838 Mon Sep 17 00:00:00 2001 From: boks1971 Date: Sun, 24 Nov 2024 13:48:31 +0530 Subject: [PATCH] add IsEmpty --- utils/metrics_batch_builder.go | 4 ++++ utils/metrics_batch_builder_test.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/utils/metrics_batch_builder.go b/utils/metrics_batch_builder.go index b7b28cd3..d6fc54e2 100644 --- a/utils/metrics_batch_builder.go +++ b/utils/metrics_batch_builder.go @@ -274,6 +274,10 @@ func (m *MetricsBatchBuilder) Merge(other *livekit.MetricsBatch) { } } +func (m *MetricsBatchBuilder) IsEmpty() bool { + return len(m.MetricsBatch.TimeSeries) == 0 && len(m.MetricsBatch.Events) == 0 +} + func (m *MetricsBatchBuilder) isLabelFiltered(label livekit.MetricLabel, participantIdentity livekit.ParticipantIdentity) bool { if participantIdentity == m.restrictedLabels.ParticipantIdentity { // all labels allowed for restricted participant diff --git a/utils/metrics_batch_builder_test.go b/utils/metrics_batch_builder_test.go index 565ced11..6e15a16b 100644 --- a/utils/metrics_batch_builder_test.go +++ b/utils/metrics_batch_builder_test.go @@ -36,6 +36,7 @@ func TestMetricsBatchBuilder(t *testing.T) { } mbb := NewMetricsBatchBuilder() + require.True(t, mbb.IsEmpty()) mbb.SetTime( time.Unix(0, expected.TimestampMs*int64(time.Millisecond)), expected.NormalizedTimestamp.AsTime(), @@ -165,6 +166,7 @@ func TestMetricsBatchBuilder(t *testing.T) { Rid: "f", }) require.NoError(t, err) + require.False(t, mbb.IsEmpty()) // should not be able to add sample to invalid index err = mbb.AddMetricSamplesToTimeSeriesMetric(-1, nil)