Skip to content

Commit

Permalink
koordlet: add cold memory collection and reporting (#1574)
Browse files Browse the repository at this point in the history
Signed-off-by: BUPT-wxq <[email protected]>
  • Loading branch information
BUPT-wxq authored Sep 21, 2023
1 parent 1d0df44 commit 773eadd
Show file tree
Hide file tree
Showing 21 changed files with 2,294 additions and 32 deletions.
7 changes: 7 additions & 0 deletions pkg/features/koordlet_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ const (
//
// BlkIOReconcile enables block I/O QoS feature of koordlet.
BlkIOReconcile featuregate.Feature = "BlkIOReconcile"

// owner: @BUPT-wxq
// alpha v1.4
//
// ColdPageCollector enables coldPageCollector feature of koordlet.
ColdPageCollector featuregate.Feature = "ColdPageCollector"
)

func init() {
Expand Down Expand Up @@ -154,6 +160,7 @@ var (
Libpfm4: {Default: false, PreRelease: featuregate.Alpha},
PSICollector: {Default: false, PreRelease: featuregate.Alpha},
BlkIOReconcile: {Default: false, PreRelease: featuregate.Alpha},
ColdPageCollector: {Default: false, PreRelease: featuregate.Alpha},
}
)

Expand Down
7 changes: 7 additions & 0 deletions pkg/koordlet/metriccache/metric_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ var (
ContainerGPUCoreUsageMetric = defaultMetricFactory.New(ContainerMetricGPUCoreUsage).withPropertySchema(MetricPropertyContainerID, MetricPropertyGPUMinor, MetricPropertyGPUDeviceUUID)
ContainerGPUMemUsageMetric = defaultMetricFactory.New(ContainerMetricGPUMemUsage).withPropertySchema(MetricPropertyContainerID, MetricPropertyGPUMinor, MetricPropertyGPUDeviceUUID)
ContainerCPUThrottledMetric = defaultMetricFactory.New(ContainerMetricCPUThrottled).withPropertySchema(MetricPropertyContainerID)
// cold memory metrics
NodeMemoryWithHotPageUsageMetric = defaultMetricFactory.New(NodeMemoryWithHotPageUsage)
PodMemoryWithHotPageUsageMetric = defaultMetricFactory.New(PodMemoryWithHotPageUsage).withPropertySchema(MetricPropertyPodUID)
ContainerMemoryWithHotPageUsageMetric = defaultMetricFactory.New(ContainerMemoryWithHotPageUsage).withPropertySchema(MetricPropertyContainerID)
NodeMemoryColdPageSizeMetric = defaultMetricFactory.New(NodeMemoryColdPageSize)
PodMemoryColdPageSizeMetric = defaultMetricFactory.New(PodMemoryColdPageSize).withPropertySchema(MetricPropertyPodUID)
ContainerMemoryColdPageSizeMetric = defaultMetricFactory.New(ContainerMemoryColdPageSize).withPropertySchema(MetricPropertyContainerID)

// CPI
ContainerCPI = defaultMetricFactory.New(ContainerMetricCPI).withPropertySchema(MetricPropertyPodUID, MetricPropertyContainerID, MetricPropertyCPIResource)
Expand Down
8 changes: 8 additions & 0 deletions pkg/koordlet/metriccache/metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ const (
ContainerMetricPSICPUFullSupported MetricKind = "container_psi_cpu_full_supported"
PodMetricPSI MetricKind = "pod_psi"
PodMetricPSICPUFullSupported MetricKind = "pod_psi_cpu_full_supported"

//cold memory metrics
NodeMemoryWithHotPageUsage MetricKind = "node_memory_with_hot_page_usage"
PodMemoryWithHotPageUsage MetricKind = "pod_memory_with_hot_page_usage"
ContainerMemoryWithHotPageUsage MetricKind = "container_memory_with_hot_page_usage"
NodeMemoryColdPageSize MetricKind = "node_memory_cold_page_size"
PodMemoryColdPageSize MetricKind = "pod_memory_cold_page_size"
ContainerMemoryColdPageSize MetricKind = "container_memory_cold_page_size"
)

// MetricProperty is the property of metric
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2022 The Koordinator 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.
*/

package coldmemoryresource

import (
"go.uber.org/atomic"

"github.com/koordinator-sh/koordinator/pkg/koordlet/metricsadvisor/framework"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
)

const (
CollectorName = "ColdPageCollector"
)

type nonColdPageCollector struct {
}

func New(opt *framework.Options) framework.Collector {
// check whether support kidled cold page info collector
if system.IsKidledSupport() {
return &kidledcoldPageCollector{
collectInterval: opt.Config.ColdPageCollectorInterval,
cgroupReader: opt.CgroupReader,
statesInformer: opt.StatesInformer,
// TODO(BUPT-wxq): implement podFilter for the VM-based pods and containers
podFilter: framework.DefaultPodFilter,
appendableDB: opt.MetricCache,
metricDB: opt.MetricCache,
started: atomic.NewBool(false),
}
}
// TODO(BUPT-wxq): check kstaled cold page collector
// nonCollector does nothing
return &nonColdPageCollector{}
}

func (n *nonColdPageCollector) Run(stopCh <-chan struct{}) {}

func (n *nonColdPageCollector) Started() bool {
return false
}

func (n *nonColdPageCollector) Enabled() bool {
return false
}

func (n *nonColdPageCollector) Setup(c1 *framework.Context) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2022 The Koordinator 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.
*/

package coldmemoryresource

import (
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"

"github.com/koordinator-sh/koordinator/pkg/koordlet/metriccache"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metricsadvisor/framework"
"github.com/koordinator-sh/koordinator/pkg/koordlet/resourceexecutor"
mock_statesinformer "github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer/mockstatesinformer"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
)

func Test_NewColdPageCollector(t *testing.T) {
helper := system.NewFileTestUtil(t)
defer helper.Cleanup()
metricCache, err := metriccache.NewMetricCache(&metriccache.Config{
TSDBPath: t.TempDir(),
TSDBEnablePromMetrics: false,
})
defer func() {
err = metricCache.Close()
assert.NoError(t, err)
}()
ctrl := gomock.NewController(t)
defer ctrl.Finish()
statesInformer := mock_statesinformer.NewMockStatesInformer(ctrl)
opt := &framework.Options{
Config: &framework.Config{
ColdPageCollectorInterval: 1 * time.Second,
},
CgroupReader: resourceexecutor.NewCgroupReader(),
StatesInformer: statesInformer,
MetricCache: metricCache,
}
type fields struct {
SetSysUtil func(helper *system.FileTestUtil)
}
tests := []struct {
name string
fields fields
want framework.Collector
}{
{
name: "os doesn't support cold page collector and return nonCollector",
want: &nonColdPageCollector{},
},
{
name: "os support kidled cold page collector but cold page collector feature-gate false",
fields: fields{
SetSysUtil: func(helper *system.FileTestUtil) {

helper.SetResourcesSupported(true, system.KidledScanPeriodInSeconds)
helper.SetResourcesSupported(true, system.KidledUseHierarchy)
},
},
want: &kidledcoldPageCollector{
collectInterval: opt.Config.ColdPageCollectorInterval,
cgroupReader: opt.CgroupReader,
statesInformer: opt.StatesInformer,
podFilter: framework.DefaultPodFilter,
appendableDB: opt.MetricCache,
metricDB: opt.MetricCache,
started: atomic.NewBool(false),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
helper := system.NewFileTestUtil(t)
defer helper.Cleanup()
if tt.fields.SetSysUtil != nil {
tt.fields.SetSysUtil(helper)
}
got := New(opt)
assert.Equal(t, tt.want, got)
assert.NotPanics(t, func() {
got.Setup(&framework.Context{})
})
})
}
}
Loading

0 comments on commit 773eadd

Please sign in to comment.