feat: add query telemetry (#12405)
Closes: #12333 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
1dcf633084
commit
f70b67fc91
@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* (cli) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Add the `tendermint key-migrate` to perform Tendermint v0.35 DB key migration.
|
||||
* (query) [#12253](https://github.com/cosmos/cosmos-sdk/pull/12253) Add `GenericFilteredPaginate` to the `query` package to improve UX.
|
||||
* (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry.
|
||||
|
||||
### Improvements
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -388,6 +389,10 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
|
||||
req.Height = app.LastBlockHeight()
|
||||
}
|
||||
|
||||
telemetry.IncrCounter(1, "query", "count")
|
||||
telemetry.IncrCounter(1, "query", req.Path)
|
||||
defer telemetry.MeasureSince(time.Now(), req.Path)
|
||||
|
||||
// handle gRPC routes first rather than calling splitPath because '/' characters
|
||||
// are used as part of gRPC paths
|
||||
if grpcHandler := app.grpcQueryRouter.Route(req.Path); grpcHandler != nil {
|
||||
|
||||
@ -7,16 +7,17 @@ order: 10
|
||||
Gather relevant insights about your application and modules with custom metrics and telemetry. {synopsis}
|
||||
|
||||
The Cosmos SDK enables operators and developers to gain insight into the performance and behavior of
|
||||
their application through the use of the `telemetry` package. The Cosmos SDK currently supports
|
||||
enabling in-memory and prometheus as telemetry sinks. This allows the ability to query for and scrape
|
||||
metrics from a single exposed API endpoint -- `/metrics?format={text|prometheus}`, the default being
|
||||
`text`.
|
||||
their application through the use of the `telemetry` package. To enable telemetrics, set `telemetry.enabled = true` in the app.toml config file.
|
||||
|
||||
The Cosmos SDK currently supports enabling in-memory and prometheus as telemetry sinks. In-memory sink is always attached (when the telemetry is enabled) with 10 second interval and 1 minute retention. This means that metrics will be aggregated over 10 seconds, and metrics will be kept alive for 1 minute.
|
||||
|
||||
To query active metrics (see retention note above) you have to enable API server (`api.enabled = true` in the app.toml). Single API endpoint is exposed: `http://localhost:1317/metrics?format={text|prometheus}`, the default being `text`.
|
||||
|
||||
## Emitting metrics
|
||||
|
||||
If telemetry is enabled via configuration, a single global metrics collector is registered via the
|
||||
[go-metrics](https://github.com/armon/go-metrics) library. This allows emitting and collecting
|
||||
metrics through simple API calls.
|
||||
|
||||
Example:
|
||||
metrics through simple [API](https://github.com/cosmos/cosmos-sdk/blob/v0.46.0-rc1/telemetry/wrapper.go). Example:
|
||||
|
||||
```go
|
||||
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user