Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added metric for ooo lag for each datapoint #534

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion carbon/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ func (app *App) startPersister() {
p.SetRemoveEmptyFile(app.Config.Whisper.RemoveEmptyFile)
p.SetWorkers(app.Config.Whisper.Workers)
p.SetHashFilenames(app.Config.Whisper.HashFilenames)

if app.Config.Prometheus.Enabled {
p.InitPrometheus(app.PromRegisterer)
}
if app.Tags != nil {
p.SetTagsEnabled(true)
p.SetTaggedFn(app.Tags.Add)
Expand Down
39 changes: 37 additions & 2 deletions persister/whisper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"syscall"
"time"

"github.com/prometheus/client_golang/prometheus"

whisper "github.com/go-graphite/go-whisper"
"go.uber.org/zap"

Expand Down Expand Up @@ -77,14 +79,20 @@ type Whisper struct {
logicalSizeChanges int64
}
}

prometheus whisperPrometheus
// blockThrottleNs uint64 // sum ns counter
// blockQueueGetNs uint64 // sum ns counter
// blockAvoidConcurrentNs uint64 // sum ns counter
// blockUpdateManyNs uint64 // sum ns counter
}

// NewWhisper create instance of Whisper
type whisperPrometheus struct {
enabled bool
outOfOrderWritesLags prometheus.Histogram
auguzun marked this conversation as resolved.
Show resolved Hide resolved
outOfOrderWritesLag func(time.Duration)
}

func NewWhisper(
rootPath string,
schemas WhisperSchemas,
Expand All @@ -108,6 +116,23 @@ func NewWhisper(
}
}

func (p *Whisper) InitPrometheus(reg prometheus.Registerer) {
p.prometheus = whisperPrometheus{
enabled: true,
outOfOrderWritesLags: prometheus.NewHistogram(
prometheus.HistogramOpts{
Name: "out_of_order_writes_lag_exp",
Help: "Lag for incoming datapoints (exponential buckets)",
Buckets: prometheus.ExponentialBuckets(time.Millisecond.Seconds(), 2.0, 30),
},
),
}
p.prometheus.outOfOrderWritesLag = func(t time.Duration) {
p.prometheus.outOfOrderWritesLags.Observe(t.Seconds())
}
reg.MustRegister(p.prometheus.outOfOrderWritesLags)
}

// SetOnlineMigration enable online migration
func (p *Whisper) EnableOnlineMigration(rate int, scope []string) {
p.onlineMigration.enabled = true
Expand Down Expand Up @@ -188,7 +213,16 @@ func fnv32(key string) uint32 {
}
return hash
}

func (p *Whisper) registerOutOfOrderLags(points []*whisper.TimeSeriesPoint) {
auguzun marked this conversation as resolved.
Show resolved Hide resolved
if !p.prometheus.enabled {
return
}
now := time.Now()
for _, point := range points {
lag := now.Sub(time.Unix(int64(point.Time), 0))
p.prometheus.outOfOrderWritesLag(lag)
}
}
func (p *Whisper) updateMany(w *whisper.Whisper, path string, points []*whisper.TimeSeriesPoint) {
defer func() {
if r := recover(); r != nil {
Expand All @@ -200,6 +234,7 @@ func (p *Whisper) updateMany(w *whisper.Whisper, path string, points []*whisper.
}()

// start = time.Now()
p.registerOutOfOrderLags(points)
auguzun marked this conversation as resolved.
Show resolved Hide resolved
if err := w.UpdateMany(points); err != nil {
p.logger.Error("fail to update metric",
zap.String("path", path),
Expand Down