grafana/loki

Replace `go.uber.go/atomic` with Go standard library `sync/atomic`

Aberta

#20.673 aberto em 4 de fev. de 2026

 (6 comentários) (0 reação) (0 responsável)Go (3.997 forks)batch import
good first issue

Métricas do repositório

Stars
 (28.187 estrelas)
Métricas de merge de PR
 (Mesclagem média 5d 20h) (522 fundiu PRs em 30d)

Description

Summary

We currently have a linter rule that blocks usage of sync/atomic and forces us to use go.uber.go/atomic instead. This rule was originally added because sync/atomic required atomic operations on primitive types, which was considered error-prone.

However, since Go 1.19, the standard library sync/atomic package now includes typed wrappers (e.g., atomic.Uint32, atomic.Int64, atomic.Bool, etc.) that provide the same safety guarantees as go.uber.go/atomic. This makes the uber package redundant.

Context

Prometheus is also making this transition:

Proposed Changes

  1. Remove the linter rule that blocks sync/atomic
  2. Migrate all go.uber.go/atomic usage to the standard library sync/atomic typed wrappers
  3. Configure a linter rule to block the old-style atomic functions that operate on primitive types (e.g., atomic.AddInt64, atomic.LoadUint32) to ensure we only use the new typed wrappers and avoid accidental misuse

This approach gives us:

  • Fewer external dependencies
  • Alignment with the broader Go ecosystem
  • Same safety guarantees we had with uber/atomic

References

Guia do colaborador