AlinsRan opened a new pull request, #14101: URL: https://github.com/apache/apisix/pull/14101
### Description Since #13992, stream metrics zone slots are created on demand, per `(listen_addr, service, service_id)`, by the first session that carries those labels. `publish_stream_bytes` only takes a baseline the first time it sees a slot and does not count it. So the bytes of every session that ends before a new service's slot is first read are absorbed into that baseline and never reach `apisix_stream_bandwidth`. A short-lived session on a new service is not counted at all, and the per `listen_addr` total, summed over services, comes out lower than the bytes actually proxied. This PR records in the metrics dict that the zone has been read at least once: - once the marker exists, a slot without a baseline is new, so it is counted from zero (its full total); - only the first read after start, or after that dict is flushed, takes baselines without counting, as before. The marker lives in the same dict as the baselines and the counters, so a flush drops all three together. Trade-off: a slot whose baseline is evicted from a full dict cannot be told apart from a new slot, so it replays its total once. TEST 9 used to assert the opposite (rebaseline on a lost baseline) and now pins this behavior. Tests: TEST 2 of `t/stream-plugin/prometheus-metrics-service.t` now expects the first session of a new service to be counted (`5` bytes instead of `no-series`). TEST 2 and TEST 9 fail without the change and pass with it; `t/stream-plugin/prometheus-metrics.t` and `t/stream-plugin/prometheus.t` still pass. #### Which issue(s) this PR fixes: Fixes # ### Checklist - [x] I have explained the need for this PR and the problem it solves - [x] I have explained the changes or the new features added to this PR - [x] I have added tests corresponding to this change - [x] I have updated the documentation to reflect this change - [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
