Repository navigation
[serve] Fix TypeError when recording a custom metric with a route tag - #66616
abrarsheikh merged 3 commits into
Conversation
Signed-off-by: GNITOAHC <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates Ray Serve metrics (Counter, Gauge, and Histogram) to correctly handle cases where no explicit tags are provided during recording, preventing a potential TypeError when filling in the route tag. It also updates the documentation and adds a test to verify this behavior. The reviewer suggests copying the user-provided tags dictionary instead of mutating it in place to avoid unexpected side-effects.
|
can you please provide a repro script for this issue? |
Sure! Below is the repro script, it exits 1 when the bug is present, 0 when it's fixed, so it can be run against master and against this branch to compare:
|
|
Hey @abrarsheikh, just checking in, I've posted the repro above, and CI is green. Let me know if you’d like me to take a different approach. |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Chao-Ting, Chen <[email protected]>
…ray-project#66616) ## Description `ray.serve.metrics.{Counter,Gauge,Histogram}` raise `TypeError: argument of type 'NoneType' is not iterable` when a metric declares `"route"` in `tag_keys` and is recorded without an explicit `tags` argument: ```python from ray.serve.metrics import Counter Counter("my_counter", tag_keys=("route",)).inc() # TypeError: argument of type 'NoneType' is not iterable ``` `inc()`, `set()` and `observe()` all default `tags` to `None` and pass it straight to `_add_serve_context_tag_values()`, which evaluates `ROUTE_TAG not in tags` against that `None`. ## Related issues No existing issue --------- Signed-off-by: GNITOAHC <[email protected]> Signed-off-by: Chao-Ting, Chen <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
fellowship: 提名 GNITOAHC (ray, 2026-11) 建議等級 2 萬 - [x] 關係人宣告:提名人與被提名者無親屬、僱傭、財務、業務合作或其他可能影響公正判斷之利害關係 - 在兩個月內自己從 Ray Serve 原始碼找到 9 個 bug 並開了 PR,其中 6 個 PR 被 Merged ([Merged PRs](https://github.com/ray-project/ray/pulls?q=is%3Apr+author%3AGNITOAHC+is%3Amerged+merged%3A%3C%3D2026-11-24)) - 開了 Gang Scheduling + Autoscaling 的 Issue 並附上 Repro Script,社群後續依此開 PR 修復,提名人則變成該 PR 的 Reviewer ([#67494](ray-project/ray#67494)) - PR Description 簡潔清楚,讓 Reviewer 清楚理解 PR 解決了什麼問題 ([#66358](ray-project/ray#66358), [#66438](ray-project/ray#66438), [#66616](ray-project/ray#66616), [#66910](ray-project/ray#66910)) - 對於 Maintainer 的 Review 會清楚了解之後回覆 ([#67923 comment](ray-project/ray#67923 (comment)), [#67210 comment](ray-project/ray#67210 (comment)), [#66438 comment](ray-project/ray#66438 (comment)))
Description
ray.serve.metrics.{Counter,Gauge,Histogram}raiseTypeError: argument of type 'NoneType' is not iterablewhen a metric declares"route"intag_keysand is recorded without an explicittagsargument:inc(),set()andobserve()all defaulttagstoNoneand pass it straight to_add_serve_context_tag_values(), which evaluatesROUTE_TAG not in tagsagainst thatNone.Related issues
No existing issue