Skip to content

Commit 0075d03

Browse files
Merge pull request #24564 from IoannisRP/ik-pandaproxy-refactor
pandaproxy: add missing internal metrics
2 parents ac58586 + 939face commit 0075d03

File tree

2 files changed

+96
-70
lines changed

2 files changed

+96
-70
lines changed

src/v/pandaproxy/probe.cc

Lines changed: 96 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <seastar/core/metrics.hh>
1818
#include <seastar/core/metrics_registration.hh>
19+
#include <seastar/util/bool_class.hh>
1920

2021
namespace pandaproxy {
2122

@@ -26,82 +27,108 @@ probe::probe(
2627
, _group_name(group_name)
2728
, _metrics() {
2829
setup_metrics();
29-
setup_public_metrics();
3030
}
3131

3232
void probe::setup_metrics() {
3333
namespace sm = ss::metrics;
3434

35-
if (config::shard_local_cfg().disable_metrics()) {
36-
return;
35+
using is_internal = ss::bool_class<struct is_internal_tag>;
36+
37+
struct Labels {
38+
sm::label_instance label;
39+
std::vector<sm::label> agg;
40+
sm::label status;
41+
};
42+
const auto make_labels = [this](const is_internal internal) -> Labels {
43+
const auto make_label =
44+
[](const ss::sstring& key, const is_internal internal) {
45+
return internal ? sm::label(key)
46+
: metrics::make_namespaced_label(key);
47+
};
48+
const auto operation_label = make_label("operation", internal);
49+
const auto agg = internal ? std::vector<sm::label>{sm::shard_label}
50+
: std::vector<sm::label>{
51+
sm::shard_label, operation_label};
52+
const auto status = make_label("status", internal);
53+
return {
54+
.label = operation_label(_path.operations.nickname),
55+
.agg = agg,
56+
.status = status};
57+
};
58+
59+
const auto internal_labels = make_labels(is_internal::yes);
60+
const auto public_labels = make_labels(is_internal::no);
61+
62+
const auto make_internal_request_latency = [this](const Labels& l) {
63+
return sm::make_histogram(
64+
"request_latency",
65+
sm::description("Request latency"),
66+
{l.label},
67+
[this] {
68+
return _request_metrics.hist().internal_histogram_logform();
69+
});
70+
};
71+
72+
const auto make_public_request_latency = [this](const Labels& l) {
73+
return sm::make_histogram(
74+
"request_latency_seconds",
75+
sm::description(
76+
ssx::sformat("Internal latency of request for {}", _group_name)),
77+
{l.label},
78+
[this] {
79+
return _request_metrics.hist().public_histogram_logform();
80+
});
81+
};
82+
83+
const auto make_request_errors_total_5xx = [this](const Labels& l) {
84+
return sm::make_counter(
85+
"request_errors_total",
86+
[this] { return _request_metrics._5xx_count; },
87+
sm::description(
88+
ssx::sformat("Total number of {} server errors", _group_name)),
89+
{l.label, l.status("5xx")});
90+
};
91+
92+
const auto make_request_errors_total_4xx = [this](const Labels& l) {
93+
return sm::make_counter(
94+
"request_errors_total",
95+
[this] { return _request_metrics._4xx_count; },
96+
sm::description(
97+
ssx::sformat("Total number of {} client errors", _group_name)),
98+
{l.label, l.status("4xx")});
99+
};
100+
101+
const auto make_request_errors_total_3xx = [this](const Labels& l) {
102+
return sm::make_counter(
103+
"request_errors_total",
104+
[this] { return _request_metrics._3xx_count; },
105+
sm::description(
106+
ssx::sformat("Total number of {} redirection errors", _group_name)),
107+
{l.label, l.status("3xx")});
108+
};
109+
110+
if (!config::shard_local_cfg().disable_metrics()) {
111+
_metrics.add_group(
112+
"pandaproxy",
113+
{make_internal_request_latency(internal_labels),
114+
make_request_errors_total_5xx(internal_labels),
115+
make_request_errors_total_4xx(internal_labels),
116+
make_request_errors_total_3xx(internal_labels)},
117+
{},
118+
internal_labels.agg);
37119
}
38-
39-
auto operation_label = sm::label("operation");
40-
std::vector<sm::label_instance> labels{
41-
operation_label(_path.operations.nickname)};
42-
43-
_metrics.add_group(
44-
"pandaproxy",
45-
{sm::make_histogram(
46-
"request_latency",
47-
sm::description("Request latency"),
48-
labels,
49-
[this] {
50-
return _request_metrics.hist().internal_histogram_logform();
51-
})},
52-
{},
53-
{sm::shard_label});
54-
}
55-
56-
void probe::setup_public_metrics() {
57-
namespace sm = ss::metrics;
58-
59-
if (config::shard_local_cfg().disable_public_metrics()) {
60-
return;
120+
if (!config::shard_local_cfg().disable_public_metrics()) {
121+
_public_metrics.add_group(
122+
_group_name,
123+
{make_public_request_latency(public_labels)
124+
.aggregate(public_labels.agg),
125+
make_request_errors_total_5xx(public_labels)
126+
.aggregate(public_labels.agg),
127+
make_request_errors_total_4xx(public_labels)
128+
.aggregate(public_labels.agg),
129+
make_request_errors_total_3xx(public_labels)
130+
.aggregate(public_labels.agg)});
61131
}
62-
63-
auto operation_label = metrics::make_namespaced_label("operation");
64-
auto status_label = metrics::make_namespaced_label("status");
65-
66-
std::vector<sm::label_instance> labels{
67-
operation_label(_path.operations.nickname)};
68-
69-
auto aggregate_labels = std::vector<sm::label>{
70-
sm::shard_label, operation_label};
71-
72-
_public_metrics.add_group(
73-
_group_name,
74-
{sm::make_histogram(
75-
"request_latency_seconds",
76-
sm::description(
77-
ssx::sformat("Internal latency of request for {}", _group_name)),
78-
labels,
79-
[this] { return _request_metrics.hist().public_histogram_logform(); })
80-
.aggregate(aggregate_labels),
81-
82-
sm::make_counter(
83-
"request_errors_total",
84-
[this] { return _request_metrics._5xx_count; },
85-
sm::description(
86-
ssx::sformat("Total number of {} server errors", _group_name)),
87-
{operation_label(_path.operations.nickname), status_label("5xx")})
88-
.aggregate(aggregate_labels),
89-
90-
sm::make_counter(
91-
"request_errors_total",
92-
[this] { return _request_metrics._4xx_count; },
93-
sm::description(
94-
ssx::sformat("Total number of {} client errors", _group_name)),
95-
{operation_label(_path.operations.nickname), status_label("4xx")})
96-
.aggregate(aggregate_labels),
97-
98-
sm::make_counter(
99-
"request_errors_total",
100-
[this] { return _request_metrics._3xx_count; },
101-
sm::description(
102-
ssx::sformat("Total number of {} redirection errors", _group_name)),
103-
{operation_label(_path.operations.nickname), status_label("3xx")})
104-
.aggregate(aggregate_labels)});
105132
}
106133

107134
} // namespace pandaproxy

src/v/pandaproxy/probe.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class probe {
7272

7373
private:
7474
void setup_metrics();
75-
void setup_public_metrics();
7675

7776
private:
7877
http_status_metric _request_metrics;

0 commit comments

Comments
 (0)