forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADR: 013] Observability (cosmos#5188)
* [ADR: 013] Metrics - Inital ADR for metrics with in the SDK - extending metrics to be module specific as well Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * add some metrics * update adr-013 to Observability * Update docs/architecture/README.MD Co-Authored-By: Jack Zampolin <jack.zampolin@gmail.com> * change wording * minor wording change * add more things * undo module work * Fix formatting and added more info * Address comments * Address comments Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Jack Zampolin <jack.zampolin@gmail.com> Co-authored-by: Timothy Chen <tnachen@gmail.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bc863c9
commit 6c1e3e5
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# ADR 013: Observability | ||
|
||
## Changelog | ||
|
||
- 20-01-2020: Initial Draft | ||
|
||
## Status | ||
|
||
Proposed | ||
|
||
## Context | ||
|
||
There has been discussion around exposing more metrics to users and node operators about the application. Currently there is only a way to expose metrics from Tendermint and not the application itself. To bring more visibility into applications, I would like to propose reporting of metrics through [Prometheus](https://prometheus.io/). | ||
|
||
Extending `AppModuleBasic` to support registering of metrics would enable developers to see more information about individual modules. | ||
|
||
```go | ||
type AppModuleBasic interface { | ||
Name() string | ||
RegisterCodec(*codec.Codec) | ||
RegisterMetrics(namespace string, labelsAndValues... string) *Metrics | ||
|
||
// genesis | ||
DefaultGenesis() json.RawMessage | ||
ValidateGenesis(json.RawMessage) error | ||
|
||
// client functionality | ||
RegisterRESTRoutes(context.CLIContext, *mux.Router) | ||
GetTxCmd(*codec.Codec) *cobra.Command | ||
GetQueryCmd(*codec.Codec) *cobra.Command | ||
} | ||
// ..... | ||
|
||
func (bm BasicManager) RegisterMetrics(appName string, labelsAndValues... string) MetricsProvider { | ||
for _, b := range bm { | ||
b.CreateMetrics(appName, labelsAndValues) | ||
} | ||
} | ||
``` | ||
|
||
Each module can define its own `Metrics` type and`CreateMetrics` function in the x/<module>/observability/metrics.go file: | ||
|
||
```go | ||
type Metrics struct { | ||
Size metrics.Guage | ||
|
||
Transactions metrics.Counter | ||
} | ||
|
||
func CreateMetrics(namespace string, labelsAndValues... string) *Metrics { | ||
labels := make([]string, len(labelsAndValues/2)) | ||
for i := 0; i < len(labelsAndValues); i += 2 { | ||
labels[i/2] = labelsAndValues[i] | ||
} | ||
return &Metrics{ | ||
Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ | ||
Namespace: namespace, | ||
Subsystem: "subsystem", | ||
Name: "size", | ||
Help: "Size of the custom metric", | ||
}, labels).With(labelsAndValues...), | ||
Transactions: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ | ||
Namespace: namespace, | ||
Subsystem: "subsystem", | ||
Name: "transactions", | ||
Help: "Number of transactions processed", | ||
}, labels).With(labelsAndValues...), | ||
} | ||
|
||
``` | ||
To get the correct namespace for the modules changing `BasicManager` to consist of the app name is needed. | ||
```go | ||
type BasicManager struct { | ||
appName string | ||
modules map[string]AppModuleBasic | ||
} | ||
``` | ||
## Decision | ||
- Use Prometheus for metric gathering. | ||
- Add a method to register metrics to the `AppModuleBasic` interface | ||
- Modules create a observability/metrics.go that defines the metrics and create the metrics object. | ||
## Consequences | ||
### Positive | ||
- Add more visibility into SDK based application and modules | ||
### Negative | ||
### Neutral | ||
## References |