Skip to content

Commit 13fea45

Browse files
authored
Improve data accuracy in Otterize Cloud by periodically re-reporting data (#310)
1 parent 3d06360 commit 13fea45

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/mapper/pkg/metrics_collection_traffic/metrics_collection_traffic_cache.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
"github.com/spf13/viper"
1212
"golang.org/x/exp/slices"
1313
"hash/crc32"
14+
"time"
15+
)
16+
17+
const (
18+
cacheTTL = 5 * time.Hour
1419
)
1520

1621
type CacheValue []byte
@@ -21,9 +26,7 @@ type MetricsCollectionTrafficCache struct {
2126

2227
func NewMetricsCollectionTrafficCache() *MetricsCollectionTrafficCache {
2328
size := viper.GetInt(config.MetricsCollectionTrafficCacheSizeKey)
24-
// We don't want the cache to expire. It does not contain a lot of data, and we want to keep it as long as possible
25-
// so we won't send unnecessary requests to the cloud.
26-
cache := expirable.NewLRU[string, CacheValue](size, OnEvict, 0)
29+
cache := expirable.NewLRU[string, CacheValue](size, OnEvict, cacheTTL)
2730

2831
return &MetricsCollectionTrafficCache{
2932
cache: cache,

src/mapper/pkg/webhook_traffic/webhook_services_cache.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
"time"
1515
)
1616

17+
const (
18+
cacheTTL = 5 * time.Hour
19+
)
20+
1721
type CacheValue []byte
1822

1923
type WebhookServicesCache struct {
@@ -22,7 +26,7 @@ type WebhookServicesCache struct {
2226

2327
func NewWebhookServicesCache() *WebhookServicesCache {
2428
size := viper.GetInt(config.WebhookServicesCacheSizeKey)
25-
cache := expirable.NewLRU[string, CacheValue](size, OnEvict, 5*time.Hour)
29+
cache := expirable.NewLRU[string, CacheValue](size, OnEvict, cacheTTL)
2630

2731
return &WebhookServicesCache{
2832
cache: cache,

0 commit comments

Comments
 (0)