Skip to content

Addressed comments #1

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
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 33 additions & 9 deletions prometheus/gen_go_collector_metrics_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,29 @@ func main() {
v := goVersion(gv.Segments()[1])
log.Printf("generating metrics for Go version %q", v)

allDesc := metrics.All()

// Find default metrics.
var defaultDesc []metrics.Description
for _, d := range allDesc {
if !internal.GoCollectorDefaultRuntimeMetrics.MatchString(d.Name) {
continue
}
defaultDesc = append(defaultDesc, d)
}

// Generate code.
var buf bytes.Buffer
err = testFile.Execute(&buf, struct {
Descriptions []metrics.Description
GoVersion goVersion
Cardinality int
AllDescriptions []metrics.Description
DefaultDescriptions []metrics.Description
GoVersion goVersion
Cardinality int
}{
Descriptions: metrics.All(),
GoVersion: v,
Cardinality: rmCardinality(),
AllDescriptions: allDesc,
DefaultDescriptions: defaultDesc,
GoVersion: v,
Cardinality: rmCardinality(),
})
if err != nil {
log.Fatalf("executing template: %v", err)
Expand Down Expand Up @@ -167,14 +180,25 @@ var testFile = template.Must(template.New("testFile").Funcs(map[string]interface

package prometheus

var expectedRuntimeMetrics = map[string]string{
{{- range .Descriptions -}}
var (
expectedRuntimeMetrics = map[string]string{
{{- range .AllDescriptions -}}
{{- $trans := rm2prom . -}}
{{- if ne $trans "" }}
{{.Name | printf "%q"}}: {{$trans | printf "%q"}},
{{- end -}}
{{end}}
}
}

expMetrics = map[string]string{
{{- range .DefaultDescriptions -}}
{{- $trans := rm2prom . -}}
{{- if ne $trans "" }}
{{.Name | printf "%q"}}: {{$trans | printf "%q"}},
{{- end -}}
{{end}}
}
)

const expectedRuntimeMetricsCardinality = {{.Cardinality}}
`))
6 changes: 2 additions & 4 deletions prometheus/go_collector_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package prometheus
import (
"fmt"
"math"
"regexp"
"runtime"
"runtime/metrics"
"strings"
Expand Down Expand Up @@ -155,9 +154,8 @@ func defaultGoCollectorOptions() internal.GoCollectorOptions {
"/gc/heap/frees-by-size:bytes": goGCHeapFreesBytes,
},
RuntimeMetricRules: []internal.GoCollectorRule{
{
Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`),
},
// Recommended metrics we want by default from runtime/metrics.
{Matcher: internal.GoCollectorDefaultRuntimeMetrics},
},
}
}
Expand Down
21 changes: 0 additions & 21 deletions prometheus/go_collector_latest_go120_test.go

This file was deleted.

23 changes: 0 additions & 23 deletions prometheus/go_collector_latest_go121_test.go

This file was deleted.

100 changes: 53 additions & 47 deletions prometheus/go_collector_metrics_go120_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading