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

CLI metrics table renders blank cells for counters and histograms

Open
#221 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug metrics
Dominant language
Java
Stars
16
Forks
24
Avg merge
8h 17m
Merged PRs (30d)
15

Description

MetricsReporter only knows how to render Metrics.Timer. Both table paths in
cli/src/main/java/io/github/open_policy_agent/opa/cli/MetricsReporter.java
test instanceof Metrics.Timer and leave everything else as the empty string:

  • printSingleMetricsTable (lines 39-43 and 56-61) initialises String value = ""
    and only fills it in for a timer.
  • printStatisticalMetricsTable (line 74) collects values only for timers, so
    non-timer metrics are dropped from that table entirely.

Until #216, SimpleMetrics.all() returned only timers, so this was unreachable.
That PR makes all() return counters and histograms too, so a metric registered
via Metrics.counter(...) or Metrics.histogram(...) now reaches the reporter and
prints as a row with a blank cell under TIME.

Nothing in the repo registers a counter or histogram yet, so this is not visible
in normal CLI use today — it only shows up for an embedder that registers one on
the Metrics instance passed to an evaluation. It seemed better as a follow-up
than as scope added to #216.

Suggested fix

Handle the other two types the way MetricsPrinter already does
(opa-evaluator/src/main/java/io/github/open_policy_agent/opa/metrics/MetricsPrinter.java:78-87):
counters print their integer value, histograms explode into one row per stat.
The TIME column header also stops being accurate once non-timers can appear.

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 in cli/src/main/java/io/github/open_policy_agent/opa/cli/MetricsReporter.java, focusing on printSingleMetricsTable and printStatisticalMetricsTable. Compare their handling with MetricsPrinter at opa-evaluator/src/main/java/io/github/open_policy_agent/opa/metrics/MetricsPrinter.java:78-87; done means counters and histogram statistics render in the CLI tables without an inaccurate TIME-only header.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.