From 8a450cc476d33f6374164f1f00d92cdf65309558 Mon Sep 17 00:00:00 2001 From: Guy Arbitman Date: Tue, 10 Dec 2024 22:53:44 +0200 Subject: [PATCH] usm: telemetry: tests: Move Clear method to test only file (#31981) --- pkg/network/protocols/telemetry/registry.go | 12 ------------ .../protocols/telemetry/registry_testutil.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 pkg/network/protocols/telemetry/registry_testutil.go diff --git a/pkg/network/protocols/telemetry/registry.go b/pkg/network/protocols/telemetry/registry.go index d80df1df3394b..a49c997e5899d 100644 --- a/pkg/network/protocols/telemetry/registry.go +++ b/pkg/network/protocols/telemetry/registry.go @@ -60,18 +60,6 @@ func (r *registry) GetMetrics(params ...string) []metric { return result } -// Clear metrics -// WARNING: Only intended for tests -func Clear() { - globalRegistry.Lock() - globalRegistry.metrics = nil - globalRegistry.Unlock() - - telemetryDelta.mux.Lock() - telemetryDelta.stateByClientID = make(map[string]*clientState) - telemetryDelta.mux.Unlock() -} - func init() { globalRegistry = new(registry) } diff --git a/pkg/network/protocols/telemetry/registry_testutil.go b/pkg/network/protocols/telemetry/registry_testutil.go new file mode 100644 index 0000000000000..46777d052b4cc --- /dev/null +++ b/pkg/network/protocols/telemetry/registry_testutil.go @@ -0,0 +1,19 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +//go:build test + +package telemetry + +// Clear metrics +func Clear() { + globalRegistry.Lock() + globalRegistry.metrics = nil + globalRegistry.Unlock() + + telemetryDelta.mux.Lock() + telemetryDelta.stateByClientID = make(map[string]*clientState) + telemetryDelta.mux.Unlock() +}