artprima / prometheus-metrics-bundle

Symfony 5/6 Prometheus Metrics Bundle
MIT License
127 stars 29 forks source link

HTTP requests total count #77

Closed b2p-fred closed 2 years ago

b2p-fred commented 2 years ago

Starting from an empty metrics storage, and after only one request to GET /api/about, I got those metrics (removed Prometheus stuff for readability...) :

epr_http_2xx_responses_total{action="GET-api_about"} 1
epr_http_2xx_responses_total{action="all"} 1

epr_http_requests_total{action="GET-api_about"} 2
epr_http_requests_total{action="all"} 2

epr_http_responses_total{action="GET-api_about"} 1
epr_http_responses_total{action="all"} 1

Ok, so the total requests count is 2 whereas I only had one request. Something I missed somewhere ?

b2p-fred commented 2 years ago

Some more information that may help...

On a second GET /api/about I got those

epr_http_2xx_responses_total{action="GET-api_about"} 2
epr_http_2xx_responses_total{action="all"} 2

epr_http_requests_total{action="GET-api_about"} 4
epr_http_requests_total{action="all"} 4

epr_http_responses_total{action="GET-api_about"} 2
epr_http_responses_total{action="all"} 2

A total of 4 ... and then 6 for 3, 8 for 4

And then I tried on another endpoint and I got this:


epr_http_2xx_responses_total{action="GET-api_about"} 4
epr_http_2xx_responses_total{action="GET-api_addresses_get_collection"} 1
epr_http_2xx_responses_total{action="all"} 6

epr_http_requests_total{action="GET-api_about"} 8
epr_http_requests_total{action="GET-api_addresses_get_collection"} 2
epr_http_requests_total{action="all"} 10

epr_http_responses_total{action="GET-api_about"} 4
epr_http_responses_total{action="GET-api_addresses_get_collection"} 1
epr_http_responses_total{action="all"} 6

Still x2 for the http_requests_total, but note the 4 + 1 = 6 :wink:

denisvmedia commented 2 years ago

That could be a race condition issue, when the first values were read before the total was written. However, if you think, it's a bug, feel free to submit a PR with a fix.

b2p-fred commented 2 years ago

Hmmm. I do not think about a race condition because it is a systematic behaviour. Each unique request

Another example:

epr_http_3xx_responses_total{action="GET-api_me"} 1 epr_http_3xx_responses_total{action="all"} 1

epr_http_requests_total{action="GET-api_doc"} 2 epr_http_requests_total{action="GET-api_me"} 2 epr_http_requests_total{action="GET-api_users_get_item"} 2 epr_http_requests_total{action="all"} 6

epr_http_responses_total{action="GET-api_doc"} 1 epr_http_responses_total{action="GET-api_me"} 1 epr_http_responses_total{action="GET-api_users_get_item"} 1 epr_http_responses_total{action="all"} 3



and note that every unique request is counted twice in the requests_total.

All the tests always show this twice count in the total ... I will investigate about this in all my source code
b2p-fred commented 2 years ago

My bad ... and sorry for this issue. I was making those tests on a branch where I tried to add your example for a metrics collector ... and It increments the total count :)

Once again, sorry...