Skip to content

CLI metrics table renders blank cells for counters and histograms #221

Open

Description

@sspaink

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmetricsMetrics API and instrumentation

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions