Skip to content

Commit

Permalink
Addressed comments on Arianna's PR.
Browse files Browse the repository at this point in the history
Signed-off-by: bwplotka <[email protected]>
  • Loading branch information
bwplotka committed Aug 9, 2024
1 parent b8a9eb7 commit 9b3aee9
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 260 deletions.
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

0 comments on commit 9b3aee9

Please sign in to comment.