Skip to content

[HbarLimitService] Replace updateAverageAmountSpentPerSubscriptionTier with Efficient Metrics Collection #3709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
quiet-node opened this issue Apr 17, 2025 · 0 comments
Labels
enhancement New feature or request Team Promoted Issues to be triaged and discussed by committers, maintainers, to be worked on the following sprint

Comments

@quiet-node
Copy link
Contributor

Problem

The updateAverageAmountSpentPerSubscriptionTier method in HbarLimitService generates excessive logs when the database contains many HBAR spending plans. It retrieves all active plans for a subscription tier, calculates the average amount spent, and updates a Prometheus gauge.

When there are numerous accounts, this process:

  • Iterates over potentially large collections of accounts
  • Creates multiple database queries
  • Generates excessive debug logs
  • Performs calculations that could be done more efficiently at visualization time

Proposed Solution

  1. Remove the updateAverageAmountSpentPerSubscriptionTier method entirely
  2. Replace with two separate metrics:
    • Track the total amount spent per subscription tier
    • Track the count of active plans per subscription tier (already implemented)
  3. Leverage Grafana's calculation capabilities to compute the average (total amount / count) at visualization time

Benefits

  • Reduced database load: No need to frequently fetch all plans
  • Decreased log volume: Elimination of unnecessary log entries for each calculation
  • More efficient metrics collection: Basic counters instead of complex calculations
  • Improved performance: Calculations moved to visualization layer (Grafana)
  • Better scalability: Solution works efficiently regardless of the number of accounts

Implementation Notes

  • The current averageSpendingPlanAmountSpentGauge should be replaced with a new gauge for tracking total amount spent
  • Existing counters for tracking unique plans can be utilized for the denominator
  • Transition should be seamless for monitoring dashboards with proper Grafana query adjustments
@quiet-node quiet-node added the enhancement New feature or request label Apr 17, 2025
@quiet-node quiet-node added the Team Promoted Issues to be triaged and discussed by committers, maintainers, to be worked on the following sprint label Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Team Promoted Issues to be triaged and discussed by committers, maintainers, to be worked on the following sprint
Projects
None yet
Development

No branches or pull requests

1 participant