Skip to content

Commit ef4303a

Browse files
authored
Merge pull request #3157 from rabbitmq/stream-protocol-counters
Add specific stream protocol counters to track protocol errors
2 parents f1f7334 + b636ad2 commit ef4303a

File tree

9 files changed

+206
-13
lines changed

9 files changed

+206
-13
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-define(NUM_PROTOCOL_COUNTERS, 8).
2+
-define(NUM_PROTOCOL_QUEUE_TYPE, 8).

deps/rabbit/src/rabbit_global_counters.erl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
-export([
1111
boot_step/0,
1212
init/1,
13+
init/2,
1314
overview/0,
1415
prometheus_format/0,
16+
increase_protocol_counter/3,
1517
messages_received/2,
1618
messages_received_confirm/2,
1719
messages_routed/2,
@@ -41,6 +43,7 @@
4143
-define(MESSAGES_CONFIRMED, 6).
4244
-define(PUBLISHERS, 7).
4345
-define(CONSUMERS, 8).
46+
%% Note: ?NUM_PROTOCOL_COUNTERS needs to be up-to-date. See include/rabbit_global_counters.hrl
4447
-define(PROTOCOL_COUNTERS,
4548
[
4649
{
@@ -86,6 +89,7 @@
8689
-define(MESSAGES_GET_EMPTY, 6).
8790
-define(MESSAGES_REDELIVERED, 7).
8891
-define(MESSAGES_ACKNOWLEDGED, 8).
92+
%% Note: ?NUM_PROTOCOL_QUEUE_TYPE_COUNTERS needs to be up-to-date. See include/rabbit_global_counters.hrl
8993
-define(PROTOCOL_QUEUE_TYPE_COUNTERS,
9094
[
9195
{
@@ -128,14 +132,17 @@ boot_step() ->
128132
init([{protocol, amqp091}, {queue_type, rabbit_quorum_queue}]),
129133
init([{protocol, amqp091}, {queue_type, rabbit_stream_queue}]).
130134

131-
init(Labels = [{protocol, Protocol}, {queue_type, QueueType}]) ->
135+
init(Labels) ->
136+
init(Labels, []).
137+
138+
init(Labels = [{protocol, Protocol}, {queue_type, QueueType}], Extra) ->
132139
_ = seshat_counters:new_group(?MODULE),
133-
Counters = seshat_counters:new(?MODULE, Labels, ?PROTOCOL_QUEUE_TYPE_COUNTERS),
140+
Counters = seshat_counters:new(?MODULE, Labels, ?PROTOCOL_QUEUE_TYPE_COUNTERS ++ Extra),
134141
persistent_term:put({?MODULE, Protocol, QueueType}, Counters),
135142
ok;
136-
init(Labels = [{protocol, Protocol}]) ->
143+
init(Labels = [{protocol, Protocol}], Extra) ->
137144
_ = seshat_counters:new_group(?MODULE),
138-
Counters = seshat_counters:new(?MODULE, Labels, ?PROTOCOL_COUNTERS),
145+
Counters = seshat_counters:new(?MODULE, Labels, ?PROTOCOL_COUNTERS ++ Extra),
139146
persistent_term:put({?MODULE, Protocol}, Counters),
140147
ok.
141148

@@ -145,6 +152,9 @@ overview() ->
145152
prometheus_format() ->
146153
seshat_counters:prometheus_format(?MODULE).
147154

155+
increase_protocol_counter(Protocol, Counter, Num) ->
156+
counters:add(fetch(Protocol), Counter, Num).
157+
148158
messages_received(Protocol, Num) ->
149159
counters:add(fetch(Protocol), ?MESSAGES_RECEIVED, Num).
150160

deps/rabbitmq_prometheus/metrics.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ To generate these:
6767
| rabbitmq_global_publishers | Publishers currently connected |
6868
| rabbitmq_global_consumers | Consumers currently connected |
6969

70+
#### Stream global counters
71+
72+
These metrics are specific to the stream protocol.
73+
74+
| Metric | Description |
75+
| --- | --- |
76+
| stream_error_stream_does_not_exist_total | Total number of commands rejected with stream does not exist error |
77+
| stream_error_subscription_id_already_exists_total | Total number of commands failed with subscription id already exists |
78+
| stream_error_subscription_id_does_not_exist_total | Total number of commands failed with subscription id does not exist |
79+
| stream_error_stream_already_exists_total | Total number of commands failed with stream already exists |
80+
| stream_error_stream_not_available_total | Total number of commands failed with stream not available |
81+
| stream_error_sasl_mechanism_not_supported_total | Total number of commands failed with sasl mechanism not supported |
82+
| stream_error_authentication_failure_total | Total number of commands failed with authentication failure |
83+
| stream_error_sasl_error_total | Total number of commands failed with sasl error |
84+
| stream_error_sasl_challenge_total | Total number of commands failed with sasl challenge |
85+
| stream_error_sasl_authentication_failure_loopback_total | Total number of commands failed with sasl authentication failure loopback |
86+
| stream_error_vhost_access_failure_total | Total number of commands failed with vhost access failure |
87+
| stream_error_unknown_frame_total | Total number of commands failed with unknown frame |
88+
| stream_error_frame_too_large_total | Total number of commands failed with frame too large |
89+
| stream_error_internal_error_total | Total number of commands failed with internal error |
90+
| stream_error_access_refused_total | Total number of commands failed with access refused |
91+
| stream_error_precondition_failed_total | Total number of commands failed with precondition failed |
92+
| stream_error_publisher_does_not_exist_total | Total number of commands failed with publisher does not exist |
93+
94+
7095
### Generic
7196

7297
| Metric | Description |

deps/rabbitmq_stream/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ BUILD_DEPS = [
4141

4242
DEPS = [
4343
"//deps/rabbitmq_stream_common:bazel_erlang_lib",
44-
]
45-
46-
RUNTIME_DEPS = [
4744
"//deps/rabbit:bazel_erlang_lib",
4845
]
4946

@@ -53,7 +50,6 @@ rabbitmq_lib(
5350
app_module = APP_MODULE,
5451
app_name = APP_NAME,
5552
build_deps = BUILD_DEPS,
56-
runtime_deps = RUNTIME_DEPS,
5753
deps = DEPS,
5854
)
5955

@@ -105,6 +101,7 @@ rabbitmq_integration_suite(
105101
},
106102
},
107103
deps = [
104+
"//deps/rabbit:bazel_erlang_lib",
108105
"//deps/rabbitmq_stream_common:bazel_erlang_lib",
109106
],
110107
)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,94 @@
1+
-include_lib("rabbit/include/rabbit_global_counters.hrl").
2+
13
-define(TABLE_CONSUMER, rabbit_stream_consumer_created).
24
-define(TABLE_PUBLISHER, rabbit_stream_publisher_created).
5+
6+
-define(STREAM_DOES_NOT_EXIST, ?NUM_PROTOCOL_COUNTERS + 1).
7+
-define(SUBSCRIPTION_ID_ALREADY_EXISTS, ?NUM_PROTOCOL_COUNTERS + 2).
8+
-define(SUBSCRIPTION_ID_DOES_NOT_EXIST, ?NUM_PROTOCOL_COUNTERS + 3).
9+
-define(STREAM_ALREADY_EXISTS, ?NUM_PROTOCOL_COUNTERS + 4).
10+
-define(STREAM_NOT_AVAILABLE, ?NUM_PROTOCOL_COUNTERS + 5).
11+
-define(SASL_MECHANISM_NOT_SUPPORTED, ?NUM_PROTOCOL_COUNTERS + 6).
12+
-define(AUTHENTICATION_FAILURE, ?NUM_PROTOCOL_COUNTERS + 7).
13+
-define(SASL_ERROR, ?NUM_PROTOCOL_COUNTERS + 8).
14+
-define(SASL_CHALLENGE, ?NUM_PROTOCOL_COUNTERS + 9).
15+
-define(SASL_AUTHENTICATION_FAILURE_LOOPBACK, ?NUM_PROTOCOL_COUNTERS + 10).
16+
-define(VHOST_ACCESS_FAILURE, ?NUM_PROTOCOL_COUNTERS + 11).
17+
-define(UNKNOWN_FRAME, ?NUM_PROTOCOL_COUNTERS + 12).
18+
-define(FRAME_TOO_LARGE, ?NUM_PROTOCOL_COUNTERS + 13).
19+
-define(INTERNAL_ERROR, ?NUM_PROTOCOL_COUNTERS + 14).
20+
-define(ACCESS_REFUSED, ?NUM_PROTOCOL_COUNTERS + 15).
21+
-define(PRECONDITION_FAILED, ?NUM_PROTOCOL_COUNTERS + 16).
22+
-define(PUBLISHER_DOES_NOT_EXIST, ?NUM_PROTOCOL_COUNTERS + 17).
23+
24+
-define(PROTOCOL_COUNTERS,
25+
[
26+
{
27+
stream_error_stream_does_not_exist_total, ?STREAM_DOES_NOT_EXIST, counter,
28+
"Total number of commands rejected with stream does not exist error"
29+
},
30+
{
31+
stream_error_subscription_id_already_exists_total, ?SUBSCRIPTION_ID_ALREADY_EXISTS, counter,
32+
"Total number of commands failed with subscription id already exists"
33+
},
34+
{
35+
stream_error_subscription_id_does_not_exist_total, ?SUBSCRIPTION_ID_DOES_NOT_EXIST, counter,
36+
"Total number of commands failed with subscription id does not exist"
37+
},
38+
{
39+
stream_error_stream_already_exists_total, ?STREAM_ALREADY_EXISTS, counter,
40+
"Total number of commands failed with stream already exists"
41+
},
42+
{
43+
stream_error_stream_not_available_total, ?STREAM_NOT_AVAILABLE, counter,
44+
"Total number of commands failed with stream not available"
45+
},
46+
{
47+
stream_error_sasl_mechanism_not_supported_total, ?SASL_MECHANISM_NOT_SUPPORTED, counter,
48+
"Total number of commands failed with sasl mechanism not supported"
49+
},
50+
{
51+
stream_error_authentication_failure_total, ?AUTHENTICATION_FAILURE, counter,
52+
"Total number of commands failed with authentication failure"
53+
},
54+
{
55+
stream_error_sasl_error_total, ?SASL_ERROR, counter,
56+
"Total number of commands failed with sasl error"
57+
},
58+
{
59+
stream_error_sasl_challenge_total, ?SASL_CHALLENGE, counter,
60+
"Total number of commands failed with sasl challenge"
61+
},
62+
{
63+
stream_error_sasl_authentication_failure_loopback_total, ?SASL_AUTHENTICATION_FAILURE_LOOPBACK, counter,
64+
"Total number of commands failed with sasl authentication failure loopback"
65+
},
66+
{
67+
stream_error_vhost_access_failure_total, ?VHOST_ACCESS_FAILURE, counter,
68+
"Total number of commands failed with vhost access failure"
69+
},
70+
{
71+
stream_error_unknown_frame_total, ?UNKNOWN_FRAME, counter,
72+
"Total number of commands failed with unknown frame"
73+
},
74+
{
75+
stream_error_frame_too_large_total, ?FRAME_TOO_LARGE, counter,
76+
"Total number of commands failed with frame too large"
77+
},
78+
{
79+
stream_error_internal_error_total, ?INTERNAL_ERROR, counter,
80+
"Total number of commands failed with internal error"
81+
},
82+
{
83+
stream_error_access_refused_total, ?ACCESS_REFUSED, counter,
84+
"Total number of commands failed with access refused"
85+
},
86+
{
87+
stream_error_precondition_failed_total, ?PRECONDITION_FAILED, counter,
88+
"Total number of commands failed with precondition failed"
89+
},
90+
{
91+
stream_error_publisher_does_not_exist_total, ?PUBLISHER_DOES_NOT_EXIST, counter,
92+
"Total number of commands failed with publisher does not exist"
93+
}
94+
]).

deps/rabbitmq_stream/src/rabbit_stream.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434

3535
-include_lib("rabbit_common/include/rabbit.hrl").
3636
-include_lib("rabbitmq_stream_common/include/rabbit_stream.hrl").
37+
-include("rabbit_stream_metrics.hrl").
3738

3839
start(_Type, _Args) ->
3940
rabbit_stream_metrics:init(),
40-
rabbit_global_counters:init([{protocol, stream}]),
41+
rabbit_global_counters:init([{protocol, stream}], ?PROTOCOL_COUNTERS),
4142
rabbit_global_counters:init([{protocol, stream}, {queue_type, ?STREAM_QUEUE_TYPE}]),
4243
rabbit_stream_sup:start_link().
4344

0 commit comments

Comments
 (0)