Skip to content

Implement token reporting in console#3743

Open
michaeljguarino wants to merge 1 commit into
masterfrom
report-tokens
Open

Implement token reporting in console#3743
michaeljguarino wants to merge 1 commit into
masterfrom
report-tokens

Conversation

@michaeljguarino

Copy link
Copy Markdown
Member

Will be needed when we ultimately need to bill-back token usage in plural cloud

Test Plan

Test environment: https://console.your-env.onplural.sh/

Checklist

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have deployed the agent to a test environment and verified that it works as expected (required only when changing agent code).

Plural Flow: console

Will be needed when we ultimately need to bill-back token usage in plural cloud
@michaeljguarino michaeljguarino requested a review from a team June 20, 2026 00:06
@michaeljguarino michaeljguarino added the enhancement New feature or request label Jun 20, 2026
@soffi-ai

soffi-ai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Soffi AI Summary

This PR adds token usage reporting to the console's statistics module, motivated by the need to eventually support billing-back token usage in Plural Cloud. The change refactors the info/0 function in Console.Deployments.Statistics to collect all Prometheus meter metrics once (avoiding duplicate calls) and exposes a new tokens field alongside the existing bytes_ingested metric. A minor correctness fix is also included, aligning the clusters count in info/0 to use Cluster.physical() — consistent with the standalone clusters/0 function — ensuring virtual/non-physical clusters are excluded from the reported count.

Commits

Commit Summary
0ab738f Adds token usage to the statistics info payload by collecting all Prometheus meter metrics in a single call and exposing a new tokens field. Also fixes the cluster count in info/0 to use Cluster.physical() for consistency with the rest of the codebase.

Deploy in Soffi


Updated: 2026-06-20 00:06 UTC

@greptile-apps

greptile-apps Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR wires token usage reporting into the console's periodic ping to the Plural platform, laying the groundwork for future billing of LLM token consumption in Plural Cloud.

  • Statistics.info/0 now calls Console.Prom.Meter.collect/0 once and extracts both bytes_ingested and tokens from the result, avoiding a double fetch/reset. The cluster count is also corrected from Cluster to Cluster.physical/0, consistent with the existing clusters/0 function.
  • Console.Prom.Meter already tracks a tokens counter (incremented via incr_tokens/2) and resets it on each collect/0 call, so the new field is available with no changes needed to the meter module itself.

Confidence Score: 4/5

Safe to merge — the change is small and well-scoped, touching only how statistics are gathered and reported.

The functional change is straightforward: deduplicate a meter fetch and add a tokens field. The only gap worth noting is that pinger.ex's to_gql/1 is not updated to document tokens as an explicit usage attribute — the field passes through correctly today because no renaming is needed, but nothing in the code signals that it is intentionally forwarded to the Plural API.

lib/console/plural/pinger.ex — to_gql/1 should be updated to reflect that tokens is now a forwarded usage attribute.

Important Files Changed

Filename Overview
lib/console/deployments/statistics.ex Adds token reporting to the statistics info map; also corrects cluster count from Cluster to Cluster.physical(), and deduplicates the Console.Prom.Meter.collect() call so both meters are read in one atomic fetch/reset cycle.

Reviews (1): Last reviewed commit: "Implement token reporting in console" | Re-trigger Greptile

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants