gossamer icon indicating copy to clipboard operation
gossamer copied to clipboard

feat(trie): add Prometheus metrics for tries

Open qdm12 opened this issue 2 years ago • 0 comments

Changes

⚠️ this is just production code changes. I have most test code locally, but would like some feedback before continuing updating tests and adding more deltas for reviewers.

💁 this PR shall be the foundation to accommodate several future additional metrics (such as number of key bytes, number of value bytes for all tries, number of encodings, disk operations etc.)

Changes consist essentially in:

  • 3 metric packages, each with a Prometheus and a Noop implementation (for tests, instead of using 'any' mocks)
    • internal/runtime/metrics/roothash
    • internal/runtime/metrics/proof
    • internal/state/metrics
  • Add trie Die() method to clear metrics (add nodes removed). This is used when the trie is no longer needed and would be GC. We kind of need this to keep track of the total number of nodes kept in memory, especially for state tries.

The alternative implementation would be to return statistics from trie operations (Put, Delete etc.) and handle all the metrics in callers (lib/runtime/wasmer/imports.go and dot/state/tries.go). That makes a bit more sense so we handle all the metricing in callers, since those metrics are not specific to a single trie. On the other hand, that looks like it would require a lot more code changes 😢

Tests

Issues

#2229

Primary Reviewer

@timwu20

qdm12 avatar Aug 03 '22 15:08 qdm12