Skip to content

Commit

Permalink
Merge pull request #6 from grafana/fix_ttl
Browse files Browse the repository at this point in the history
Fix race condition and add to testing.
  • Loading branch information
mattdurham authored Dec 2, 2024
2 parents 83ac26b + 5f1bc0a commit 6ec70ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: Install dependencies
run: go mod vendor
- name: Test with the Go CLI
run: go test ./...
run: go test --race ./...
13 changes: 7 additions & 6 deletions implementations/prometheus/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package prometheus
import (
"github.com/grafana/walqueue/types"
"github.com/prometheus/client_golang/prometheus"
"sync/atomic"
)

type PrometheusStats struct {
serializerIn int64
networkOut int64
serializerIn atomic.Int64
networkOut atomic.Int64
register prometheus.Registerer
// Network Stats
NetworkSeriesSent prometheus.Counter
Expand Down Expand Up @@ -267,8 +268,8 @@ func (s *PrometheusStats) UpdateNetwork(stats types.NetworkStats) {
s.RemoteStorageDuration.Observe(stats.SendDuration.Seconds())
// The newest timestamp is no always sent.
if stats.NewestTimestampSeconds != 0 {
s.networkOut = stats.NewestTimestampSeconds
s.TimestampDriftSeconds.Set(float64(s.serializerIn - s.networkOut))
s.networkOut.Store(stats.NewestTimestampSeconds)
s.TimestampDriftSeconds.Set(float64(s.serializerIn.Load() - s.networkOut.Load()))
s.RemoteStorageOutTimestamp.Set(float64(stats.NewestTimestampSeconds))
s.NetworkNewestOutTimeStampSeconds.Set(float64(stats.NewestTimestampSeconds))
}
Expand All @@ -294,8 +295,8 @@ func (s *PrometheusStats) UpdateSerializer(stats types.SerializerStats) {
s.SerializerInSeries.Add(float64(stats.MetadataStored))
s.SerializerErrors.Add(float64(stats.Errors))
if stats.NewestTimestampSeconds != 0 {
s.serializerIn = stats.NewestTimestampSeconds
s.TimestampDriftSeconds.Set(float64(s.serializerIn - s.networkOut))
s.serializerIn.Store(stats.NewestTimestampSeconds)
s.TimestampDriftSeconds.Set(float64(s.serializerIn.Load() - s.networkOut.Load()))
s.SerializerNewestInTimeStampSeconds.Set(float64(stats.NewestTimestampSeconds))
s.RemoteStorageInTimestamp.Set(float64(stats.NewestTimestampSeconds))
}
Expand Down

0 comments on commit 6ec70ef

Please sign in to comment.