-
Notifications
You must be signed in to change notification settings - Fork 239
feat: add metrics to payload disperser #1441
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
904cb6c
Add metrics to payload disperser.
cody-littley 19fb6a6
fix labels
cody-littley 2b749e3
capture all stages of dispersal in metrics
cody-littley ea581f1
update metric names
cody-littley b23bc28
properly register metrics
cody-littley fc6eb6b
Capture more metrics.
cody-littley 0706240
better locking
cody-littley 4317129
fix QUEUED status
cody-littley 30df50d
Made suggested changes.
cody-littley 51fcbac
fix nil pointer error
cody-littley 0aa09e1
move thigns around
cody-littley 25286b6
ordering
cody-littley 62689bd
made suggested changes
cody-littley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package common | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
// It may be helpful to generalize this utility to be used in other parts of the codebase. For a future PR, perhaps. | ||
|
||
// StageTimer encapsulates metrics to help track the time spent in each stage of the payload dispersal process. | ||
type StageTimer struct { | ||
stageCount *prometheus.GaugeVec | ||
stageLatency *prometheus.SummaryVec | ||
} | ||
|
||
// SequenceProbe tracks the timing of a single sequence of operations. Multiple sequences can be tracked concurrently. | ||
litt3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type SequenceProbe struct { | ||
stageTimer *StageTimer | ||
currentStage string | ||
currentStageStart time.Time | ||
} | ||
|
||
// NewStageTimer creates a new stageTimer with the given prefix and name. | ||
func NewStageTimer(registry *prometheus.Registry, prefix, name string) *StageTimer { | ||
if registry == nil { | ||
return nil | ||
} | ||
|
||
statusLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: prefix, | ||
Name: name + "_stage_latency_ms", | ||
Help: "the latency of each type of operation", | ||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, | ||
}, | ||
[]string{"stage"}, | ||
) | ||
|
||
statusCount := promauto.With(registry).NewGaugeVec( | ||
litt3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prometheus.GaugeOpts{ | ||
Namespace: prefix, | ||
Name: name + "_stage_count", | ||
Help: "the number of operations with a specific status", | ||
}, | ||
[]string{"stage"}, | ||
) | ||
|
||
return &StageTimer{ | ||
stageLatency: statusLatency, | ||
stageCount: statusCount, | ||
} | ||
} | ||
|
||
// NewSequence creates a new sequenceProbe with the given initial status. | ||
func (s *StageTimer) NewSequence(initialStatus string) *SequenceProbe { | ||
if s == nil { | ||
return nil | ||
} | ||
|
||
s.stageCount.WithLabelValues(initialStatus).Inc() | ||
return &SequenceProbe{ | ||
stageTimer: s, | ||
currentStage: initialStatus, | ||
currentStageStart: time.Now(), | ||
litt3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// SetStage updates the status of the current sequence. | ||
func (p *SequenceProbe) SetStage(stage string) { | ||
if p == nil { | ||
return | ||
} | ||
if p.currentStage == stage { | ||
return | ||
} | ||
|
||
now := time.Now() | ||
elapsed := now.Sub(p.currentStageStart) | ||
p.stageTimer.stageLatency.WithLabelValues(p.currentStage).Observe(ToMilliseconds(elapsed)) | ||
p.currentStageStart = now | ||
|
||
p.stageTimer.stageCount.WithLabelValues(p.currentStage).Dec() | ||
p.stageTimer.stageCount.WithLabelValues(stage).Inc() | ||
p.currentStage = stage | ||
} | ||
|
||
// End completes the current sequence. It is important to call this before discarding the sequenceProbe. | ||
func (p *SequenceProbe) End() { | ||
if p == nil { | ||
return | ||
} | ||
|
||
now := time.Now() | ||
elapsed := now.Sub(p.currentStageStart) | ||
p.stageTimer.stageLatency.WithLabelValues(p.currentStage).Observe(ToMilliseconds(elapsed)) | ||
|
||
p.stageTimer.stageCount.WithLabelValues(p.currentStage).Dec() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.