1
0
mirror of http://git.haproxy.org/git/haproxy.git/ synced 2025-04-04 15:19:52 +00:00

MINOR: counters: Review conditions to increment counters from analysers

Now, for these counters, the following rules are followed to know if it must be
incremented or not:

  * if it exists for a frontend, the counter is incremented
  * if stats must be collected for the session's listener, if the counter exists
    for this listener, it is incremented
  * if the backend is already assigned, if the counter exists for this backend,
    it is incremented
  * if a server is attached to the stream, if the counter exists for this
    server, it is incremented

It is not hardcoded rules. Some counters are still handled in a different
way. But many counters are incremented this way now.
This commit is contained in:
Christopher Faulet 2019-12-16 16:13:44 +01:00
parent a08546bb5a
commit cff0f739e5
4 changed files with 74 additions and 14 deletions

View File

@ -474,10 +474,11 @@ static int fcgi_flt_http_headers(struct stream *s, struct filter *filter, struct
rewrite_err:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
if (sess->fe != s->be)
_HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
hdr_rule_err:
node = ebpt_first(&hdr_rules);
while (node) {

View File

@ -650,7 +650,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
req->analyse_exp = tick_add(now_ms, 0);
stream_inc_http_err_ctr(s);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
if (sess->fe != s->be)
if (s->flags & SF_BE_ASSIGNED)
_HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
@ -668,7 +668,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
s->logs.tv_request = now;
stream_inc_http_err_ctr(s);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
if (sess->fe != s->be)
if (s->flags & SF_BE_ASSIGNED)
_HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
@ -679,6 +679,8 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_INTERNAL;
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
if (s->flags & SF_BE_ASSIGNED)
_HA_ATOMIC_ADD(&s->be->be_counters.internal_errors, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->internal_errors, 1);
goto return_prx_err;
@ -941,6 +943,8 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_INTERNAL;
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
if (s->flags & SF_BE_ASSIGNED)
_HA_ATOMIC_ADD(&sess->fe->be_counters.internal_errors, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->internal_errors, 1);
goto return_prx_cond;
@ -1101,6 +1105,8 @@ int http_wait_for_request_body(struct stream *s, struct channel *req, int an_bit
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_INTERNAL;
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
if (s->flags & SF_BE_ASSIGNED)
_HA_ATOMIC_ADD(&sess->fe->be_counters.internal_errors, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->internal_errors, 1);
goto return_prx_cond;
@ -1338,8 +1344,10 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit)
return_cli_abort:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.cli_aborts, 1);
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_CLICL;
status = 400;
@ -1348,8 +1356,10 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit)
return_srv_abort:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.srv_aborts, 1);
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_SRVCL;
status = 502;
@ -1359,8 +1369,11 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit)
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_INTERNAL;
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.internal_errors, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->internal_errors, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.internal_errors, 1);
status = 500;
goto return_prx_cond;
@ -1573,6 +1586,8 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
else if ((rep->flags & CF_SHUTR) && ((s->req.flags & (CF_SHUTR|CF_SHUTW)) == (CF_SHUTR|CF_SHUTW))) {
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.cli_aborts, 1);
@ -1631,6 +1646,8 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
goto abort_keep_alive;
_HA_ATOMIC_ADD(&s->be->be_counters.failed_resp, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_resp, 1);
rep->analysers &= AN_RES_FLT_END;
if (!(s->flags & SF_ERR_MASK))
@ -1827,7 +1844,10 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
return 1;
return_int_err:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.internal_errors, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->internal_errors, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.internal_errors, 1);
txn->status = 500;
@ -2136,7 +2156,10 @@ int http_process_res_common(struct stream *s, struct channel *rep, int an_bit, s
txn->status = 500;
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_INTERNAL;
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.internal_errors, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.internal_errors, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.internal_errors, 1);
goto return_prx_err;
@ -2381,8 +2404,10 @@ int http_response_forward_body(struct stream *s, struct channel *res, int an_bit
return_srv_abort:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.srv_aborts, 1);
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_SRVCL;
goto return_error;
@ -2390,14 +2415,19 @@ int http_response_forward_body(struct stream *s, struct channel *res, int an_bit
return_cli_abort:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.cli_aborts, 1);
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_CLICL;
goto return_error;
return_int_err:
_HA_ATOMIC_ADD(&sess->fe->fe_counters.internal_errors, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.internal_errors, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->internal_errors, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.internal_errors, 1);
if (!(s->flags & SF_ERR_MASK))
@ -2407,7 +2437,7 @@ int http_response_forward_body(struct stream *s, struct channel *res, int an_bit
return_bad_res:
_HA_ATOMIC_ADD(&s->be->be_counters.failed_resp, 1);
if (objt_server(s->target)) {
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.failed_resp, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_resp, 1);
health_adjust(__objt_server(s->target), HANA_STATUS_HTTP_RSP);
}
if (!(s->flags & SF_ERR_MASK))
@ -3032,7 +3062,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
}
_HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
if (sess->fe != s->be)
if (s->flags & SF_BE_ASSIGNED)
_HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
@ -3391,12 +3421,11 @@ resume_execution:
}
_HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_rewrites, 1);
if (sess->fe != s->be)
_HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.failed_rewrites, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
}
free_trash_chunk(replace);
break;
@ -5000,9 +5029,12 @@ static void http_end_response(struct stream *s)
}
else if (chn->flags & CF_SHUTW) {
txn->rsp.msg_state = HTTP_MSG_ERROR;
_HA_ATOMIC_ADD(&strm_sess(s)->fe->fe_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
if (strm_sess(s)->listener->counters)
_HA_ATOMIC_ADD(&strm_sess(s)->listener->counters->cli_aborts, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&objt_server(s->target)->counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.cli_aborts, 1);
goto end;
}
DBG_TRACE_LEAVE(STRM_EV_HTTP_ANA, s, txn);

View File

@ -1616,6 +1616,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
if (!(req->analysers) && !(res->analysers)) {
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.cli_aborts, 1);
if (!(s->flags & SF_ERR_MASK))
@ -1637,6 +1639,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
if (!(req->analysers) && !(res->analysers)) {
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.srv_aborts, 1);
if (!(s->flags & SF_ERR_MASK))
@ -1890,6 +1894,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
if (req->flags & CF_READ_ERROR) {
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.cli_aborts, 1);
s->flags |= SF_ERR_CLICL;
@ -1897,6 +1903,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
else if (req->flags & CF_READ_TIMEOUT) {
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.cli_aborts, 1);
s->flags |= SF_ERR_CLITO;
@ -1904,6 +1912,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
else if (req->flags & CF_WRITE_ERROR) {
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.srv_aborts, 1);
s->flags |= SF_ERR_SRVCL;
@ -1911,6 +1921,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
else {
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.srv_aborts, 1);
s->flags |= SF_ERR_SRVTO;
@ -1936,6 +1948,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
if (res->flags & CF_READ_ERROR) {
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.srv_aborts, 1);
s->flags |= SF_ERR_SRVCL;
@ -1943,6 +1957,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
else if (res->flags & CF_READ_TIMEOUT) {
_HA_ATOMIC_ADD(&s->be->be_counters.srv_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.srv_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->srv_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.srv_aborts, 1);
s->flags |= SF_ERR_SRVTO;
@ -1950,6 +1966,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
else if (res->flags & CF_WRITE_ERROR) {
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.cli_aborts, 1);
s->flags |= SF_ERR_CLICL;
@ -1957,6 +1975,8 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
else {
_HA_ATOMIC_ADD(&s->be->be_counters.cli_aborts, 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.cli_aborts, 1);
if (sess->listener->counters)
_HA_ATOMIC_ADD(&sess->listener->counters->cli_aborts, 1);
if (srv)
_HA_ATOMIC_ADD(&srv->counters.cli_aborts, 1);
s->flags |= SF_ERR_CLITO;
@ -2374,6 +2394,7 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
if (sess->fe->mode == PR_MODE_HTTP) {
_HA_ATOMIC_ADD(&sess->fe->fe_counters.p.http.rsp[n], 1);
_HA_ATOMIC_ADD(&sess->fe->fe_counters.p.http.cum_req, 1);
}
if ((s->flags & SF_BE_ASSIGNED) &&
(s->be->mode == PR_MODE_HTTP)) {

View File

@ -412,13 +412,19 @@ resume_execution:
return 1;
deny:
_HA_ATOMIC_ADD(&s->sess->fe->fe_counters.denied_resp, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.denied_resp, 1);
if (s->sess->listener->counters)
_HA_ATOMIC_ADD(&s->sess->listener->counters->denied_resp, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.denied_resp, 1);
goto reject;
internal:
_HA_ATOMIC_ADD(&s->sess->fe->fe_counters.internal_errors, 1);
_HA_ATOMIC_ADD(&s->be->be_counters.internal_errors, 1);
if (s->sess->listener->counters)
_HA_ATOMIC_ADD(&s->sess->listener->counters->internal_errors, 1);
if (objt_server(s->target))
_HA_ATOMIC_ADD(&__objt_server(s->target)->counters.internal_errors, 1);
if (!(s->flags & SF_ERR_MASK))