mirror of https://github.com/docker/buildx.git
Update the lint metrics to match agains the rule URL rather than a prefix on the lint rule
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
This commit is contained in:
parent
ab835fd904
commit
9fdc99dc76
2
go.mod
2
go.mod
|
@ -49,6 +49,7 @@ require (
|
|||
golang.org/x/sync v0.6.0
|
||||
golang.org/x/sys v0.18.0
|
||||
golang.org/x/term v0.18.0
|
||||
golang.org/x/text v0.14.0
|
||||
google.golang.org/grpc v1.59.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
k8s.io/api v0.29.2
|
||||
|
@ -160,7 +161,6 @@ require (
|
|||
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
|
||||
golang.org/x/net v0.23.0 // indirect
|
||||
golang.org/x/oauth2 v0.11.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
golang.org/x/tools v0.17.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
"github.com/opencontainers/go-digest"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
type metricWriter struct {
|
||||
|
@ -446,14 +448,22 @@ func newLintMetricRecorder(meter metric.Meter, attrs attribute.Set) *lintMetricR
|
|||
return mr
|
||||
}
|
||||
|
||||
func kebabToCamel(s string) string {
|
||||
words := strings.Split(s, "-")
|
||||
for i, word := range words {
|
||||
words[i] = cases.Title(language.English).String(word)
|
||||
}
|
||||
return strings.Join(words, "")
|
||||
}
|
||||
|
||||
func (mr *lintMetricRecorder) Record(ss *client.SolveStatus) {
|
||||
for _, warning := range ss.Warnings {
|
||||
m := reLintMessage.FindSubmatch(warning.Short)
|
||||
m := reLintMessage.FindSubmatch([]byte(warning.URL))
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ruleName := string(m[1])
|
||||
ruleName := kebabToCamel(string(m[1]))
|
||||
mr.Count.Add(context.Background(), 1,
|
||||
metric.WithAttributeSet(mr.Attributes),
|
||||
metric.WithAttributes(
|
||||
|
@ -464,6 +474,6 @@ func (mr *lintMetricRecorder) Record(ss *client.SolveStatus) {
|
|||
}
|
||||
|
||||
var (
|
||||
reLintMessage = regexp.MustCompile(`^Lint Rule '(\w+)':`)
|
||||
reLintMessage = regexp.MustCompile(`^https://docs\.docker\.com/go/dockerfile/rule/([\w|-]+)/`)
|
||||
lintRuleNameProperty = attribute.Key("lint.rule.name")
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue