Skip to content

Commit

Permalink
Reduce metrics cardinality, removing labels for coingecko cache metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Aug 23, 2024
1 parent ec25c08 commit c97353c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## v25.13.2

- Reduce metrics cardinality, removing labels for coingecko cache metrics.

## v25.13.1

- Fix `/config` query bug for chain handler use case returning the default that is overriden by CoinGecko pricing source.
Expand Down
26 changes: 26 additions & 0 deletions domain/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ var (
// counter that measures the number of spot price errors
SQSPricingSpotPriceErrorMetricName = "sqs_pricing_spot_price_error_total"

// sqs_pricing_coingecko_cache_hits_total
//
// counter that measures the number of pricing coingecko cache hits
SQSPricingCoingeckoCacheHitsCounterMetricName = "sqs_pricing_coingecko_cache_hits_total"

// sqs_pricing_coingecko_cache_misses_total
//
// counter that measures the number of pricing coingecko cache misses
SQSPricingCoingeckoCacheMissesCounterMetricName = "sqs_pricing_coingecko_cache_misses_total"

SQSIngestHandlerProcessBlockDurationGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: SQSIngestUsecaseProcessBlockDurationMetricName,
Expand Down Expand Up @@ -250,6 +260,20 @@ var (
Help: "Total number of spot price errors in pricing",
},
)

SQSPricingCoingeckoCacheHitsCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: SQSPricingCoingeckoCacheHitsCounterMetricName,
Help: "Total number of pricing coingecko cache hits",
},
)

SQSPricingCoingeckoCacheMissesCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: SQSPricingCoingeckoCacheMissesCounterMetricName,
Help: "Total number of pricing coingecko cache misses",
},
)
)

func init() {
Expand All @@ -271,4 +295,6 @@ func init() {
prometheus.MustRegister(SQSPricingCacheMissesCounter)
prometheus.MustRegister(SQSPricingTruncationCounter)
prometheus.MustRegister(SQSPricingSpotPriceError)
prometheus.MustRegister(SQSPricingCoingeckoCacheHitsCounter)
prometheus.MustRegister(SQSPricingCoingeckoCacheMissesCounter)
}
25 changes: 4 additions & 21 deletions tokens/usecase/pricing/coingecko/pricing_coingecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var (
cacheHitsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sqs_pricing_coingecko_cache_hits_total",
Help: "Total number of pricing coingecko cache hits",
},
[]string{"base", "quote"},
)
cacheMissesCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sqs_pricing_coingecko_cache_misses_total",
Help: "Total number of pricing coingecko cache misses",
},
[]string{"base", "quote"},
)
)

const USDC_DENOM = "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4"
const USDT_DENOM = "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB"

Expand All @@ -54,10 +37,10 @@ type coingeckoPricing struct {
}

func init() {
if err := prometheus.Register(cacheHitsCounter); err != nil {
if err := prometheus.Register(domain.SQSPricingCoingeckoCacheHitsCounter); err != nil {
panic(err)
}
if err := prometheus.Register(cacheMissesCounter); err != nil {
if err := prometheus.Register(domain.SQSPricingCoingeckoCacheMissesCounter); err != nil {
panic(err)
}
}
Expand Down Expand Up @@ -106,11 +89,11 @@ func (c *coingeckoPricing) GetPrice(ctx context.Context, baseDenom string, quote
return osmomath.BigDec{}, fmt.Errorf("invalid type cached in pricing, expected BigDec, got (%T)", cachedValue)
}
// Increase cache hits
cacheHitsCounter.WithLabelValues(baseDenom, quoteDenom).Inc()
domain.SQSPricingCoingeckoCacheHitsCounter.Inc()
return cachedBigDecPrice, nil
} else if !found {
// Increase cache misses
cacheMissesCounter.WithLabelValues(baseDenom, quoteDenom).Inc()
domain.SQSPricingCoingeckoCacheMissesCounter.Inc()
}

price, err := c.priceGetterFn(ctx, baseDenom, coingeckoId)
Expand Down

0 comments on commit c97353c

Please sign in to comment.