mirror of https://github.com/docker/buildx.git
metrics: measure export image operation
This measures the amount of time it takes to export to a specific format. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
parent
d410597f5a
commit
a0cce9b31e
|
@ -25,6 +25,7 @@ func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
|
||||||
newLocalSourceTransferMetricRecorder(meter, attrs),
|
newLocalSourceTransferMetricRecorder(meter, attrs),
|
||||||
newImageSourceTransferMetricRecorder(meter, attrs),
|
newImageSourceTransferMetricRecorder(meter, attrs),
|
||||||
newExecMetricRecorder(meter, attrs),
|
newExecMetricRecorder(meter, attrs),
|
||||||
|
newExportImageMetricRecorder(meter, attrs),
|
||||||
},
|
},
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
}
|
}
|
||||||
|
@ -276,3 +277,59 @@ var reExecType = regexp.MustCompile(`^\[.*] RUN `)
|
||||||
func detectExecType(vertexName string) bool {
|
func detectExecType(vertexName string) bool {
|
||||||
return reExecType.MatchString(vertexName)
|
return reExecType.MatchString(vertexName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
exportImageMetricRecorder struct {
|
||||||
|
// Attributes holds the attributes for the export image metric.
|
||||||
|
Attributes attribute.Set
|
||||||
|
|
||||||
|
// Duration tracks the duration of image exporting.
|
||||||
|
Duration metric.Float64Counter
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newExportImageMetricRecorder(meter metric.Meter, attrs attribute.Set) *exportImageMetricRecorder {
|
||||||
|
mr := &exportImageMetricRecorder{
|
||||||
|
Attributes: attrs,
|
||||||
|
}
|
||||||
|
mr.Duration, _ = meter.Float64Counter("export.image.time",
|
||||||
|
metric.WithDescription("Measures the length of time spent exporting the image."),
|
||||||
|
metric.WithUnit("ms"))
|
||||||
|
return mr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mr *exportImageMetricRecorder) Record(ss *client.SolveStatus) {
|
||||||
|
for _, v := range ss.Vertexes {
|
||||||
|
if v.Started == nil || v.Completed == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
format := detectExportImageType(v.Name)
|
||||||
|
if format == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dur := float64(v.Completed.Sub(*v.Started)) / float64(time.Millisecond)
|
||||||
|
mr.Duration.Add(context.Background(), dur,
|
||||||
|
metric.WithAttributeSet(mr.Attributes),
|
||||||
|
metric.WithAttributes(
|
||||||
|
attribute.String("image.format", format),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var reExportImageType = regexp.MustCompile(`^exporting to (image|(?P<format>\w+) image format)$`)
|
||||||
|
|
||||||
|
func detectExportImageType(vertexName string) string {
|
||||||
|
m := reExportImageType.FindStringSubmatch(vertexName)
|
||||||
|
if m == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
format := "docker"
|
||||||
|
if m[2] != "" {
|
||||||
|
format = m[2]
|
||||||
|
}
|
||||||
|
return format
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue