From eccaf0e50149d890d4c8350371c498aa062bb680 Mon Sep 17 00:00:00 2001 From: NyaliaLui Date: Tue, 8 Aug 2023 13:24:45 -0400 Subject: [PATCH] cluster: include a hash in the metrics reporter Signed-off-by: NyaliaLui --- src/v/cluster/metrics_reporter.cc | 8 ++++++++ src/v/cluster/metrics_reporter.h | 1 + tests/rptest/tests/metrics_reporter_test.py | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/v/cluster/metrics_reporter.cc b/src/v/cluster/metrics_reporter.cc index 19ca7f2bcb05d..da8798aec02d7 100644 --- a/src/v/cluster/metrics_reporter.cc +++ b/src/v/cluster/metrics_reporter.cc @@ -269,6 +269,11 @@ metrics_reporter::build_metrics_snapshot() { 0, metrics_snapshot::max_size_for_rp_env); } + auto license = _feature_table.local().get_license(); + if (license.has_value()) { + snapshot.id_hash = license->checksum; + } + co_return snapshot; } @@ -523,6 +528,9 @@ void rjson_serialize( w.Key("redpanda_environment"); w.String(snapshot.redpanda_environment); + w.Key("id_hash"); + w.String(snapshot.id_hash); + w.EndObject(); } diff --git a/src/v/cluster/metrics_reporter.h b/src/v/cluster/metrics_reporter.h index 6805426cbb216..a0fb7aaebb760 100644 --- a/src/v/cluster/metrics_reporter.h +++ b/src/v/cluster/metrics_reporter.h @@ -78,6 +78,7 @@ class metrics_reporter { static constexpr int64_t max_size_for_rp_env = 80; ss::sstring redpanda_environment; + ss::sstring id_hash; }; static constexpr ss::shard_id shard = 0; diff --git a/tests/rptest/tests/metrics_reporter_test.py b/tests/rptest/tests/metrics_reporter_test.py index 84e1caa797f94..65da25ede4449 100644 --- a/tests/rptest/tests/metrics_reporter_test.py +++ b/tests/rptest/tests/metrics_reporter_test.py @@ -12,6 +12,7 @@ from rptest.services.cluster import cluster from rptest.services.redpanda import RESTART_LOG_ALLOW_LIST +from rptest.utils.rpenv import sample_license from ducktape.utils.util import wait_until from rptest.clients.types import TopicSpec @@ -47,6 +48,18 @@ def _test_redpanda_metrics_reporting(self): """ Test that redpanda nodes send well formed messages to the metrics endpoint """ + + # Load and put a license at start. This is to check the SHA-256 checksum + admin = Admin(self.redpanda) + license = sample_license() + if license is None: + self.logger.warn( + "REDPANDA_SAMPLE_LICENSE env var not found, ignoring license checks." + ) + + assert admin.put_license( + license).status_code == 200, "PUT License failed" + total_topics = 5 total_partitions = 0 for _ in range(0, total_topics): @@ -80,7 +93,6 @@ def _state_up_to_date(): def assert_fields_are_the_same(metadata, field): assert all(m[field] == metadata[0][field] for m in metadata) - admin = Admin(self.redpanda) features = admin.get_features() # cluster uuid and create timestamp should stay the same across requests @@ -123,6 +135,7 @@ def assert_fields_are_the_same(metadata, field): wait_until(lambda: len(self.http.requests) > pre_restart_requests, timeout_sec=20, backoff_sec=1) + self.redpanda.logger.info("Checking metadata after restart") assert_fields_are_the_same(metadata, 'cluster_uuid') assert_fields_are_the_same(metadata, 'cluster_created_ts') @@ -134,6 +147,9 @@ def assert_fields_are_the_same(metadata, field): assert last["config"]["log_message_timestamp_type"] == "CreateTime" assert last["redpanda_environment"] == "test" + last_post_restart = metadata.pop() + assert last_post_restart["id_hash"] == last["id_hash"] + class MultiNodeMetricsReporterTest(MetricsReporterTest): """