Skip to content

Commit

Permalink
add IsEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
boks1971 committed Nov 24, 2024
1 parent 0d5ca88 commit 28e4467
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils/metrics_batch_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions utils/metrics_batch_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 28e4467

Please sign in to comment.