Skip to content

Update the lint metrics to match agains the rule URL #2507

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 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions util/progress/metricwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"github.com/opencontainers/go-digest"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"golang.org/x/text/cases"

Check failure on line 16 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu-22.04)

cannot find module providing package golang.org/x/text/cases: import lookup disabled by -mod=vendor

Check failure on line 16 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu-22.04)

cannot find module providing package golang.org/x/text/cases: import lookup disabled by -mod=vendor

Check failure on line 16 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (macos-12)

cannot find module providing package golang.org/x/text/cases: import lookup disabled by -mod=vendor

Check failure on line 16 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (macos-12)

cannot find module providing package golang.org/x/text/cases: import lookup disabled by -mod=vendor

Check failure on line 16 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (windows-2022)

cannot find module providing package golang.org/x/text/cases: import lookup disabled by -mod=vendor

Check failure on line 16 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (windows-2022)

cannot find module providing package golang.org/x/text/cases: import lookup disabled by -mod=vendor
"golang.org/x/text/language"

Check failure on line 17 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu-22.04)

cannot find module providing package golang.org/x/text/language: import lookup disabled by -mod=vendor

Check failure on line 17 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu-22.04)

cannot find module providing package golang.org/x/text/language: import lookup disabled by -mod=vendor

Check failure on line 17 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (macos-12)

cannot find module providing package golang.org/x/text/language: import lookup disabled by -mod=vendor

Check failure on line 17 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (macos-12)

cannot find module providing package golang.org/x/text/language: import lookup disabled by -mod=vendor

Check failure on line 17 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (windows-2022)

cannot find module providing package golang.org/x/text/language: import lookup disabled by -mod=vendor

Check failure on line 17 in util/progress/metricwriter.go

View workflow job for this annotation

GitHub Actions / test-unit (windows-2022)

cannot find module providing package golang.org/x/text/language: import lookup disabled by -mod=vendor
)

type metricWriter struct {
Expand Down Expand Up @@ -446,14 +448,22 @@
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(
Expand All @@ -464,6 +474,6 @@
}

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