open-policy-agent / open-policy-agent/java-opa-sdk

Make SimpleMetrics thread-safe

Open
#56 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

evaluator metrics
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 use AtomicLong for the accumulated value).
  • Use AtomicLong / LongAdder for Counter.
  • Add a concurrency test that exercises a shared Metrics from multiple threads.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.