Skip to content

Commit 616ec6e

Browse files
committed
make intel resource control collector optional
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent d448bc1 commit 616ec6e

File tree

13 files changed

+142
-71
lines changed

13 files changed

+142
-71
lines changed

manager/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, HousekeepingConfi
221221
return nil, err
222222
}
223223

224-
newManager.resctrlManager, err = resctrl.NewManager(resctrlInterval, resctrl.Setup, machineInfo.CPUVendorID, inHostNamespace)
224+
newManager.resctrlManager, err = resctrl.NewManager(resctrlInterval, machineInfo.CPUVendorID, inHostNamespace)
225225
if err != nil {
226226
klog.V(4).Infof("Cannot gather resctrl metrics: %v", err)
227227
}
@@ -264,8 +264,8 @@ type manager struct {
264264
containerWatchers []watcher.ContainerWatcher
265265
eventsChannel chan watcher.ContainerEvent
266266
collectorHTTPClient *http.Client
267-
perfManager stats.Manager
268-
resctrlManager resctrl.Manager
267+
perfManager stats.Manager
268+
resctrlManager resctrl.Manager
269269
// List of raw container cgroup path prefix whitelist.
270270
rawContainerCgroupPathPrefixWhiteList []string
271271
// List of container env prefix whitelist, the matched container envs would be collected into metrics as extra labels.

resctrl/collector.go renamed to resctrl/intel/collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// limitations under the License.
1717

1818
// Collector of resctrl for a container.
19-
package resctrl
19+
package intel
2020

2121
import (
2222
"fmt"

resctrl/collector_test.go renamed to resctrl/intel/collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// limitations under the License.
1717

1818
// Collector tests.
19-
package resctrl
19+
package intel
2020

2121
import (
2222
"fmt"

resctrl/intel/install/install.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package install
16+
17+
import (
18+
"github.com/google/cadvisor/resctrl"
19+
"github.com/google/cadvisor/resctrl/intel"
20+
"k8s.io/klog/v2"
21+
)
22+
23+
func init() {
24+
err := resctrl.RegisterManager("intel", &intel.IntelManager{})
25+
if err != nil {
26+
klog.Fatalf("Failed to register resource control plugin: %v", err)
27+
}
28+
}

resctrl/intel/manager.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//go:build linux
2+
// +build linux
3+
4+
// Copyright 2021 Google Inc. All Rights Reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
package intel
19+
20+
import (
21+
"errors"
22+
"time"
23+
24+
"k8s.io/klog/v2"
25+
26+
"github.com/google/cadvisor/container/raw"
27+
"github.com/google/cadvisor/stats"
28+
)
29+
30+
type IntelManager struct {
31+
stats.NoopDestroy
32+
interval time.Duration
33+
vendorID string
34+
inHostNamespace bool
35+
}
36+
37+
func (m *IntelManager) GetCollector(containerName string, getContainerPids func() ([]string, error), numberOfNUMANodes int) (stats.Collector, error) {
38+
collector := newCollector(containerName, getContainerPids, m.interval, numberOfNUMANodes, m.vendorID, m.inHostNamespace)
39+
err := collector.setup()
40+
if err != nil {
41+
return &stats.NoopCollector{}, err
42+
}
43+
44+
return collector, nil
45+
}
46+
47+
func (m *IntelManager) Init(interval time.Duration, vendorID string, inHostNamespace bool) error {
48+
err := Setup()
49+
if err != nil {
50+
return err
51+
}
52+
53+
if !isResctrlInitialized {
54+
return errors.New("the resctrl isn't initialized")
55+
}
56+
if !(enabledCMT || enabledMBM) {
57+
return errors.New("there are no monitoring features available")
58+
}
59+
60+
if !*raw.DockerOnly {
61+
klog.Warning("--docker_only should be set when collecting Resctrl metrics! See the runtime docs.")
62+
}
63+
64+
m.interval = interval
65+
m.vendorID = vendorID
66+
m.inHostNamespace = inHostNamespace
67+
return nil
68+
}

resctrl/manager_test.go renamed to resctrl/intel/manager_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
// limitations under the License.
1717

1818
// Manager tests.
19-
package resctrl
19+
package intel
2020

2121
import (
2222
"os"
2323
"testing"
2424

25+
"github.com/google/cadvisor/resctrl"
2526
"github.com/stretchr/testify/assert"
2627
)
2728

@@ -32,7 +33,7 @@ func TestNewManager(t *testing.T) {
3233
enabledMBM bool
3334
inHostNamespace bool
3435
err string
35-
expected Manager
36+
expected resctrl.Manager
3637
}{
3738
{
3839
true,
@@ -64,39 +65,39 @@ func TestNewManager(t *testing.T) {
6465
false,
6566
false,
6667
"the resctrl isn't initialized",
67-
&NoopManager{},
68+
&resctrl.NoopManager{},
6869
},
6970
{
7071
false,
7172
false,
7273
true,
7374
false,
7475
"the resctrl isn't initialized",
75-
&NoopManager{},
76+
&resctrl.NoopManager{},
7677
},
7778
{
7879
false,
7980
true,
8081
true,
8182
true,
8283
"the resctrl isn't initialized",
83-
&NoopManager{},
84+
&resctrl.NoopManager{},
8485
},
8586
{
8687
false,
8788
false,
8889
false,
8990
true,
9091
"the resctrl isn't initialized",
91-
&NoopManager{},
92+
&resctrl.NoopManager{},
9293
},
9394
{
9495
true,
9596
false,
9697
false,
9798
true,
9899
"there are no monitoring features available",
99-
&NoopManager{},
100+
&resctrl.NoopManager{},
100101
},
101102
}
102103

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)