Frédéric Lécaille | 6f7607e | 2022-05-25 22:25:37 +0200 | [diff] [blame] | 1 | #include <haproxy/h3.h> |
| 2 | #include <haproxy/stats.h> |
| 3 | |
| 4 | enum { |
| 5 | /* h3 frame type counters */ |
| 6 | H3_ST_DATA, |
| 7 | H3_ST_HEADERS, |
| 8 | H3_ST_CANCEL_PUSH, |
| 9 | H3_ST_PUSH_PROMISE, |
| 10 | H3_ST_MAX_PUSH_ID, |
| 11 | H3_ST_GOAWAY, |
| 12 | H3_ST_SETTINGS, |
| 13 | /* h3 error counters */ |
| 14 | H3_ST_H3_NO_ERROR, |
| 15 | H3_ST_H3_GENERAL_PROTOCOL_ERROR, |
| 16 | H3_ST_H3_INTERNAL_ERROR, |
| 17 | H3_ST_H3_STREAM_CREATION_ERROR, |
| 18 | H3_ST_H3_CLOSED_CRITICAL_STREAM, |
| 19 | H3_ST_H3_FRAME_UNEXPECTED, |
| 20 | H3_ST_H3_FRAME_ERROR, |
| 21 | H3_ST_H3_EXCESSIVE_LOAD, |
| 22 | H3_ST_H3_ID_ERROR, |
| 23 | H3_ST_H3_SETTINGS_ERROR, |
| 24 | H3_ST_H3_MISSING_SETTINGS, |
| 25 | H3_ST_H3_REQUEST_REJECTED, |
| 26 | H3_ST_H3_REQUEST_CANCELLED, |
| 27 | H3_ST_H3_REQUEST_INCOMPLETE, |
| 28 | H3_ST_H3_MESSAGE_ERROR, |
| 29 | H3_ST_H3_CONNECT_ERROR, |
| 30 | H3_ST_H3_VERSION_FALLBACK, |
| 31 | /* QPACK error counters */ |
| 32 | H3_ST_QPACK_DECOMPRESSION_FAILED, |
| 33 | H3_ST_QPACK_ENCODER_STREAM_ERROR, |
| 34 | H3_ST_QPACK_DECODER_STREAM_ERROR, |
| 35 | H3_STATS_COUNT /* must be the last */ |
| 36 | }; |
| 37 | |
| 38 | static struct name_desc h3_stats[] = { |
| 39 | /* h3 frame type counters */ |
| 40 | [H3_ST_DATA] = { .name = "h3_data", |
| 41 | .desc = "Total number of DATA frames received" }, |
| 42 | [H3_ST_HEADERS] = { .name = "h3_headers", |
| 43 | .desc = "Total number of HEADERS frames received" }, |
| 44 | [H3_ST_CANCEL_PUSH] = { .name = "h3_cancel_push", |
| 45 | .desc = "Total number of CANCEL_PUSH frames received" }, |
| 46 | [H3_ST_PUSH_PROMISE] = { .name = "h3_push_promise", |
| 47 | .desc = "Total number of PUSH_PROMISE frames received" }, |
| 48 | [H3_ST_MAX_PUSH_ID] = { .name = "h3_max_push_id", |
| 49 | .desc = "Total number of MAX_PUSH_ID frames received" }, |
| 50 | [H3_ST_GOAWAY] = { .name = "h3_goaway", |
| 51 | .desc = "Total number of GOAWAY frames received" }, |
| 52 | [H3_ST_SETTINGS] = { .name = "h3_settings", |
| 53 | .desc = "Total number of SETTINGS frames received" }, |
| 54 | /* h3 error counters */ |
| 55 | [H3_ST_H3_NO_ERROR] = { .name = "h3_no_error", |
| 56 | .desc = "Total number of H3_NO_ERROR errors received" }, |
| 57 | [H3_ST_H3_GENERAL_PROTOCOL_ERROR] = { .name = "h3_general_protocol_error", |
| 58 | .desc = "Total number of H3_GENERAL_PROTOCOL_ERROR errors received" }, |
| 59 | [H3_ST_H3_INTERNAL_ERROR] = { .name = "h3_internal_error", |
| 60 | .desc = "Total number of H3_INTERNAL_ERROR errors received" }, |
| 61 | [H3_ST_H3_STREAM_CREATION_ERROR] = { .name = "h3_stream_creation_error", |
| 62 | .desc = "Total number of H3_STREAM_CREATION_ERROR errors received" }, |
| 63 | [H3_ST_H3_CLOSED_CRITICAL_STREAM] = { .name = "h3_closed_critical_stream", |
| 64 | .desc = "Total number of H3_CLOSED_CRITICAL_STREAM errors received" }, |
| 65 | [H3_ST_H3_FRAME_UNEXPECTED] = { .name = "h3_frame_unexpected", |
| 66 | .desc = "Total number of H3_FRAME_UNEXPECTED errors received" }, |
| 67 | [H3_ST_H3_FRAME_ERROR] = { .name = "h3_frame_error", |
| 68 | .desc = "Total number of H3_FRAME_ERROR errors received" }, |
| 69 | [H3_ST_H3_EXCESSIVE_LOAD] = { .name = "h3_excessive_load", |
| 70 | .desc = "Total number of H3_EXCESSIVE_LOAD errors received" }, |
| 71 | [H3_ST_H3_ID_ERROR] = { .name = "h3_id_error", |
| 72 | .desc = "Total number of H3_ID_ERROR errors received" }, |
| 73 | [H3_ST_H3_SETTINGS_ERROR] = { .name = "h3_settings_error", |
| 74 | .desc = "Total number of H3_SETTINGS_ERROR errors received" }, |
| 75 | [H3_ST_H3_MISSING_SETTINGS] = { .name = "h3_missing_settings", |
| 76 | .desc = "Total number of H3_MISSING_SETTINGS errors received" }, |
| 77 | [H3_ST_H3_REQUEST_REJECTED] = { .name = "h3_request_rejected", |
| 78 | .desc = "Total number of H3_REQUEST_REJECTED errors received" }, |
| 79 | [H3_ST_H3_REQUEST_CANCELLED] = { .name = "h3_request_cancelled", |
| 80 | .desc = "Total number of H3_REQUEST_CANCELLED errors received" }, |
| 81 | [H3_ST_H3_REQUEST_INCOMPLETE] = { .name = "h3_request_incomplete", |
| 82 | .desc = "Total number of H3_REQUEST_INCOMPLETE errors received" }, |
| 83 | [H3_ST_H3_MESSAGE_ERROR] = { .name = "h3_message_error", |
| 84 | .desc = "Total number of H3_MESSAGE_ERROR errors received" }, |
| 85 | [H3_ST_H3_CONNECT_ERROR] = { .name = "h3_connect_error", |
| 86 | .desc = "Total number of H3_CONNECT_ERROR errors received" }, |
| 87 | [H3_ST_H3_VERSION_FALLBACK] = { .name = "h3_version_fallback", |
| 88 | .desc = "Total number of H3_VERSION_FALLBACK errors received" }, |
| 89 | /* QPACK error counters */ |
| 90 | [H3_ST_QPACK_DECOMPRESSION_FAILED] = { .name = "pack_decompression_failed", |
| 91 | .desc = "Total number of QPACK_DECOMPRESSION_FAILED errors received" }, |
| 92 | [H3_ST_QPACK_ENCODER_STREAM_ERROR] = { .name = "qpack_encoder_stream_error", |
| 93 | .desc = "Total number of QPACK_ENCODER_STREAM_ERROR errors received" }, |
| 94 | [H3_ST_QPACK_DECODER_STREAM_ERROR] = { .name = "qpack_decoder_stream_error", |
| 95 | .desc = "Total number of QPACK_DECODER_STREAM_ERROR errors received" }, |
| 96 | }; |
| 97 | |
| 98 | static struct h3_counters { |
| 99 | /* h3 frame type counters */ |
| 100 | long long h3_data; /* total number of DATA frames received */ |
| 101 | long long h3_headers; /* total number of HEADERS frames received */ |
| 102 | long long h3_cancel_push; /* total number of CANCEL_PUSH frames received */ |
| 103 | long long h3_push_promise; /* total number of PUSH_PROMISE frames received */ |
| 104 | long long h3_max_push_id; /* total number of MAX_PUSH_ID frames received */ |
| 105 | long long h3_goaway; /* total number of GOAWAY frames received */ |
| 106 | long long h3_settings; /* total number of SETTINGS frames received */ |
| 107 | /* h3 error counters */ |
| 108 | long long h3_no_error; /* total number of H3_NO_ERROR errors received */ |
| 109 | long long h3_general_protocol_error; /* total number of H3_GENERAL_PROTOCOL_ERROR errors received */ |
| 110 | long long h3_internal_error; /* total number of H3_INTERNAL_ERROR errors received */ |
| 111 | long long h3_stream_creation_error; /* total number of H3_STREAM_CREATION_ERROR errors received */ |
| 112 | long long h3_closed_critical_stream; /* total number of H3_CLOSED_CRITICAL_STREAM errors received */ |
| 113 | long long h3_frame_unexpected; /* total number of H3_FRAME_UNEXPECTED errors received */ |
| 114 | long long h3_frame_error; /* total number of H3_FRAME_ERROR errors received */ |
| 115 | long long h3_excessive_load; /* total number of H3_EXCESSIVE_LOAD errors received */ |
| 116 | long long h3_id_error; /* total number of H3_ID_ERROR errors received */ |
| 117 | long long h3_settings_error; /* total number of H3_SETTINGS_ERROR errors received */ |
| 118 | long long h3_missing_settings; /* total number of H3_MISSING_SETTINGS errors received */ |
| 119 | long long h3_request_rejected; /* total number of H3_REQUEST_REJECTED errors received */ |
| 120 | long long h3_request_cancelled; /* total number of H3_REQUEST_CANCELLED errors received */ |
| 121 | long long h3_request_incomplete; /* total number of H3_REQUEST_INCOMPLETE errors received */ |
| 122 | long long h3_message_error; /* total number of H3_MESSAGE_ERROR errors received */ |
| 123 | long long h3_connect_error; /* total number of H3_CONNECT_ERROR errors received */ |
| 124 | long long h3_version_fallback; /* total number of H3_VERSION_FALLBACK errors received */ |
| 125 | /* QPACK error counters */ |
| 126 | long long qpack_decompression_failed; /* total number of QPACK_DECOMPRESSION_FAILED errors received */ |
| 127 | long long qpack_encoder_stream_error; /* total number of QPACK_ENCODER_STREAM_ERROR errors received */ |
| 128 | long long qpack_decoder_stream_error; /* total number of QPACK_DECODER_STREAM_ERROR errors received */ |
| 129 | } h3_counters; |
| 130 | |
| 131 | static void h3_fill_stats(void *data, struct field *stats) |
| 132 | { |
| 133 | struct h3_counters *counters = data; |
| 134 | |
| 135 | /* h3 frame type counters */ |
| 136 | stats[H3_ST_DATA] = mkf_u64(FN_COUNTER, counters->h3_data); |
| 137 | stats[H3_ST_HEADERS] = mkf_u64(FN_COUNTER, counters->h3_headers); |
| 138 | stats[H3_ST_CANCEL_PUSH] = mkf_u64(FN_COUNTER, counters->h3_cancel_push); |
| 139 | stats[H3_ST_PUSH_PROMISE] = mkf_u64(FN_COUNTER, counters->h3_push_promise); |
| 140 | stats[H3_ST_MAX_PUSH_ID] = mkf_u64(FN_COUNTER, counters->h3_max_push_id); |
| 141 | stats[H3_ST_GOAWAY] = mkf_u64(FN_COUNTER, counters->h3_goaway); |
| 142 | stats[H3_ST_SETTINGS] = mkf_u64(FN_COUNTER, counters->h3_settings); |
| 143 | /* h3 error counters */ |
| 144 | stats[H3_ST_H3_NO_ERROR] = mkf_u64(FN_COUNTER, counters->h3_no_error); |
| 145 | stats[H3_ST_H3_GENERAL_PROTOCOL_ERROR] = mkf_u64(FN_COUNTER, counters->h3_general_protocol_error); |
| 146 | stats[H3_ST_H3_INTERNAL_ERROR] = mkf_u64(FN_COUNTER, counters->h3_internal_error); |
| 147 | stats[H3_ST_H3_STREAM_CREATION_ERROR] = mkf_u64(FN_COUNTER, counters->h3_stream_creation_error); |
| 148 | stats[H3_ST_H3_CLOSED_CRITICAL_STREAM] = mkf_u64(FN_COUNTER, counters->h3_closed_critical_stream); |
| 149 | stats[H3_ST_H3_FRAME_UNEXPECTED] = mkf_u64(FN_COUNTER, counters->h3_frame_unexpected); |
| 150 | stats[H3_ST_H3_FRAME_ERROR] = mkf_u64(FN_COUNTER, counters->h3_frame_error); |
| 151 | stats[H3_ST_H3_EXCESSIVE_LOAD] = mkf_u64(FN_COUNTER, counters->h3_excessive_load); |
| 152 | stats[H3_ST_H3_ID_ERROR] = mkf_u64(FN_COUNTER, counters->h3_id_error); |
| 153 | stats[H3_ST_H3_SETTINGS_ERROR] = mkf_u64(FN_COUNTER, counters->h3_settings_error); |
| 154 | stats[H3_ST_H3_MISSING_SETTINGS] = mkf_u64(FN_COUNTER, counters->h3_missing_settings); |
| 155 | stats[H3_ST_H3_REQUEST_REJECTED] = mkf_u64(FN_COUNTER, counters->h3_request_rejected); |
| 156 | stats[H3_ST_H3_REQUEST_CANCELLED] = mkf_u64(FN_COUNTER, counters->h3_request_cancelled); |
| 157 | stats[H3_ST_H3_REQUEST_INCOMPLETE] = mkf_u64(FN_COUNTER, counters->h3_request_incomplete); |
| 158 | stats[H3_ST_H3_MESSAGE_ERROR] = mkf_u64(FN_COUNTER, counters->h3_message_error); |
| 159 | stats[H3_ST_H3_CONNECT_ERROR] = mkf_u64(FN_COUNTER, counters->h3_connect_error); |
| 160 | stats[H3_ST_H3_VERSION_FALLBACK] = mkf_u64(FN_COUNTER, counters->h3_version_fallback); |
| 161 | /* QPACK error counters */ |
| 162 | stats[H3_ST_QPACK_DECOMPRESSION_FAILED] = mkf_u64(FN_COUNTER, counters->qpack_decompression_failed); |
| 163 | stats[H3_ST_QPACK_ENCODER_STREAM_ERROR] = mkf_u64(FN_COUNTER, counters->qpack_encoder_stream_error); |
| 164 | stats[H3_ST_QPACK_DECODER_STREAM_ERROR] = mkf_u64(FN_COUNTER, counters->qpack_decoder_stream_error); |
| 165 | } |
| 166 | |
| 167 | struct stats_module h3_stats_module = { |
| 168 | .name = "h3", |
| 169 | .fill_stats = h3_fill_stats, |
| 170 | .stats = h3_stats, |
| 171 | .stats_count = H3_STATS_COUNT, |
| 172 | .counters = &h3_counters, |
| 173 | .counters_size = sizeof(h3_counters), |
| 174 | .domain_flags = MK_STATS_PROXY_DOMAIN(STATS_PX_CAP_FE), |
| 175 | .clearable = 1, |
| 176 | }; |
| 177 | |
| 178 | INITCALL1(STG_REGISTER, stats_register_module, &h3_stats_module); |
| 179 | |
| 180 | void h3_inc_err_cnt(struct h3_counters *ctrs, int error_code) |
| 181 | { |
| 182 | switch (error_code) { |
| 183 | case H3_NO_ERROR: |
| 184 | HA_ATOMIC_INC(&ctrs->h3_no_error); |
| 185 | break; |
| 186 | case H3_GENERAL_PROTOCOL_ERROR: |
| 187 | HA_ATOMIC_INC(&ctrs->h3_general_protocol_error); |
| 188 | break; |
| 189 | case H3_INTERNAL_ERROR: |
| 190 | HA_ATOMIC_INC(&ctrs->h3_internal_error); |
| 191 | break; |
| 192 | case H3_STREAM_CREATION_ERROR: |
| 193 | HA_ATOMIC_INC(&ctrs->h3_stream_creation_error); |
| 194 | break; |
| 195 | case H3_CLOSED_CRITICAL_STREAM: |
| 196 | HA_ATOMIC_INC(&ctrs->h3_closed_critical_stream); |
| 197 | break; |
| 198 | case H3_FRAME_UNEXPECTED: |
| 199 | HA_ATOMIC_INC(&ctrs->h3_frame_unexpected); |
| 200 | break; |
| 201 | case H3_FRAME_ERROR: |
| 202 | HA_ATOMIC_INC(&ctrs->h3_frame_error); |
| 203 | break; |
| 204 | case H3_EXCESSIVE_LOAD: |
| 205 | HA_ATOMIC_INC(&ctrs->h3_excessive_load); |
| 206 | break; |
| 207 | case H3_ID_ERROR: |
| 208 | HA_ATOMIC_INC(&ctrs->h3_id_error); |
| 209 | break; |
| 210 | case H3_SETTINGS_ERROR: |
| 211 | HA_ATOMIC_INC(&ctrs->h3_settings_error); |
| 212 | break; |
| 213 | case H3_MISSING_SETTINGS: |
| 214 | HA_ATOMIC_INC(&ctrs->h3_missing_settings); |
| 215 | break; |
| 216 | case H3_REQUEST_REJECTED: |
| 217 | HA_ATOMIC_INC(&ctrs->h3_request_rejected); |
| 218 | break; |
| 219 | case H3_REQUEST_CANCELLED: |
| 220 | HA_ATOMIC_INC(&ctrs->h3_request_cancelled); |
| 221 | break; |
| 222 | case H3_REQUEST_INCOMPLETE: |
| 223 | HA_ATOMIC_INC(&ctrs->h3_request_incomplete); |
| 224 | break; |
| 225 | case H3_MESSAGE_ERROR: |
| 226 | HA_ATOMIC_INC(&ctrs->h3_message_error); |
| 227 | break; |
| 228 | case H3_CONNECT_ERROR: |
| 229 | HA_ATOMIC_INC(&ctrs->h3_connect_error); |
| 230 | break; |
| 231 | case H3_VERSION_FALLBACK: |
| 232 | HA_ATOMIC_INC(&ctrs->h3_version_fallback); |
| 233 | break; |
| 234 | case QPACK_DECOMPRESSION_FAILED: |
| 235 | HA_ATOMIC_INC(&ctrs->qpack_decompression_failed); |
| 236 | break; |
| 237 | case QPACK_ENCODER_STREAM_ERROR: |
| 238 | HA_ATOMIC_INC(&ctrs->qpack_encoder_stream_error); |
| 239 | break; |
| 240 | case QPACK_DECODER_STREAM_ERROR: |
| 241 | HA_ATOMIC_INC(&ctrs->qpack_decoder_stream_error); |
| 242 | break; |
| 243 | default: |
| 244 | break; |
| 245 | |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void h3_inc_frame_type_cnt(struct h3_counters *ctrs, int frm_type) |
| 250 | { |
| 251 | switch (frm_type) { |
| 252 | case H3_FT_DATA: |
| 253 | HA_ATOMIC_INC(&ctrs->h3_data); |
| 254 | break; |
| 255 | case H3_FT_HEADERS: |
| 256 | HA_ATOMIC_INC(&ctrs->h3_headers); |
| 257 | break; |
| 258 | case H3_FT_CANCEL_PUSH: |
| 259 | HA_ATOMIC_INC(&ctrs->h3_cancel_push); |
| 260 | break; |
| 261 | case H3_FT_PUSH_PROMISE: |
| 262 | HA_ATOMIC_INC(&ctrs->h3_push_promise); |
| 263 | break; |
| 264 | case H3_FT_MAX_PUSH_ID: |
| 265 | HA_ATOMIC_INC(&ctrs->h3_max_push_id); |
| 266 | break; |
| 267 | case H3_FT_GOAWAY: |
| 268 | HA_ATOMIC_INC(&ctrs->h3_goaway); |
| 269 | break; |
| 270 | case H3_FT_SETTINGS: |
| 271 | HA_ATOMIC_INC(&ctrs->h3_settings); |
| 272 | break; |
| 273 | default: |
| 274 | break; |
| 275 | } |
| 276 | } |