-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads #1559
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
Add default Go runtime metrics for /gc/gogc:percent, /gc/gomemlimit:bytes, /sched/gomaxprocs:threads #1559
Changes from 12 commits
cd8445b
5d64fb7
17b3065
5d9b680
4490f8d
fb0afbe
0b3a6f0
6478f56
e4a5ade
a04c891
20ebd6c
ed4053d
b8a9eb7
23879d6
cd5a2a6
5eb377e
4a2cb15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,9 @@ | |
package prometheus | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"regexp" | ||
"runtime" | ||
"runtime/metrics" | ||
"strings" | ||
|
@@ -153,7 +155,9 @@ func defaultGoCollectorOptions() internal.GoCollectorOptions { | |
"/gc/heap/frees-by-size:bytes": goGCHeapFreesBytes, | ||
}, | ||
RuntimeMetricRules: []internal.GoCollectorRule{ | ||
//{Matcher: regexp.MustCompile("")}, | ||
{ | ||
Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, do we really need to escape |
||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -376,13 +380,13 @@ func unwrapScalarRMValue(v metrics.Value) float64 { | |
// | ||
// This should never happen because we always populate our metric | ||
// set from the runtime/metrics package. | ||
panic("unexpected unsupported metric") | ||
panic("unexpected bad kind metric") | ||
default: | ||
// Unsupported metric kind. | ||
// | ||
// This should never happen because we check for this during initialization | ||
// and flag and filter metrics whose kinds we don't understand. | ||
panic("unexpected unsupported metric kind") | ||
panic(fmt.Sprintf("unexpected unsupported metric: %v", v.Kind())) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2024 The Prometheus Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build !go1.21 | ||
// +build !go1.21 | ||
|
||
package prometheus | ||
|
||
var expMetrics = map[string]string{ | ||
bwplotka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2024 The Prometheus Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build go1.21 | ||
// +build go1.21 | ||
|
||
package prometheus | ||
|
||
var expMetrics = map[string]string{ | ||
"/gc/gogc:percent": "go_gc_gogc_percent", | ||
"/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes", | ||
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,13 @@ func addExpectedRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} | |
return metrics | ||
} | ||
|
||
func addExpectedDefaultRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} { | ||
for _, e := range expMetrics { | ||
metrics[e] = struct{}{} | ||
} | ||
return metrics | ||
} | ||
|
||
func TestGoCollector_ExposedMetrics(t *testing.T) { | ||
for _, tcase := range []struct { | ||
opts internal.GoCollectorOptions | ||
|
@@ -86,8 +93,13 @@ func TestGoCollector_ExposedMetrics(t *testing.T) { | |
expectedFQNameSet: expectedBaseMetrics(), | ||
}, | ||
{ | ||
// Default, only MemStats. | ||
expectedFQNameSet: addExpectedRuntimeMemStats(expectedBaseMetrics()), | ||
// Default, only MemStats and default Runtime metrics. | ||
opts: internal.GoCollectorOptions{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use default function then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind using our new internal.GoCollector default etc here? |
||
RuntimeMetricRules: []internal.GoCollectorRule{ | ||
{Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`)}, | ||
}, | ||
}, | ||
expectedFQNameSet: addExpectedDefaultRuntimeMetrics(addExpectedRuntimeMemStats(expectedBaseMetrics())), | ||
}, | ||
{ | ||
// Get all runtime/metrics without MemStats. | ||
|
Uh oh!
There was an error while loading. Please reload this page.