Feat/config management#457
Open
Mrchinedum wants to merge 4 commits intorinafcode:mainfrom
Open
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
- 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)
- Add docs/MODULE_INTERFACE_STANDARDS.md defining 8 rules: module-level doc comment, manager-struct pattern, section comments, #[must_use] on pure getters, error handling, auth pattern, compliance table, and a minimal example module - Refactor reputation.rs: free functions -> ReputationManager struct, add module doc, section comments (Mutations/Queries/Internal), #[must_use] on get_reputation - Add module doc, Mutations/Queries section comments, and #[must_use] on all 3 getters in score.rs - Add module doc, standardize section comments (Initialization/Mutations/Admin/Queries), and #[must_use] on all 5 getters in rewards.rs - Update all 4 reputation call sites in lib.rs from free functions to ReputationManager::* methods
- Centralize 45 scattered pub const values from 13 contract modules into contracts/teachlink/src/config.rs (15 sections, fully documented) - Each module re-exports its constants from config via pub use aliases preserving backward compatibility - Add mod config to lib.rs - Add indexer ConfigManager: typed IndexerConfig snapshot, startup validation (URL format, port range, poll interval, batch size), hot-reload via reload() method - Add AppConfigModule wrapping NestJS ConfigModule + ConfigManager - Add GET /analytics/config and POST /analytics/config/reload endpoints - Wire AppConfigModule into AppModule and ReportingModule
|
@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! 🚀 |
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 #384
feat: implement comprehensive configuration management
Configuration was scattered across 13 contract modules as isolated
pub const values with no shared convention, no validation, and no
runtime reload capability. This change centralizes all constants into
a single contract config module and adds a validated, hot-reloadable
ConfigManager to the indexer.
Changes
contracts/teachlink/src/config.rs (new — 184 lines)
15 documented sections:
Analytics METRICS_UPDATE_INTERVAL
Atomic Swaps SWAP_MIN_TIMELOCK, SWAP_MAX_TIMELOCK, SWAP_HASH_LENGTH
Audit AUDIT_MAX_RECORDS, AUDIT_COMPLIANCE_PERIOD
BFT Consensus BFT_MIN_VALIDATOR_STAKE, BFT_PROPOSAL_TIMEOUT,
BFT_ROTATION_EPOCH_ROUNDS, BFT_MIN_ACTIVE_REPUTATION
Emergency EMERGENCY_SECURITY_COUNCIL_SIZE, EMERGENCY_DAILY_VOLUME_RESET
Ledger Time LEDGER_EST_SECS
Liquidity LIQUIDITY_BASE_FEE_BPS, LIQUIDITY_MAX_FEE_BPS,
LIQUIDITY_MIN_FEE_BPS, LIQUIDITY_UTILIZATION_THRESHOLD
Message Passing MSG_DEFAULT_PACKET_TIMEOUT, MSG_MAX_RETRY_ATTEMPTS,
MSG_RETRY_DELAY_BASE
Multichain MULTICHAIN_MAX_CHAINS, MULTICHAIN_MAX_ASSETS
Network Recovery RECOVERY_MAX_RETRY_ATTEMPTS, RECOVERY_INITIAL_BACKOFF_SECS,
RECOVERY_MAX_BACKOFF_SECS, RECOVERY_BACKOFF_MULTIPLIER
Notifications NOTIF_IMMEDIATE_DELIVERY, NOTIF_MIN_DELAY_SECS,
NOTIF_MAX_DELAY_SECS, NOTIF_BATCH_SIZE,
NOTIF_DEFAULT_EVENT_TTL_SECS
Performance Cache PERF_CACHE_TTL_SECS, PERF_MAX_TOP_CHAINS
Rate Limiting RATE_LIMIT_DEFAULT_MAX_CALLS, RATE_LIMIT_DEFAULT_WINDOW_LEDGERS
Slashing SLASH_DOUBLE_VOTE_BPS, SLASH_INVALID_SIGNATURE_BPS,
SLASH_INACTIVITY_BPS, SLASH_BYZANTINE_BPS, SLASH_MALICIOUS_BPS
Sustainability SUSTAIN_CONTENT_SCORE_CAP, SUSTAIN_USER_SCORE_CAP
Upgrade UPGRADE_ROLLBACK_WINDOW_SECS
contracts/teachlink/src/lib.rs
13 contract modules refactored (zero behavior change)
emergency.rs, ledger_time.rs, liquidity.rs, message_passing.rs,
multichain.rs, network_recovery.rs, notification.rs, performance.rs,
rate_limiting.rs, slashing.rs, upgrade.rs
pub use crate::config::CANONICAL_NAME as LOCAL_NAME;
preserving all existing call sites while pointing to the single
source of truth
indexer/src/config/config.manager.ts (new — 175 lines)
indexer, and app settings; every field documents its env var and default
load() reads all values from ConfigService into a typed snapshot
validate() enforces 7 rules:
horizonUrl / sorobanRpcUrl must start with http
dbPort must be 1–65535
dbPassword must be non-empty
pollIntervalMs must be >= 1000
batchSize must be 1–10000
port must be 1–65535
onModuleInit() calls load() + validate() at startup; throws if
any rule fails, preventing a misconfigured boot
reload() re-runs load() + validate() and atomically swaps the
snapshot on success; returns errors without applying
on failure (safe hot-reload)
get() returns the current validated snapshot
indexer/src/config/config.module.ts (new)
exports ConfigManager for injection anywhere in the app
indexer/src/reporting/reporting.controller.ts
{ success: true } or { success: false, errors }
indexer/src/reporting/reporting.module.ts
indexer/src/app.module.ts
Acceptance criteria met
✓ Centralize configuration — config.rs (contract) + ConfigManager (indexer)
✓ Add validation — 7 startup rules; boot fails on misconfiguration
✓ Support hot-reload — POST /analytics/config/reload; atomic swap,
no restart required
✓ Document configuration — every constant and field has inline docs
with env var, unit, and default value