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] auditing: construct metrics probe during service construction #24128

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
12 changes: 5 additions & 7 deletions src/v/security/audit/audit_log_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ audit_log_manager::audit_log_manager(
, _controller(controller)
, _config(client_config)
, _metadata_cache(metadata_cache) {
_probe.setup_metrics([this] {
return 1.0
- (static_cast<double>(_queue_bytes_sem.available_units()) / static_cast<double>(_max_queue_size_bytes));
});
if (ss::this_shard_id() == client_shard_id) {
_sink = std::make_unique<audit_sink>(this, controller, client_config);
}
Expand Down Expand Up @@ -808,11 +812,6 @@ ss::future<> audit_log_manager::start() {
"Redpanda is operating in recovery mode. Auditing is disabled!");
co_return;
}
_probe = std::make_unique<audit_probe>();
_probe->setup_metrics([this] {
return 1.0
- (static_cast<double>(_queue_bytes_sem.available_units()) / static_cast<double>(_max_queue_size_bytes));
});
if (ss::this_shard_id() != client_shard_id) {
co_return;
}
Expand Down Expand Up @@ -846,7 +845,6 @@ ss::future<> audit_log_manager::stop() {
/// Gate may already be closed if ::pause() had been called
co_await _gate.close();
}
_probe.reset(nullptr);
if (_queue.size() > 0) {
vlog(
adtlog.debug,
Expand Down Expand Up @@ -1006,7 +1004,7 @@ audit_log_manager::should_enqueue_audit_event() const {
adtlog.warn,
"Audit message passthrough active until cluster has been fully "
"upgraded to the min supported version for audit_logging");
_probe->audit_error();
_probe.audit_error();
return std::make_optional(audit_event_passthrough::yes);
}
if (_auth_misconfigured) {
Expand Down
7 changes: 5 additions & 2 deletions src/v/security/audit/audit_log_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class audit_log_manager
return true;
}

audit_probe& probe() { return *_probe; }
audit_probe& probe() { return _probe; }

template<security::audit::returns_auditable_resource_vector Func>
auto restrict_topics(Func&& func) const noexcept {
Expand Down Expand Up @@ -401,6 +401,10 @@ class audit_log_manager
underlying_t _queue;
ssx::semaphore _active_drain{1, "audit-drain"};

// Probe is mutable so it can be modified in const methods when they need to
// report auditing failures
mutable audit_probe _probe;

/// Single instance contains a kafka::client::client instance.
friend class audit_sink;
std::unique_ptr<audit_sink> _sink;
Expand All @@ -409,7 +413,6 @@ class audit_log_manager
model::node_id _self;
cluster::controller* _controller;
kafka::client::configuration& _config;
std::unique_ptr<audit_probe> _probe;

ss::sharded<cluster::metadata_cache>* _metadata_cache;
};
Expand Down
Loading