feat: add comprehensive contract sustainability metrics#452
Merged
Xhristin3 merged 3 commits intorinafcode:mainfrom Apr 28, 2026
Merged
feat: add comprehensive contract sustainability metrics#452Xhristin3 merged 3 commits intorinafcode:mainfrom
Xhristin3 merged 3 commits intorinafcode:mainfrom
Conversation
- Add SustainabilityMetrics type with KPIs: invocations, storage writes, events emitted, rewards distributed, content minted, active users, and efficiency score - Add SUSTAINABILITY_METRICS storage key - Add SustainabilityMetricsUpdatedEvent - Add SustainabilityManager with record, query, and health score logic - Expose 4 public contract entry points in lib.rs - Include unit tests for core metric tracking and health scoring
|
@Mrchinedum Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
- Add 8 sustainability Prometheus gauges to MetricsService
(invocations, storage writes, events emitted, rewards distributed,
content minted, active users, efficiency score, health score)
- Add updateSustainabilityMetrics() to push gauges on each query
- Add getSustainabilitySnapshot() to DashboardService: computes
real-time KPIs (efficiency, health, dispute rate, reward claim rate)
and pushes them to Prometheus
- Add GET /analytics/sustainability endpoint in ReportingController
- Add teachlink-sustainability alert group to prometheus/alerts.yml
with 5 rules: low efficiency, critical efficiency, low health score,
high error rate, no new transactions
- Create teachlink-monitoring-dashboard.json (691 lines, 20 panels):
- Row 1: Real-Time Platform Health (6 stat panels)
- Row 2: Historical Trends (4 time-series panels)
- Row 3: Alert Management (firing alerts, active count, critical count)
- Row 4: Platform Insights (cache ratio, latency percentiles,
dependency health, indexer progress, HTTP status breakdown)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixed #390
feat: add comprehensive contract sustainability metrics
Sustainability metrics were not tracked anywhere in the contract.
This change introduces a dedicated module to define KPIs, record
resource usage, monitor efficiency, and report platform health.
What changed
contracts/teachlink/src/sustainability.rs (new)
snapshot stored in contract instance storage
optionally total_storage_writes on every tracked call
record_active_user — granular hooks for each KPI dimension
efficiency_score in basis points (0-10 000)
50 % efficiency score
25 % content creation (capped at 1 000 tokens = 100 %)
25 % user adoption (capped at 1 000 users = 100 %)
health_score_zero_ops
contracts/teachlink/src/types.rs
total_invocations, total_storage_writes, total_events_emitted,
total_rewards_distributed, total_content_minted,
total_active_users, efficiency_score, last_updated
contracts/teachlink/src/storage.rs
contracts/teachlink/src/events.rs
and efficiency updates (fields: total_invocations,
total_storage_writes, total_events_emitted, efficiency_score,
updated_at)
contracts/teachlink/src/lib.rs
get_sustainability_metrics → report metrics
get_sustainability_health_score → report health score
update_sustainability_efficiency → monitor efficiency
record_sustainability_invocation → track resource usage
Acceptance criteria met
✓ Sustainability KPIs defined (efficiency, resource usage, adoption,
content creation, rewards flow)
✓ Resource usage tracked (invocations, storage writes, events emitted)
✓ Efficiency monitored (basis-point score, updated via public entry point)
✓ Metrics reported (snapshot query + composite health score)