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

[draft] Pp access log v24.2.x #25061

Draft
wants to merge 2 commits into
base: v24.2.x
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion src/v/pandaproxy/rest/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace pandaproxy::rest {

using server = proxy::server;

ss::logger rest_proxy_access("rest_proxy_access");

const security::acl_principal principal{
security::principal_type::ephemeral_user, "__pandaproxy"};

Expand Down Expand Up @@ -123,7 +125,8 @@ proxy::proxy(
"header",
"/definitions",
_ctx,
json::serialization_format::application_json)
json::serialization_format::application_json,
rest_proxy_access)
, _ensure_started{[this]() { return do_start(); }}
, _controller(controller) {
_inflight_config_binding.watch([this]() {
Expand Down
11 changes: 11 additions & 0 deletions src/v/pandaproxy/schema_registry/handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <seastar/core/future.hh>
#include <seastar/core/sstring.hh>

#include <absl/strings/escaping.h>

#include <limits>

namespace ppj = pandaproxy::json;
Expand Down Expand Up @@ -425,6 +427,7 @@ post_subject(server::request_t rq, server::reply_t rp) {
try {
auto unparsed = co_await ppj::rjson_parse(
std::move(rq.req), post_subject_versions_request_handler<>{sub});
vlog(rq.service().access_logger().trace, "{}", unparsed.def);
schema = co_await rq.service().schema_store().make_canonical_schema(
std::move(unparsed.def), norm);
} catch (const exception& e) {
Expand Down Expand Up @@ -465,6 +468,7 @@ post_subject_versions(server::request_t rq, server::reply_t rp) {

auto unparsed = co_await ppj::rjson_parse(
std::move(rq.req), post_subject_versions_request_handler<>{sub});
vlog(rq.service().access_logger().trace, "{}", unparsed.def);

// If presented with a non-positive integer for version, set it to
// invalid_schema_version so that the version number can be projected
Expand Down Expand Up @@ -522,6 +526,9 @@ ss::future<ctx_server<service>::reply_t> get_subject_versions_version(
sub, version, inc_del);
});

auto str = fmt::format("{}", get_res.schema);
vlog(rq.service().access_logger().trace, "{}", absl::CEscape(str));

rp.rep->write_body(
"json",
ppj::rjson_serialize(post_subject_versions_version_response{
Expand All @@ -548,6 +555,9 @@ ss::future<ctx_server<service>::reply_t> get_subject_versions_version_schema(
auto get_res = co_await rq.service().schema_store().get_subject_schema(
sub, version, inc_del);

auto str = fmt::format("{}", get_res.schema);
vlog(rq.service().access_logger().trace, "{}", absl::CEscape(str));

rp.rep->write_body(
"json", ppj::as_body_writer(std::move(get_res.schema).def().raw()()));
co_return rp;
Expand Down Expand Up @@ -653,6 +663,7 @@ compatibility_subject_version(server::request_t rq, server::reply_t rp) {
.value_or(verbose::no)};
auto unparsed = co_await ppj::rjson_parse(
std::move(rq.req), post_subject_versions_request_handler<>{sub});
vlog(rq.service().access_logger().trace, "{}", unparsed.def);

// Must read, in case we have the subject in cache with an outdated config
co_await rq.service().writer().read_sync();
Expand Down
7 changes: 6 additions & 1 deletion src/v/pandaproxy/schema_registry/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
#include <seastar/coroutine/parallel_for_each.hh>
#include <seastar/http/api_docs.hh>
#include <seastar/http/exception.hh>
#include <seastar/util/log.hh>
#include <seastar/util/noncopyable_function.hh>

namespace pandaproxy::schema_registry {

static constexpr auto audit_svc_name = "Redpanda Schema Registry Service";
ss::logger schema_registry_access{"schema_registry_access"};

using server = ctx_server<service>;
const security::acl_principal principal{
Expand Down Expand Up @@ -620,7 +622,8 @@ service::service(
"schema_registry_header",
"/schema_registry_definitions",
_ctx,
json::serialization_format::schema_registry_v1_json)
json::serialization_format::schema_registry_v1_json,
schema_registry_access)
, _store(store)
, _writer(sequencer)
, _controller(controller)
Expand Down Expand Up @@ -658,4 +661,6 @@ kafka::client::configuration& service::client_config() {
return _client.local().config();
}

ss::logger& service::access_logger() { return schema_registry_access; }

} // namespace pandaproxy::schema_registry
1 change: 1 addition & 0 deletions src/v/pandaproxy/schema_registry/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class service : public ss::peering_sharded_service<service> {
security::audit::audit_log_manager& audit_mgr() {
return _audit_mgr.local();
}
ss::logger& access_logger();

private:
ss::future<> do_start();
Expand Down
35 changes: 30 additions & 5 deletions src/v/pandaproxy/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
#include <seastar/http/function_handlers.hh>
#include <seastar/http/reply.hh>
#include <seastar/net/tls.hh>
#include <seastar/util/log.hh>

#include <fmt/chrono.h>
#include <fmt/ranges.h>

#include <charconv>
#include <exception>
#include <memory>
#include <type_traits>

namespace pandaproxy {

Expand Down Expand Up @@ -77,12 +79,14 @@ struct handler_adaptor : ss::httpd::handler_base {
server::function_handler&& handler,
ss::httpd::path_description& path_desc,
const ss::sstring& metrics_group_name,
json::serialization_format exceptional_mime_type)
json::serialization_format exceptional_mime_type,
ss::logger& log)
: _pending_requests(pending_requests)
, _ctx(ctx)
, _handler(std::move(handler))
, _probe(path_desc, metrics_group_name)
, _exceptional_mime_type(exceptional_mime_type) {}
, _exceptional_mime_type(exceptional_mime_type)
, _log(log) {}

ss::future<std::unique_ptr<ss::http::reply>> handle(
const ss::sstring&,
Expand Down Expand Up @@ -112,6 +116,16 @@ struct handler_adaptor : ss::httpd::handler_base {
co_return std::move(rp.rep);
}
auto sem_units = co_await ss::get_units(_ctx.mem_sem, req_size);

// Username is empty 'cos auth wrapper happens later :'()
auto access_log = ssx::sformat(
R"("{} {} {} {} HTTP/{}")",
rq.req->get_client_address().addr(),
rq.user.name,
rq.req->_method,
rq.req->_url,
rq.req->_version);

if (_ctx.as.abort_requested()) {
set_reply_unavailable(*rp.rep);
rp.mime_type = _exceptional_mime_type;
Expand All @@ -133,6 +147,13 @@ struct handler_adaptor : ss::httpd::handler_base {
rp = server::reply_t{exception_reply(ex), _exceptional_mime_type};
}
set_and_measure_response(rp);
vlog(
_log.trace,
"{} {} {}",
access_log,
static_cast<std::underlying_type_t<ss::http::reply::status_type>>(
rp.rep->_status),
rp.rep->_content.size());
co_return std::move(rp.rep);
}

Expand All @@ -141,6 +162,7 @@ struct handler_adaptor : ss::httpd::handler_base {
server::function_handler _handler;
probe _probe;
json::serialization_format _exceptional_mime_type;
ss::logger& _log;
};

server::server(
Expand All @@ -150,15 +172,17 @@ server::server(
const ss::sstring& header,
const ss::sstring& definitions,
context_t& ctx,
json::serialization_format exceptional_mime_type)
json::serialization_format exceptional_mime_type,
ss::logger& log)
: _server(server_name)
, _public_metrics_group_name(public_metrics_group_name)
, _pending_reqs()
, _api20(std::move(api20))
, _has_routes(false)
, _ctx(ctx)
, _exceptional_mime_type(exceptional_mime_type)
, _probe{} {
, _probe{}
, _log(log) {
_api20.set_api_doc(_server._routes);
_api20.register_api_file(_server._routes, header);
_api20.add_definitions_file(_server._routes, definitions);
Expand All @@ -177,7 +201,8 @@ void server::route(server::route_t r) {
std::move(r.handler),
r.path_desc,
_public_metrics_group_name,
_exceptional_mime_type);
_exceptional_mime_type,
_log);
r.path_desc.set(_server._routes, handler);
}

Expand Down
4 changes: 3 additions & 1 deletion src/v/pandaproxy/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class server {
const ss::sstring& header,
const ss::sstring& definitions,
context_t& ctx,
json::serialization_format exceptional_mime_type);
json::serialization_format exceptional_mime_type,
ss::logger& log);

void route(route_t route);
void routes(routes_t&& routes);
Expand All @@ -141,6 +142,7 @@ class server {
context_t& _ctx;
json::serialization_format _exceptional_mime_type;
std::unique_ptr<server_probe> _probe;
ss::logger& _log;
};

template<typename service_t>
Expand Down