js-ceramic
js-ceramic copied to clipboard
feat: add ability to publish metrics as ceramic model instance documents (rebased)
Description
This PR enables publishing metrics to the ceramic network as model instance documents. It uses the same count
and observe
semantics as ServiceMetrics, with a configurable interval for publishing.
Key Design notes
-
avoids circular dependencies. the observability model-metrics package accepts a ceramic api instance at run time, so never imports any js-ceramic common packages.
-
singleton pattern. because of the instance import and that its instantiated as a singleton, you can import model-metrics from a code path where the ceramic instance is not accessible, and still use it; also no need to pass it around, just import
-
lightweight functions. the
count
observe
andrecordError
functions are very lightweight, and only update variables in memory. At the configured interval time, a summary will be published as a model metric.
These designs are in the model-metrics package in the observability repo which is a dependency of this PR. The code is separate from js-ceramic but the npm package is published under @ceramicnetwork/model-metrics
How Has This Been Tested?
Describe the tests that you ran to verify your changes. Provide instructions for reproduction.
- [x ] Tested manually with a local node on dev-unstable, verified that metrics are correctly produced.
To reproduce this test, add the following into daemon.config.json and run your node.
"metrics": {
"metrics-publisher-enabled": true
}
- [ x] Tested Manually with a harness at https://github.com/3box/runbooks-and-oncall/tree/main/MetricsDemo (see readme for instructions)
PR checklist
Before submitting this PR, please make sure:
- [x] I have tagged the relevant reviewers and interested parties
- [ ] I have updated the READMEs of affected packages
- [ ] I have made corresponding changes to the documentation
References:
Please list relevant documentation (e.g. tech specs, articles, related work etc.) relevant to this change, and note if the documentation has been updated.