Skip to content

Commit

Permalink
Merge branch 'release/v1.x.x' into chore/backport-757
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 authored Dec 11, 2024
2 parents eca2ea6 + 4f4aafe commit 3db6423
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
3 changes: 2 additions & 1 deletion oracle/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
)
Expand Down
10 changes: 6 additions & 4 deletions oracle/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package log
import (
"fmt"
"os"
"strings"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -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.
Expand All @@ -40,6 +44,7 @@ func NewDefaultConfig() Config {
MaxBackups: 1,
MaxAge: 3, // 3 days
Compress: false,
LogSamplePeriod: 10 * time.Second,
}
}

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion pkg/math/oracle/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)),
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions service/clients/marketmap/types/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"fmt"

"go.uber.org/zap"

"github.com/skip-mev/slinky/oracle/config"
Expand All @@ -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 (
Expand Down

0 comments on commit 3db6423

Please sign in to comment.