Skip to content

Commit

Permalink
metrics: measure run operations for exec operations
Browse files Browse the repository at this point in the history
This measures the duration of exec operations. It does not factor in
whether the operation was cached or not so this should include the
amount of time to determine whether an operation was cached.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
  • Loading branch information
jsternberg committed Mar 6, 2024
1 parent 9ebfde4 commit 356856c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions util/progress/metricwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
return &metricWriter{
recorders: []metricRecorder{
newLocalSourceTransferMetricRecorder(meter, attrs),
newExecMetricRecorder(meter, attrs),
},
attrs: attrs,
}
Expand Down Expand Up @@ -149,3 +150,37 @@ func detectLocalSourceType(vertexName string) attribute.KeyValue {
// No matches found.
return attribute.KeyValue{}
}

type (
execMetricRecorder struct {
BaseAttributes attribute.Set
Duration metric.Float64Counter
}
)

func newExecMetricRecorder(meter metric.Meter, attrs attribute.Set) *execMetricRecorder {
mr := &execMetricRecorder{
BaseAttributes: attrs,
}
mr.Duration, _ = meter.Float64Counter("exec.command.time",
metric.WithDescription("Measures the length of time spent executing run statements."),
metric.WithUnit("ms"))
return mr
}

func (mr *execMetricRecorder) Record(ss *client.SolveStatus) {
for _, v := range ss.Vertexes {
if v.Started == nil || v.Completed == nil || !detectExecType(v.Name) {
continue
}

dur := float64(v.Completed.Sub(*v.Started)) / float64(time.Millisecond)
mr.Duration.Add(context.Background(), dur, metric.WithAttributeSet(mr.BaseAttributes))
}
}

var reExecType = regexp.MustCompile(`^\[.*] RUN `)

func detectExecType(vertexName string) bool {
return reExecType.MatchString(vertexName)
}

0 comments on commit 356856c

Please sign in to comment.