In release mode, Investigate counter update to fail in compile time if the counter being updated is not defined.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 16
- Forks
- 22
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 5
Description
Right now updating a counter that is not defined will cause memory corruption in release mode.
Slack Discuss: https://ebay-eng.slack.com/archives/C07JWRZGG4D/p1740761894559139
Some Discussion History:
From Yaming Kuang:
See code below, for debug build, if someone is updating counter that doesn't exist, it should be able to throw runtime assert error, line: 263.
For release build, it won't, because see line:275, there is no check, it is just pretending it got valid index (this index could be anything) and then try to increase it.
#define COUNTER_INCREMENT(group, name, ...) \
__VALIDATE_AND_EXECUTE(group, NamedCounter, counter_increment, name, __VA_ARGS__)
258 #ifndef NDEBUG
259 #define __VALIDATE_AND_EXECUTE(group, type, method, name, ...) \
260 { \
261 using namespace sisl; \
262 const auto index{METRIC_NAME_TO_INDEX(type, name)}; \
263 if (index == std::numeric_limits< decltype(index) >::max()) { \
264 fprintf(stderr, "Metric name '%s' not registered yet but used\n", BOOST_PP_STRINGIZE(name)); \
265 fflush(stderr); \
266 assert(0); \
267 } \
268 ((group).m_impl_ptr->method(index, __VA_ARGS__)); \
269 }
270 #else
271 #define __VALIDATE_AND_EXECUTE(group, type, method, name, ...) \
272 { \
273 using namespace sisl; \
274 const auto index{METRIC_NAME_TO_INDEX(type, name)}; \
275 ((group).m_impl_ptr->method(index, __VA_ARGS__)); \
276 }
277 #endif
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search for COUNTER_INCREMENT, __VALIDATE_AND_EXECUTE, and METRIC_NAME_TO_INDEX, then inspect how the release-mode macro handles an undefined counter. Confirm the behavior in both debug and release builds; done means an undefined counter is rejected during compilation rather than producing an invalid index and memory corruption.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100