Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v24.1.x] [CORE-8141] Add host information to metrics report #24044

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/v/cluster/metrics_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
#include <seastar/core/coroutine.hh>
#include <seastar/core/lowres_clock.hh>
#include <seastar/core/shared_ptr.hh>
#include <seastar/net/dns.hh>
#include <seastar/net/tls.hh>
#include <seastar/util/defer.hh>

#include <absl/algorithm/container.h>
#include <absl/container/node_hash_map.h>
Expand All @@ -53,9 +55,38 @@
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <fmt/core.h>
#include <sys/socket.h>

#include <climits>
#include <netdb.h>
#include <stdexcept>

namespace {
ss::sstring get_hostname() {
std::array<char, HOST_NAME_MAX> hostname{};
if (::gethostname(hostname.data(), hostname.size()) != 0) {
return {};
}

return hostname.data();
}

ss::sstring get_domainname() {
std::array<char, HOST_NAME_MAX> domainname{};
if (::getdomainname(domainname.data(), domainname.size()) != 0) {
return {};
}

return domainname.data();
}

ss::future<std::vector<ss::sstring>> get_fqdns(std::string_view hostname) {
ss::net::dns_resolver resolver;
auto hostent = co_await resolver.get_host_by_name(hostname.data());
co_return hostent.names;
}
} // namespace

namespace cluster {

namespace details {
Expand Down Expand Up @@ -217,6 +248,14 @@ metrics_reporter::build_metrics_snapshot() {
}

metrics.uptime_ms = report->local_state.uptime / 1ms;
auto& advertised_listeners
= nm->get().broker.kafka_advertised_listeners();
metrics.advertised_listeners.reserve(advertised_listeners.size());
std::transform(
advertised_listeners.begin(),
advertised_listeners.end(),
std::back_inserter(metrics.advertised_listeners),
[](const model::broker_endpoint& ep) { return ep.address; });
}
auto& topics = _topics.local().topics_map();
snapshot.topic_count = 0;
Expand Down Expand Up @@ -276,6 +315,10 @@ metrics_reporter::build_metrics_snapshot() {

snapshot.enterprise_features.emplace(std::move(feature_report));

snapshot.host_name = get_hostname();
snapshot.domain_name = get_domainname();
snapshot.fqdns = co_await get_fqdns(snapshot.host_name);

co_return snapshot;
}

Expand Down Expand Up @@ -559,6 +602,15 @@ void rjson_serialize(
w.EndArray();
}

w.Key("hostname");
w.String(snapshot.host_name);

w.Key("domainname");
w.String(snapshot.domain_name);

w.Key("fqdns");
rjson_serialize(w, snapshot.fqdns);

w.EndObject();
}

Expand Down Expand Up @@ -595,6 +647,8 @@ void rjson_serialize(
rjson_serialize(w, d);
}
w.EndArray();
w.Key("kafka_advertised_listeners");
rjson_serialize(w, nm.advertised_listeners);

w.EndObject();
}
Expand Down
6 changes: 6 additions & 0 deletions src/v/cluster/metrics_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "features/fwd.h"
#include "http/client.h"
#include "model/metadata.h"
#include "net/unresolved_address.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is it yeah?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah sorry I should have called it out

#include "security/fwd.h"
#include "utils/prefix_logger.h"

Expand Down Expand Up @@ -58,6 +59,7 @@ class metrics_reporter {
cluster_version logical_version{invalid_version};
std::vector<node_disk_space> disks;
uint64_t uptime_ms{0};
std::vector<net::unresolved_address> advertised_listeners;
};

struct metrics_snapshot {
Expand Down Expand Up @@ -85,6 +87,10 @@ class metrics_reporter {
bool has_valid_license{false};

std::optional<features::enterprise_feature_report> enterprise_features;

ss::sstring host_name;
ss::sstring domain_name;
std::vector<ss::sstring> fqdns;
};
static constexpr ss::shard_id shard = 0;

Expand Down
7 changes: 7 additions & 0 deletions tests/rptest/tests/metrics_reporter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def assert_fields_are_the_same(metadata, field):
assert_fields_are_the_same(metadata, 'has_valid_license')
assert_fields_are_the_same(metadata, 'has_enterprise_features')
assert_fields_are_the_same(metadata, 'enterprise_features')
assert_fields_are_the_same(metadata, 'hostname')
assert_fields_are_the_same(metadata, 'domainname')
assert_fields_are_the_same(metadata, 'fqdns')
# get the last report
last = metadata.pop()
assert last['topic_count'] == total_topics
Expand All @@ -152,6 +155,9 @@ def assert_fields_are_the_same(metadata, field):
assert last['has_enterprise_features'] == False
assert 'enterprise_features' in last
assert type(last['enterprise_features']) == list
assert 'hostname' in last
assert 'domainname' in last
assert 'fqdns' in last
nodes_meta = last['nodes']

assert len(last['nodes']) == len(self.redpanda.nodes)
Expand All @@ -163,6 +169,7 @@ def assert_fields_are_the_same(metadata, field):
assert all('uptime_ms' in n for n in nodes_meta)
assert all('is_alive' in n for n in nodes_meta)
assert all('disks' in n for n in nodes_meta)
assert all('kafka_advertised_listeners' in n for n in nodes_meta)

# Check cluster UUID and creation time survive a restart
for n in self.redpanda.nodes:
Expand Down