Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions app/ante/metrics.go

This file was deleted.

14 changes: 12 additions & 2 deletions app/legacyabci/begin_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func BeginBlock(
byzantineValidators []abci.Misbehavior,
keepers BeginBlockKeepers,
) {
defer telemetry.MeasureSince(time.Now(), "module", "total_begin_block")
start := time.Now()
defer func() {
legacyAbciMetrics.totalBeginBlockDuration.Record(ctx.Context(), time.Since(start).Seconds())
// TODO(PLT-343): remove once begin_blocker_duration verified
telemetry.MeasureSince(start, "module", "total_begin_block")
}()

keepers.EpochKeeper.BeginBlock(ctx)
upgrade.BeginBlocker(*keepers.UpgradeKeeper, ctx)
Expand All @@ -57,7 +62,12 @@ func BeginBlock(
evidence.BeginBlocker(ctx, byzantineValidators, *keepers.EvidenceKeeper)
staking.BeginBlocker(ctx, *keepers.StakingKeeper)
func() {
defer telemetry.ModuleMeasureSince("ibc", time.Now(), telemetry.MetricKeyBeginBlocker)
ibcStart := time.Now()
defer func() {
legacyAbciMetrics.ibcBeginBlockerDuration.Record(ctx.Context(), time.Since(ibcStart).Seconds())
// TODO(PLT-343): remove once ibc_begin_blocker_duration verified
telemetry.ModuleMeasureSince("ibc", ibcStart, telemetry.MetricKeyBeginBlocker)
}()
ibcclient.BeginBlocker(ctx, keepers.IBCKeeper.ClientKeeper)
}()
keepers.EvmKeeper.BeginBlock(ctx)
Expand Down
20 changes: 13 additions & 7 deletions app/legacyabci/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
upgradekeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/upgrade/keeper"
ibckeeper "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/keeper"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
otelmetric "go.opentelemetry.io/otel/metric"
)

var defaultRecoveryMiddleware = newDefaultRecoveryMiddleware()
Expand Down Expand Up @@ -58,13 +59,18 @@ func CheckTx(
if ctx.IsReCheckTx() {
label = "recheck"
}
defer telemetry.MeasureThroughputSinceWithLabels(
telemetry.TxCount,
[]gometrics.Label{
telemetry.NewLabel("mode", label),
},
time.Now(),
)
txStart := time.Now()
defer func() {
legacyAbciMetrics.txDuration.Record(ctx.Context(), time.Since(txStart).Seconds(), otelmetric.WithAttributes(attribute.String("mode", label)))
// TODO(PLT-343): remove once tx_duration verified
telemetry.MeasureThroughputSinceWithLabels(
telemetry.TxCount,
[]gometrics.Label{
telemetry.NewLabel("mode", label),
},
txStart,
)
}()
spanCtx, span := tracingInfo.StartWithContext("CheckTx", ctx.TraceSpanContext())
defer span.End()
ctx = ctx.WithTraceSpanContext(spanCtx)
Expand Down
20 changes: 13 additions & 7 deletions app/legacyabci/deliver_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -51,13 +52,18 @@ func DeliverTx(
txCtx sdk.Context,
err error,
) {
defer telemetry.MeasureThroughputSinceWithLabels(
telemetry.TxCount,
[]metrics.Label{
telemetry.NewLabel("mode", "deliver"),
},
time.Now(),
)
txStart := time.Now()
defer func() {
legacyAbciMetrics.txDuration.Record(ctx.Context(), time.Since(txStart).Seconds(), otelmetric.WithAttributes(attribute.String("mode", "deliver")))
// TODO(PLT-343): remove once tx_duration verified
telemetry.MeasureThroughputSinceWithLabels(
telemetry.TxCount,
[]metrics.Label{
telemetry.NewLabel("mode", "deliver"),
},
txStart,
)
}()
// check for existing parent tracer, and if applicable, use it
spanCtx, span := tracingInfo.StartWithContext("DeliverTx", ctx.TraceSpanContext())
defer span.End()
Expand Down
47 changes: 47 additions & 0 deletions app/legacyabci/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package legacyabci

import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
)

var (
meter = otel.Meter("legacyabci")

// finerGrainedBuckets units are in seconds
finerGrainedBuckets = metric.WithExplicitBucketBoundaries(
0.000025, 0.000050, 0.0001, 0.0005, 0.001, 0.0025, 0.005, 0.010, 0.020, 0.050, 0.075, 0.1, 0.25, 0.5, 1, 10,
)

legacyAbciMetrics = struct {
totalBeginBlockDuration metric.Float64Histogram
ibcBeginBlockerDuration metric.Float64Histogram
txDuration metric.Float64Histogram
}{
totalBeginBlockDuration: must(meter.Float64Histogram(
"begin_blocker_duration",
metric.WithDescription("Total duration of begin-block execution in seconds"),
finerGrainedBuckets,
metric.WithUnit("s"),
)),
ibcBeginBlockerDuration: must(meter.Float64Histogram(
"ibc_begin_blocker_duration",
metric.WithDescription("Duration of IBC begin-blocker execution in seconds"),
finerGrainedBuckets,
metric.WithUnit("s"),
)),
txDuration: must(meter.Float64Histogram(
"tx_duration",
metric.WithDescription("Duration of tx processing by mode (check, recheck, deliver)"),
finerGrainedBuckets,
metric.WithUnit("s"),
)),
}
)

func must[V any](v V, err error) V {
if err != nil {
panic(err)
}
return v
}
7 changes: 4 additions & 3 deletions loadtest/loadtest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/sei-protocol/sei-chain/sei-cosmos/types"
typestx "github.com/sei-protocol/sei-chain/sei-cosmos/types/tx"
stakingtypes "github.com/sei-protocol/sei-chain/sei-cosmos/x/staking/types"
"github.com/sei-protocol/sei-chain/utils/metrics"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
"golang.org/x/sync/semaphore"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
Expand Down Expand Up @@ -194,7 +195,7 @@ func (c *LoadTestClient) BuildTxs(
}
// Generate a message type first
messageType := c.getRandomMessageType(config.MessageTypes)
metrics.IncrProducerEventCount(messageType)
loadtestMetrics.produceCount.Add(context.Background(), 1, otelmetric.WithAttributes(attribute.String("msg_type", messageType)))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For loadtest, replaced the metrics as it is only for test and no need to emit dual metrics.

var signedTx SignedTx
// Sign EVM and Cosmos TX differently
switch messageType {
Expand Down Expand Up @@ -264,7 +265,7 @@ func (c *LoadTestClient) SendTxs(
return
case tx, ok := <-txQueue:
atomic.AddInt64(sentCountPerMsgType[tx.MsgType], 1)
metrics.IncrConsumerEventCount(tx.MsgType)
loadtestMetrics.consumeCount.Add(context.Background(), 1, otelmetric.WithAttributes(attribute.String("msg_type", tx.MsgType)))
if !ok {
fmt.Printf("Stopping consumers\n")
return
Expand Down
5 changes: 3 additions & 2 deletions loadtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import (
"golang.org/x/time/rate"

"github.com/sei-protocol/sei-chain/app"
"github.com/sei-protocol/sei-chain/utils/metrics"
tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loadtest OTel provider never configured

Medium Severity

The loadtest binary records produce, consume, and tps via OpenTelemetry but never configures a global MeterProvider (unlike seid, which calls SetupOtelMetricsProvider). Instruments use the default no-op provider, so those metrics are dropped and no longer show up on the loadtest /metrics scrape after the legacy telemetry helpers were removed.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9685149. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not spending too much time on loadtest as the sei-load is the preferred load testing framework.

)

var TestConfig EncodingConfig
Expand Down Expand Up @@ -273,7 +274,7 @@ func printStats(
//nolint:gosec
tps := float64(sentCount-prevTotalSent) / elapsed.Seconds()
totalTps += tps
defer metrics.SetThroughputMetricByType("tps", float32(tps), msgType)
defer loadtestMetrics.tps.Record(context.Background(), tps, otelmetric.WithAttributes(attribute.String("msg_type", msgType)))
}

var totalDuration time.Duration
Expand Down
35 changes: 35 additions & 0 deletions loadtest/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,43 @@ import (

"github.com/sei-protocol/sei-chain/sei-cosmos/telemetry"
"github.com/sei-protocol/sei-chain/sei-cosmos/types/rest"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
)

var (
ltMeter = otel.Meter("loadtest")

loadtestMetrics = struct {
produceCount metric.Int64Counter
consumeCount metric.Int64Counter
tps metric.Float64Gauge
}{
produceCount: must(ltMeter.Int64Counter(
"produce",
metric.WithDescription("Number of transactions produced by message type"),
metric.WithUnit("{count}"),
)),
consumeCount: must(ltMeter.Int64Counter(
"consume",
metric.WithDescription("Number of transactions consumed by message type"),
metric.WithUnit("{count}"),
)),
tps: must(ltMeter.Float64Gauge(
"tps",
metric.WithDescription("Transactions per second by message type"),
metric.WithUnit("{tps}"),
)),
}
)

func must[V any](v V, err error) V {
if err != nil {
panic(err)
}
return v
}

const (
defaultListenAddress = "0.0.0.0"
defaultMetricsPort = 9696
Expand Down
27 changes: 27 additions & 0 deletions utils/logging/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package logging

import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
)

var (
meter = otel.Meter("utils_logging")

loggingMetrics = struct {
logNotDoneAfter metric.Int64Counter
}{
logNotDoneAfter: must(meter.Int64Counter(
"log_not_done_after",
metric.WithDescription("Number of times an operation was still not finished after the expected duration by label"),
metric.WithUnit("{count}"),
)),
}
)

func must[V any](v V, err error) V {
if err != nil {
panic(err)
}
return v
}
6 changes: 4 additions & 2 deletions utils/logging/time.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package logging

import (
"context"
"time"

"github.com/sei-protocol/sei-chain/utils/metrics"
"github.com/sei-protocol/seilog"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
)

var logger = seilog.NewLogger("utils", "logging")
Expand Down Expand Up @@ -37,7 +39,7 @@ func LogIfNotDoneAfter[R any](task func() (R, error), after time.Duration, label
// reraise panic in main goroutine
panic(err)
case <-time.After(after):
metrics.IncrLogIfNotDoneAfter(label)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function LogIfNotDoneAfter is only used in tests, so no need for keeping the older metric.

loggingMetrics.logNotDoneAfter.Add(context.Background(), 1, otelmetric.WithAttributes(attribute.String("label", label)))
logger.Error("operation still not finished", "label", label, "after", after)
}
}
Expand Down
Loading
Loading