From 6523dccd07b130af4185c22dbdc313e58d2251ea Mon Sep 17 00:00:00 2001 From: Alex | Skip Date: Wed, 11 Dec 2024 16:32:33 -0500 Subject: [PATCH 1/2] chore: backport https://github.com/skip-mev/connect/pull/709 (#866) Co-authored-by: Eric Warehime --- oracle/init.go | 3 ++- oracle/update.go | 10 ++++++---- pkg/log/zap.go | 9 +++++++++ pkg/math/oracle/aggregator.go | 8 +++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/oracle/init.go b/oracle/init.go index d69f651f5..e7b587666 100644 --- a/oracle/init.go +++ b/oracle/init.go @@ -102,8 +102,9 @@ func (o *OracleImpl) createPriceProvider(ctx context.Context, cfg config.Provide // Add the provider to the oracle. o.priceProviders[provider.Name()] = state + // Add the provider name to the message here since we want these to ignore log sampling limits o.logger.Info( - "created price provider state", + fmt.Sprintf("created %s provider state", provider.Name()), zap.String("provider", provider.Name()), zap.Int("num_tickers", len(provider.GetIDs())), ) diff --git a/oracle/update.go b/oracle/update.go index d645f58a5..b68d4364d 100644 --- a/oracle/update.go +++ b/oracle/update.go @@ -74,8 +74,12 @@ func (o *OracleImpl) UpdateProviderState(providerTickers []types.ProviderTicker, }() } - // Update the provider's state. - o.logger.Info("updated provider state", zap.String("provider_state", provider.Name())) + // Ignore sampling limits for provider update logs via injecting provider name in message + o.logger.Info( + fmt.Sprintf("updated %s provider state", provider.Name()), + zap.String("provider", provider.Name()), + zap.Int("num_tickers", len(provider.GetIDs())), + ) return state, nil } @@ -104,8 +108,6 @@ func (o *OracleImpl) fetchAllPrices() { // update the last sync time o.metrics.AddTick() - - o.logger.Info("oracle updated prices", zap.Time("last_sync", o.lastPriceSync), zap.Int("num_prices", len(o.aggregator.GetPrices()))) } func (o *OracleImpl) fetchPrices(provider *types.PriceProvider) { diff --git a/pkg/log/zap.go b/pkg/log/zap.go index dd2c0ea66..a1e014d8e 100644 --- a/pkg/log/zap.go +++ b/pkg/log/zap.go @@ -3,6 +3,8 @@ package log import ( "fmt" "os" + "strings" + "time" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -27,6 +29,8 @@ type Config struct { MaxAge int // Compress determines if the rotated log files should be compressed. Compress bool + // LogSamplePeriod is the duration in which we de-dupe identical log messages. + LogSamplePeriod time.Duration } // NewDefaultConfig creates a default configuration for the logger. @@ -40,6 +44,7 @@ func NewDefaultConfig() Config { MaxBackups: 1, MaxAge: 3, // 3 days Compress: false, + LogSamplePeriod: 10 * time.Second, } } @@ -93,6 +98,10 @@ func NewLogger(config Config) *zap.Logger { } else { core = stdCore } + if strings.ToUpper(config.StdOutLogLevel) != zap.DebugLevel.CapitalString() && strings.ToUpper(config.FileOutLogLevel) != zap.DebugLevel.CapitalString() { + // If we're not in debug log level anywhere, filter any logs which have non-unique messages within a 10-second period + core = zapcore.NewSamplerWithOptions(core, config.LogSamplePeriod, 1, 0) + } return zap.New( core, diff --git a/pkg/math/oracle/aggregator.go b/pkg/math/oracle/aggregator.go index 7dd072439..b495db9d0 100644 --- a/pkg/math/oracle/aggregator.go +++ b/pkg/math/oracle/aggregator.go @@ -77,6 +77,8 @@ func (m *IndexPriceAggregator) AggregatePrices() { indexPrices := make(types.Prices) scaledPrices := make(types.Prices) + var missingPrices []string + for ticker, market := range m.cfg.Markets { if !market.Ticker.Enabled { m.logger.Debug("skipping disabled market", zap.Any("market", market)) @@ -92,7 +94,8 @@ func (m *IndexPriceAggregator) AggregatePrices() { // We need to have at least the minimum number of providers to calculate the median. if len(convertedPrices) < int(target.MinProviderCount) { //nolint:gosec - m.logger.Error( + missingPrices = append(missingPrices, ticker) + m.logger.Debug( "insufficient amount of converted prices", zap.String("target_ticker", ticker), zap.Int("num_converted_prices", len(convertedPrices)), @@ -127,6 +130,9 @@ func (m *IndexPriceAggregator) AggregatePrices() { // Update the aggregated data. These prices are going to be used as the index prices the // next time we calculate prices. m.logger.Debug("calculated median prices for price feeds", zap.Int("num_prices", len(indexPrices))) + if len(missingPrices) > 0 { + m.logger.Info("failed to calculate prices for price feeds", zap.Strings("missing_prices", missingPrices)) + } m.indexPrices = indexPrices m.scaledPrices = scaledPrices } From 4f4aafe7f5dbd5ce0a4d63cd16931bdf7142fa8c Mon Sep 17 00:00:00 2001 From: Alex | Skip Date: Wed, 11 Dec 2024 17:02:57 -0500 Subject: [PATCH 2/2] chore: backport https://github.com/skip-mev/connect/pull/699 (#863) Co-authored-by: Eric Warehime --- service/clients/marketmap/types/types.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/service/clients/marketmap/types/types.go b/service/clients/marketmap/types/types.go index 279bed175..fd7f38a06 100644 --- a/service/clients/marketmap/types/types.go +++ b/service/clients/marketmap/types/types.go @@ -1,8 +1,6 @@ package types import ( - "fmt" - "go.uber.org/zap" "github.com/skip-mev/slinky/oracle/config" @@ -26,7 +24,7 @@ type Chain struct { // String returns the string representation of the Chain schema. func (mms Chain) String() string { - return fmt.Sprintf("ChainID: %s", mms.ChainID) + return mms.ChainID } type (