File tree Expand file tree Collapse file tree 6 files changed +15
-7
lines changed
Filter options
pkg/kubelet/metrics/collectors Expand file tree Collapse file tree 6 files changed +15
-7
lines changed
Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ func (c *criMetricsCollector) DescribeWithStability(ch chan<- *metrics.Desc) {
70
70
// Collect implements the metrics.CollectWithStability interface.
71
71
// TODO(haircommander): would it be better if these were processed async?
72
72
func (c * criMetricsCollector ) CollectWithStability (ch chan <- metrics.Metric ) {
73
+ // Use context.TODO() because we currently do not have a proper context to pass in.
74
+ // Replace this with an appropriate context when refactoring this function to accept a context parameter.
73
75
ctx := context .TODO ()
74
76
logger := klog .FromContext (ctx )
75
77
podMetrics , err := c .listPodSandboxMetricsFn (ctx )
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ func (c *logMetricsCollector) DescribeWithStability(ch chan<- *metrics.Desc) {
63
63
64
64
// CollectWithStability implements the metrics.StableCollector interface.
65
65
func (c * logMetricsCollector ) CollectWithStability (ch chan <- metrics.Metric ) {
66
+ // Use context.TODO() because we currently do not have a proper context to pass in.
67
+ // Replace this with an appropriate context when refactoring this function to accept a context parameter.
66
68
ctx := context .TODO ()
67
69
logger := klog .FromContext (ctx )
68
70
podStats , err := c .podStats (ctx )
Original file line number Diff line number Diff line change @@ -149,7 +149,9 @@ func (rc *resourceMetricsCollector) DescribeWithStability(ch chan<- *metrics.Des
149
149
// leak metric collectors for containers or pods that no longer exist. Instead, implement
150
150
// custom collector in a way that only collects metrics for active containers.
151
151
func (rc * resourceMetricsCollector ) CollectWithStability (ch chan <- metrics.Metric ) {
152
- ctx := context .Background ()
152
+ // Use context.TODO() because we currently do not have a proper context to pass in.
153
+ // Replace this with an appropriate context when refactoring this function to accept a context parameter.
154
+ ctx := context .TODO ()
153
155
var errorCount float64
154
156
defer func () {
155
157
ch <- metrics .NewLazyConstMetric (resourceScrapeResultDesc , metrics .GaugeValue , errorCount )
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ limitations under the License.
17
17
package collectors
18
18
19
19
import (
20
- "context"
21
20
"fmt"
22
21
"strings"
23
22
"testing"
@@ -27,6 +26,7 @@ import (
27
26
"k8s.io/component-base/metrics/testutil"
28
27
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
29
28
summaryprovidertest "k8s.io/kubernetes/pkg/kubelet/server/stats/testing"
29
+ "k8s.io/kubernetes/test/utils/ktesting"
30
30
)
31
31
32
32
func TestCollectResourceMetrics (t * testing.T ) {
@@ -404,7 +404,7 @@ func TestCollectResourceMetrics(t *testing.T) {
404
404
for _ , test := range tests {
405
405
tc := test
406
406
t .Run (tc .name , func (t * testing.T ) {
407
- ctx := context . Background ( )
407
+ ctx := ktesting . Init ( t )
408
408
provider := summaryprovidertest .NewMockSummaryProvider (t )
409
409
provider .EXPECT ().GetCPUAndMemoryStats (ctx ).Return (tc .summary , tc .summaryErr ).Maybe ()
410
410
collector := NewResourceMetricsCollector (provider )
Original file line number Diff line number Diff line change @@ -98,7 +98,9 @@ func (collector *volumeStatsCollector) DescribeWithStability(ch chan<- *metrics.
98
98
99
99
// CollectWithStability implements the metrics.StableCollector interface.
100
100
func (collector * volumeStatsCollector ) CollectWithStability (ch chan <- metrics.Metric ) {
101
- ctx := context .Background ()
101
+ // Use context.TODO() because we currently do not have a proper context to pass in.
102
+ // Replace this with an appropriate context when refactoring this function to accept a context parameter.
103
+ ctx := context .TODO ()
102
104
podStats , err := collector .statsProvider .ListPodStats (ctx )
103
105
if err != nil {
104
106
return
Original file line number Diff line number Diff line change @@ -17,22 +17,22 @@ limitations under the License.
17
17
package collectors
18
18
19
19
import (
20
- "context"
21
20
"strings"
22
21
"testing"
23
22
24
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
24
"k8s.io/component-base/metrics/testutil"
26
25
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
27
26
statstest "k8s.io/kubernetes/pkg/kubelet/server/stats/testing"
27
+ "k8s.io/kubernetes/test/utils/ktesting"
28
28
)
29
29
30
30
func newUint64Pointer (i uint64 ) * uint64 {
31
31
return & i
32
32
}
33
33
34
34
func TestVolumeStatsCollector (t * testing.T ) {
35
- ctx := context . Background ( )
35
+ ctx := ktesting . Init ( t )
36
36
// Fixed metadata on type and help text. We prepend this to every expected
37
37
// output so we only have to modify a single place when doing adjustments.
38
38
const metadata = `
@@ -151,7 +151,7 @@ func TestVolumeStatsCollector(t *testing.T) {
151
151
}
152
152
153
153
func TestVolumeStatsCollectorWithNullVolumeStatus (t * testing.T ) {
154
- ctx := context . Background ( )
154
+ ctx := ktesting . Init ( t )
155
155
// Fixed metadata on type and help text. We prepend this to every expected
156
156
// output so we only have to modify a single place when doing adjustments.
157
157
const metadata = `
You can’t perform that action at this time.
0 commit comments