open-policy-agent / open-policy-agent/java-opa-sdk
Make SimpleMetrics thread-safe
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 16
- Forks
- 24
- Avg merge
- 8h 17m
- Merged PRs (30d)
- 15
Description
SimpleMetrics stores timers in a plain TreeMap and the inline Timer has unsynchronized start/stop/value. Engine.Builder.withMetrics(...) lets callers pass in a shared instance, so this is a footgun — and the Go OPA metrics package locks per-timer plus the outer map (see https://github.com/open-policy-agent/opa/blob/main/v1/metrics/metrics.go), so the precedent is to be safe by default.
- Guard the timer/counter/histogram maps (e.g.,
ConcurrentHashMap). - Synchronize
Timer.start/stop/value(or useAtomicLongfor the accumulated value). - Use
AtomicLong/LongAdderforCounter. - Add a concurrency test that exercises a shared
Metricsfrom multiple threads.
Contributor guide
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
Start by reading SimpleMetrics, its inline Timer, and the Engine.Builder.withMetrics(...) entry point. Compare the timer, counter, histogram, and map access patterns with the linked OPA metrics precedent, then add the requested concurrency test for a shared Metrics instance. Done means concurrent use is safe and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100