-
Notifications
You must be signed in to change notification settings - Fork 879
feat(metrics): migrate sei-cosmos to OpenTelemetry (PLT-353) #3467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bf58610
Added otel to sei-cosmos package
amir-deris 2adef34
Added bounded routes as the metric label
amir-deris 18f8dae
Fixed description of metrics
amir-deris 2b240fa
Added context to interface Queryable
amir-deris cfaaa99
Added bounded buckets for denom cardinality
amir-deris d476732
Dropped the proposal id from new metric
amir-deris e1348dc
Removed info attribute, resolved plan height metric collision
amir-deris 47ba551
Merge branch 'main' into amir/plt-352-migrate-sei-cosmos-to-otel
amir-deris 43c6641
Converted succes and proof to bool attribute
amir-deris 5613762
Fixed abciQueryMetricRoute test
amir-deris bf31afc
Updated utils_test for query context
amir-deris 3732641
Updated metric units
amir-deris 7389653
Moved DenomClass method to its own file
amir-deris 254e9f5
Added last to metric names
amir-deris 42da9c0
Added extra buckets for abci_query_duration
amir-deris 6771eb0
Merge branch 'main' into amir/plt-352-migrate-sei-cosmos-to-otel
amir-deris ad8921b
Fixing lint errors
amir-deris 198db78
Merge branch 'main' into amir/plt-352-migrate-sei-cosmos-to-otel
amir-deris 51d0617
Merge branch 'main' into amir/plt-352-migrate-sei-cosmos-to-otel
amir-deris 6fdfa8f
Merge branch 'main' into amir/plt-352-migrate-sei-cosmos-to-otel
masih 363bbe2
Reused time.Now in process proposal and finalize block
amir-deris 84551ab
Merge branch 'main' into amir/plt-352-migrate-sei-cosmos-to-otel
amir-deris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| package baseapp | ||
|
|
||
| import storetypes "github.com/sei-protocol/sei-chain/sei-cosmos/store/types" | ||
|
|
||
| // storeByNameLookup is implemented by CommitMultiStore backends (rootmulti, storev2). | ||
| type storeByNameLookup interface { | ||
| GetStoreByName(name string) storetypes.Store | ||
| } | ||
|
|
||
| // abciStoreQuerySubpaths are the only subpath segments used by mounted store | ||
| // Query implementations (/key, /subspace). See store/rootmulti and storev2/commitment. | ||
| var abciStoreQuerySubpaths = map[string]struct{}{ | ||
| "key": {}, | ||
| "subspace": {}, | ||
| } | ||
|
|
||
| // abciQueryMetricRoute returns a bounded label for ABCI query metrics. | ||
| // Raw client paths are not used directly to avoid unbounded metric cardinality. | ||
| // | ||
| // Rules: | ||
| // - Registered gRPC query paths are returned as-is (finite set at startup). | ||
| // - Legacy paths use a fixed prefix + registered segment shape. | ||
| // - Everything else is "other". | ||
| func (app *BaseApp) abciQueryMetricRoute(reqPath string) string { | ||
| if app.grpcQueryRouter != nil && app.grpcQueryRouter.Route(reqPath) != nil { | ||
| return reqPath | ||
| } | ||
|
|
||
| parts := splitPath(reqPath) | ||
| if len(parts) == 0 { | ||
| return "other" | ||
| } | ||
|
|
||
| switch parts[0] { | ||
| case "app": | ||
| if len(parts) >= 2 { | ||
| switch parts[1] { | ||
| case "simulate", "version", "snapshots": | ||
| return "app/" + parts[1] | ||
| } | ||
| } | ||
| return "app/unknown" | ||
|
|
||
| case "store": | ||
| return app.abciStoreQueryMetricRoute(parts) | ||
|
|
||
| case "custom": | ||
| if len(parts) >= 2 && parts[1] != "" && app.queryRouter != nil && app.queryRouter.Route(parts[1]) != nil { | ||
| return "custom/" + parts[1] | ||
| } | ||
| return "custom/unknown" | ||
|
|
||
| default: | ||
| return "other" | ||
| } | ||
| } | ||
|
|
||
| func (app *BaseApp) abciStoreQueryMetricRoute(parts []string) string { | ||
| unknownRoute := "store/unknown" | ||
| if len(parts) < 3 { | ||
| return unknownRoute | ||
| } | ||
| storeName, subpath := parts[1], parts[2] | ||
| if _, ok := abciStoreQuerySubpaths[subpath]; !ok { | ||
| return unknownRoute | ||
| } | ||
| if !app.storeRegisteredForQuery(storeName) { | ||
| return unknownRoute | ||
| } | ||
| return "store/" + storeName + "/" + subpath | ||
| } | ||
|
|
||
| func (app *BaseApp) storeRegisteredForQuery(name string) bool { | ||
| if lookup, ok := app.cms.(storeByNameLookup); ok && lookup.GetStoreByName(name) != nil { | ||
| return true | ||
| } | ||
| if app.qms != nil { | ||
| if lookup, ok := app.qms.(storeByNameLookup); ok && lookup.GetStoreByName(name) != nil { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // abciQueryMetricRouteLabel is kept as "path" for compatibility with existing dashboards. | ||
| const abciQueryMetricRouteLabel = "path" |
This file contains hidden or 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,76 @@ | ||
| package baseapp | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/sei-cosmos/testutil" | ||
| "github.com/sei-protocol/sei-chain/sei-cosmos/testutil/testdata" | ||
| sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types" | ||
| abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types" | ||
| "github.com/stretchr/testify/require" | ||
| dbm "github.com/tendermint/tm-db" | ||
| ) | ||
|
|
||
| func TestAbciQueryMetricRoute(t *testing.T) { | ||
| db := dbm.NewMemDB() | ||
| app := NewBaseApp(t.Name(), db, nil, nil, &testutil.TestAppOpts{}) | ||
|
|
||
| grpcQR := app.GRPCQueryRouter() | ||
| grpcQR.SetInterfaceRegistry(testdata.NewTestInterfaceRegistry()) | ||
| testdata.RegisterQueryServer(grpcQR, testdata.QueryImpl{}) | ||
|
|
||
| app.QueryRouter().AddRoute("bank", func(_ sdk.Context, _ []string, _ abci.RequestQuery) ([]byte, error) { | ||
| return nil, nil | ||
| }) | ||
|
|
||
| grpcEcho := "/testdata.Query/Echo" | ||
|
|
||
| tests := map[string]struct { | ||
| reqPath string | ||
| expected string | ||
| }{ | ||
| // Production gRPC paths (3-month sample); registered via testdata.Query. | ||
| "grpc registered": { | ||
| reqPath: grpcEcho, | ||
| expected: grpcEcho, | ||
| }, | ||
| "grpc unregistered": { | ||
| reqPath: "/cosmos.bank.v1beta1.Query/TotalSupply", | ||
| expected: "other", | ||
| }, | ||
|
|
||
| // Legacy app paths. | ||
| "app snapshots": {reqPath: "app/snapshots", expected: "app/snapshots"}, | ||
| "app version": {reqPath: "app/version", expected: "app/version"}, | ||
| "app unknown": {reqPath: "app/unknown-action", expected: "app/unknown"}, | ||
|
|
||
| // Legacy store paths (unknown store name or subpath → single bucket). | ||
| "store ibc key unregistered": {reqPath: "store/ibc/key", expected: "store/unknown"}, | ||
| "store random attack": {reqPath: "store/random1/random2", expected: "store/unknown"}, | ||
| "store bad subpath": {reqPath: "store/key1/evil", expected: "store/unknown"}, | ||
| "store short": {reqPath: "store/bank", expected: "store/unknown"}, | ||
|
|
||
| // Legacy custom paths; subpath segments are not part of the metric label. | ||
| "custom bank": {reqPath: "custom/bank/all_balances", expected: "custom/bank"}, | ||
| "custom unregistered": {reqPath: "custom/unknown/foo", expected: "custom/unknown"}, | ||
|
|
||
| // Garbage / attack paths. | ||
| "empty": {reqPath: "", expected: "other"}, | ||
| "random": {reqPath: "/totally/made/up", expected: "other"}, | ||
| "leading slash app": {reqPath: "/app/snapshots", expected: "app/snapshots"}, | ||
| } | ||
|
|
||
| for name, tc := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| require.Equal(t, tc.expected, app.abciQueryMetricRoute(tc.reqPath)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAbciQueryMetricRoute_RegisteredStore(t *testing.T) { | ||
| app := setupBaseApp(t) | ||
| route := fmt.Sprintf("store/%s/key", capKey1.Name()) | ||
| require.Equal(t, route, app.abciQueryMetricRoute(route)) | ||
| require.Equal(t, "store/unknown", app.abciQueryMetricRoute("store/random1/key")) | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.