Skip to content

Commit

Permalink
Merge pull request #24 from lidofinance/fix-lru-cache-names
Browse files Browse the repository at this point in the history
feat: Fix sending lru cache name
  • Loading branch information
sergeyWh1te authored Sep 26, 2024
2 parents d2e8894 + fe4c2a2 commit 35ea1cd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/app/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {
err error
)

if !w.cache.Contains(key) {
w.cache.Add(key, uint(1))
if !w.cache.Contains(countKey) {
w.cache.Add(countKey, uint(1))

count, err = w.redisClient.Incr(ctx, countKey).Uint64()
if err != nil {
Expand All @@ -256,8 +256,8 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {

return
} else {
v, _ := w.cache.Get(key)
w.cache.Add(key, v+1)
v, _ := w.cache.Get(countKey)
w.cache.Add(countKey, v+1)

count, err = w.redisClient.Get(ctx, countKey).Uint64()
if err != nil {
Expand All @@ -268,7 +268,7 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {
}
}

touchTimes, _ := w.cache.Get(key)
touchTimes, _ := w.cache.Get(countKey)

// TODO add finding.blockNumber
w.log.Info(fmt.Sprintf("Consumer: %s AlertId %s read %d times", consumer.Name, finding.AlertId, touchTimes),
Expand All @@ -290,7 +290,7 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {
},
)

if count == 1 && touchTimes == 10 {
/*if count == 1 && touchTimes == 10 {
finding.Severity = proto.Finding_UNKNOWN
finding.Description += fmt.Sprintf("\n\nWarning: Could not collect quorum. Finding.Severity downgraded to UNKNOWN")
Expand All @@ -303,7 +303,7 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {
w.ackMessage(msg)
return
}
}*/

if count >= w.quorum {
status, err := w.GetStatus(ctx, statusKey)
Expand All @@ -325,7 +325,7 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {
w.metrics.SentAlerts.With(prometheus.Labels{metrics.Channel: consumer.channel, metrics.Status: metrics.StatusOk}).Inc()
w.ackMessage(msg)

w.cache.Remove(key)
w.cache.Remove(countKey)
w.log.Info(fmt.Sprintf("Another instance already sent finding: %s", finding.AlertId))
return
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func (w *findingWorker) Run(ctx context.Context, g *errgroup.Group) error {
w.log.Error(fmt.Sprintf(`Could not delete statusKey %s: %v`, statusKey, err))
}

w.cache.Remove(key)
w.cache.Remove(countKey)

w.metrics.SentAlerts.With(prometheus.Labels{metrics.Channel: consumer.channel, metrics.Status: metrics.StatusFail}).Inc()
w.nackMessage(msg)
Expand Down

0 comments on commit 35ea1cd

Please sign in to comment.