Skip to content
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

Add cache limits for resources and attributes #509

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Disable debug by default
  • Loading branch information
srikanthccv committed Jan 16, 2025
commit 2889b3804f0033aee49c175c7553eb7bacfeb369
9 changes: 9 additions & 0 deletions exporter/metadataexporter/cache/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type InMemoryKeyCacheOptions struct {

TenantID string
Logger *zap.Logger

Debug bool
}

type InMemoryKeyCache struct {
Expand All @@ -59,6 +61,8 @@ type InMemoryKeyCache struct {

tenantID string
logger *zap.Logger

debug bool
}

var _ KeyCache = (*InMemoryKeyCache)(nil)
Expand Down Expand Up @@ -102,6 +106,7 @@ func NewInMemoryKeyCache(opts InMemoryKeyCacheOptions) (*InMemoryKeyCache, error

tenantID: opts.TenantID,
logger: opts.Logger,
debug: opts.Debug,
}, nil
}

Expand Down Expand Up @@ -215,6 +220,10 @@ func (c *InMemoryKeyCache) CardinalityLimitExceeded(ctx context.Context, resourc
}

func (c *InMemoryKeyCache) Debug(ctx context.Context) {
if !c.debug {
return
}

c.logger.Debug("IN MEMORY KEY CACHE DEBUG")

dump := func(name string, cache *ttlcache.Cache[uint64, *resourceEntry]) {
Expand Down
10 changes: 10 additions & 0 deletions exporter/metadataexporter/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type RedisKeyCache struct {
tracesMaxTotalCardinality uint64
metricsMaxTotalCardinality uint64
logsMaxTotalCardinality uint64

debug bool
}

type RedisKeyCacheOptions struct {
Expand Down Expand Up @@ -61,6 +63,8 @@ type RedisKeyCacheOptions struct {
TracesMaxTotalCardinality uint64
MetricsMaxTotalCardinality uint64
LogsMaxTotalCardinality uint64

Debug bool
}

var _ KeyCache = (*RedisKeyCache)(nil)
Expand Down Expand Up @@ -103,6 +107,8 @@ func NewRedisKeyCache(opts RedisKeyCacheOptions) (*RedisKeyCache, error) {
tracesMaxTotalCardinality: opts.TracesMaxTotalCardinality,
metricsMaxTotalCardinality: opts.MetricsMaxTotalCardinality,
logsMaxTotalCardinality: opts.LogsMaxTotalCardinality,

debug: opts.Debug,
}, nil
}

Expand Down Expand Up @@ -322,6 +328,10 @@ func (c *RedisKeyCache) CardinalityLimitExceededMulti(ctx context.Context, resou
// Debug prints the keys that match the metadata pattern, plus each set’s cardinality.
// (Doesn’t print HLL counts, but you could add that easily with PFCount calls.)
func (c *RedisKeyCache) Debug(ctx context.Context) {
if !c.debug {
return
}

c.logger.Debug("DEBUGGING REDIS KEY CACHE")
pattern := fmt.Sprintf("%s:metadata:*", c.tenantID)
keys, err := c.redisClient.Keys(ctx, pattern).Result()
Expand Down
3 changes: 3 additions & 0 deletions exporter/metadataexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type CacheConfig struct {
Traces CacheLimits `mapstructure:"traces_limits"`
Metrics CacheLimits `mapstructure:"metrics_limits"`
Logs CacheLimits `mapstructure:"logs_limits"`
// Iterate over all the keys in the cache and print the cardinality
// Since this is expensive, it is disabled by default
Debug bool `mapstructure:"debug"`
}

// Config defines configuration for Metadata exporter.
Expand Down
2 changes: 2 additions & 0 deletions exporter/metadataexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func newMetadataExporter(cfg Config, set exporter.Settings) (*metadataExporter,
TracesMaxTotalCardinality: cfg.Cache.Traces.MaxTotalCardinality,
MetricsMaxTotalCardinality: cfg.Cache.Metrics.MaxTotalCardinality,
LogsMaxTotalCardinality: cfg.Cache.Logs.MaxTotalCardinality,
Debug: cfg.Cache.Debug,
})
} else {
keyCache, cacheErr = kash.NewInMemoryKeyCache(kash.InMemoryKeyCacheOptions{
Expand All @@ -137,6 +138,7 @@ func newMetadataExporter(cfg Config, set exporter.Settings) (*metadataExporter,
TracesMaxTotalCardinality: cfg.Cache.Traces.MaxTotalCardinality,
MetricsMaxTotalCardinality: cfg.Cache.Metrics.MaxTotalCardinality,
LogsMaxTotalCardinality: cfg.Cache.Logs.MaxTotalCardinality,
Debug: cfg.Cache.Debug,
})
}

Expand Down
1 change: 1 addition & 0 deletions exporter/metadataexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func createDefaultConfig() component.Config {
MaxCardinalityPerResource: DefaultMaxCardinalityPerResource,
MaxTotalCardinality: DefaultMaxTotalCardinality,
},
Debug: false,
},
Enabled: false,
}
Expand Down
Loading