diff --git a/go.mod b/go.mod index 7244a24e..559166db 100644 --- a/go.mod +++ b/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 diff --git a/util/progress/metricwriter.go b/util/progress/metricwriter.go index 5173b8b9..faaf9782 100644 --- a/util/progress/metricwriter.go +++ b/util/progress/metricwriter.go @@ -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") )