From 3e257ad246d741a0f01befe43c63da52c45a387a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 30 Jun 2022 17:57:29 +0200 Subject: [PATCH 1/5] feat: add query telemetry --- baseapp/abci.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/baseapp/abci.go b/baseapp/abci.go index a56fcb8d93ed..8534b921eebd 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -388,6 +388,9 @@ 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) + // 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 { From 9bfb9d744918a47e3d26a82b7522eabc040b3868 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 5 Jul 2022 13:15:28 +0200 Subject: [PATCH 2/5] updated telemetry docs --- docs/core/telemetry.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/core/telemetry.md b/docs/core/telemetry.md index d34ad51ec1d2..2a839fddb7f0 100644 --- a/docs/core/telemetry.md +++ b/docs/core/telemetry.md @@ -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: `/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) { From 4044a1fc47a0bcf54f8b794bc940249f1a1a8ab1 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 5 Jul 2022 13:17:00 +0200 Subject: [PATCH 3/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c1b86034901..295da4b27d63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 23216252e12d08557ba99cd2d4c3cd94939926b6 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 5 Jul 2022 13:22:34 +0200 Subject: [PATCH 4/5] update link --- docs/core/telemetry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/telemetry.md b/docs/core/telemetry.md index 2a839fddb7f0..c95fac283a68 100644 --- a/docs/core/telemetry.md +++ b/docs/core/telemetry.md @@ -11,7 +11,7 @@ their application through the use of the `telemetry` package. To enable telemetr 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: `/metrics?format={text|prometheus}`, the default being `text`. +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 From ae9a5f0088b29b272bc1756665f1df10a59df61e Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 5 Jul 2022 19:49:59 +0200 Subject: [PATCH 5/5] Add measure since telemetry for queries --- baseapp/abci.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/baseapp/abci.go b/baseapp/abci.go index 8534b921eebd..2aa71a6148b9 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -8,6 +8,7 @@ import ( "sort" "strings" "syscall" + "time" "github.com/gogo/protobuf/proto" abci "github.com/tendermint/tendermint/abci/types" @@ -390,6 +391,7 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) { 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