From 1c8f66b467b0b5e84de6e6c424fbe65e825f5e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gell=C3=A9rt=20Peresztegi-Nagy?= Date: Fri, 20 Sep 2024 17:31:05 +0100 Subject: [PATCH] storage: disable metrics in disk_log_builder tests These two fixture tests create multiple `feature_table`s at the same time. This commit disables emitting metrics on these tests to prevent double metric registration errors in the follow up commit of this PR. --- src/v/storage/tests/BUILD | 1 + src/v/storage/tests/segment_deduplication_test.cc | 12 ++++++++++++ src/v/storage/tests/storage_test_fixture.h | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/v/storage/tests/BUILD b/src/v/storage/tests/BUILD index f1a49f2884394..0d45547fec77b 100644 --- a/src/v/storage/tests/BUILD +++ b/src/v/storage/tests/BUILD @@ -291,6 +291,7 @@ redpanda_cc_gtest( deps = [ ":disk_log_builder", ":disk_log_builder_fixture", + "//src/v/config", "//src/v/model", "//src/v/model/tests:random", "//src/v/random:generators", diff --git a/src/v/storage/tests/segment_deduplication_test.cc b/src/v/storage/tests/segment_deduplication_test.cc index 44c03cf97047c..96a8dd44e57ec 100644 --- a/src/v/storage/tests/segment_deduplication_test.cc +++ b/src/v/storage/tests/segment_deduplication_test.cc @@ -7,6 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0 +#include "config/configuration.h" #include "gmock/gmock.h" #include "model/record_batch_types.h" #include "model/tests/random_batch.h" @@ -220,6 +221,17 @@ TEST(FindSlidingRangeTest, TestEmptySegmentNoCompactibleRecords) { } TEST(BuildOffsetMap, TestBuildSimpleMap) { + ss::smp::invoke_on_all([] { + config::shard_local_cfg().disable_metrics.set_value(true); + config::shard_local_cfg().disable_public_metrics.set_value(true); + }).get(); + auto defer_config_reset = ss::defer([] { + ss::smp::invoke_on_all([] { + config::shard_local_cfg().disable_metrics.reset(); + config::shard_local_cfg().disable_public_metrics.reset(); + }).get(); + }); + storage::disk_log_builder b; build_segments(b, 3); auto cleanup = ss::defer([&] { b.stop().get(); }); diff --git a/src/v/storage/tests/storage_test_fixture.h b/src/v/storage/tests/storage_test_fixture.h index 20dc71fd272d3..3605538c117b9 100644 --- a/src/v/storage/tests/storage_test_fixture.h +++ b/src/v/storage/tests/storage_test_fixture.h @@ -209,9 +209,14 @@ class storage_test_fixture { resources, feature_table) { configure_unit_test_logging(); - // avoid double metric registrations + // avoid double metric registrations - disk_log_builder and other + // helpers also start a feature_table and other structs that register + // metrics ss::smp::invoke_on_all([] { config::shard_local_cfg().get("disable_metrics").set_value(true); + config::shard_local_cfg() + .get("disable_public_metrics") + .set_value(true); config::shard_local_cfg() .get("log_segment_size_min") .set_value(std::optional{}); @@ -230,6 +235,7 @@ class storage_test_fixture { feature_table.stop().get(); ss::smp::invoke_on_all([] { config::shard_local_cfg().get("disable_metrics").reset(); + config::shard_local_cfg().get("disable_public_metrics").reset(); config::shard_local_cfg().get("log_segment_size_min").reset(); }).get(); }