Skip to content

Commit

Permalink
Add log when limits exceed
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Jan 16, 2025
1 parent ee51a19 commit e7da9c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions exporter/metadataexporter/cache/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func (c *InMemoryKeyCache) AddAttrsToResource(ctx context.Context, resourceFp ui
if entry == nil {
// Check how many total resources are in the cache
if uint64(len(cache.Keys())) >= maxResourceCount {
return fmt.Errorf("too many resource fingerprints in %s cache", ds.String())
c.logger.Info("too many resource fingerprints in cache", zap.String("datasource", ds.String()), zap.Uint64("maxResourceCount", maxResourceCount))
return nil
}
// Create a new resource entry
newEntry := &resourceEntry{
Expand All @@ -143,8 +144,8 @@ func (c *InMemoryKeyCache) AddAttrsToResource(ctx context.Context, resourceFp ui

// Check if adding these attributes will exceed the limit
if uint64(len(entry.Value().attrs))+uint64(len(attrFps)) > maxAttrCount {
return fmt.Errorf("too many attribute fingerprints for resource %d in %s cache",
resourceFp, ds.String())
c.logger.Info("too many attribute fingerprints for resource", zap.Uint64("resourceFp", resourceFp), zap.String("datasource", ds.String()), zap.Uint64("maxAttrCount", maxAttrCount))
return nil
}

for _, a := range attrFps {
Expand Down
7 changes: 4 additions & 3 deletions exporter/metadataexporter/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ func (c *RedisKeyCache) AddAttrsToResource(ctx context.Context, resourceFp uint6
return err
}
if card >= int64(c.getMaxResourceFp(ds)) {
return fmt.Errorf("too many resource fingerprints in %s cache", ds.String())
c.logger.Info("too many resource fingerprints in cache", zap.String("datasource", ds.String()), zap.Uint64("maxResourceCount", c.getMaxResourceFp(ds)))
return nil
}
pipe.SAdd(ctx, resourceSetKey, resourceFpStr)
pipe.Expire(ctx, resourceSetKey, ttl)
Expand All @@ -197,8 +198,8 @@ func (c *RedisKeyCache) AddAttrsToResource(ctx context.Context, resourceFp uint6
return err
}
if card+int64(len(attrFps)) > int64(c.getMaxAttrs(ds)) {
return fmt.Errorf("too many attribute fingerprints for resource %d in %s cache",
resourceFp, ds.String())
c.logger.Info("too many attribute fingerprints for resource", zap.Uint64("resourceFp", resourceFp), zap.String("datasource", ds.String()), zap.Uint64("maxAttrCount", c.getMaxAttrs(ds)))
return nil
}

// Convert each attrFp to string
Expand Down
7 changes: 4 additions & 3 deletions exporter/metadataexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metadataexporter

import (
"context"
"fmt"
"strings"
"sync/atomic"
"time"
Expand Down Expand Up @@ -472,13 +471,15 @@ func (e *metadataExporter) writeToStatementBatch(ctx context.Context, stmt drive
resourcesLimitCheckStart := time.Now()
// check max resources limit
if e.keyCache.ResourcesLimitExceeded(ctx, ds) {
return 0, fmt.Errorf("resource limit exceeded")
e.set.Logger.Info("resource limit exceeded", zap.String("datasource", ds.String()), zap.Int("records", len(records)))
return 0, nil
}
resourcesLimitCheckDuration = time.Since(resourcesLimitCheckStart)

totalCardinalityLimitCheckStart := time.Now()
if e.keyCache.TotalCardinalityLimitExceeded(ctx, ds) {
return 0, fmt.Errorf("total cardinality limit exceeded")
e.set.Logger.Info("total cardinality limit exceeded", zap.String("datasource", ds.String()), zap.Int("records", len(records)))
return 0, nil
}
totalCardinalityLimitCheckDuration = time.Since(totalCardinalityLimitCheckStart)

Expand Down

0 comments on commit e7da9c0

Please sign in to comment.