Skip to content
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

koordlet: add page cache collector unit test and mend default cold memory config #1738

Merged
merged 26 commits into from
Dec 6, 2023
Merged
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e25cb05
feat(deps): bump github.com/docker/docker
dependabot[bot] Oct 26, 2023
d267fd9
koordlet: add pagecache collector unit
BUPT-wxq Nov 1, 2023
49d5a14
koordlet:add page cache collector unit test
BUPT-wxq Nov 13, 2023
23f26de
fix uasgeWithHotPageCache and add usageWithPageCache
BUPT-wxq Oct 19, 2023
dccacfb
koordlet: add page cache collector unit test
BUPT-wxq Nov 13, 2023
08ec8c7
koordlet: add page cache collector unit test
BUPT-wxq Nov 13, 2023
948de3d
koordlet: add page cache collector unit test
BUPT-wxq Nov 13, 2023
54fb089
koordlet: add page cache collector unit test
BUPT-wxq Nov 13, 2023
3212f81
koordlet: add page cache collector unit test
BUPT-wxq Nov 13, 2023
18f6b96
koordlet: add unit test
BUPT-wxq Nov 14, 2023
c52c886
koordlet: add page cache unit test
BUPT-wxq Nov 14, 2023
016e34d
koordlet: add page cache unit test
BUPT-wxq Nov 14, 2023
9818ab9
koordlet: add page cache unit test
BUPT-wxq Nov 14, 2023
a886fa2
koordlet: add page cache unit test
BUPT-wxq Nov 15, 2023
0744fa6
koordlet: add page cache unit test
BUPT-wxq Nov 15, 2023
6e39cfc
koordlet: add page cache unit test
BUPT-wxq Nov 15, 2023
1ddfe5c
koordlet: add page cache unit test
BUPT-wxq Nov 15, 2023
25afa92
koordlet: add unit test
BUPT-wxq Nov 18, 2023
7c9d518
koordlet: add unit test
BUPT-wxq Nov 18, 2023
dacfc82
koodlet: add unit test
BUPT-wxq Nov 20, 2023
183a91a
koodlet: add unit test
BUPT-wxq Nov 20, 2023
6918ee9
koodlet: add unit test
BUPT-wxq Nov 20, 2023
00197c3
koordlet: add unit test
BUPT-wxq Nov 24, 2023
e29f4a9
koordlet: add unit test
BUPT-wxq Nov 27, 2023
3cf33d5
koordlet: add unit test
BUPT-wxq Nov 28, 2023
496ac3e
koordlet: add unit test
BUPT-wxq Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ DirectMap1G: 0 kB`
},
},
{
Name: "test-failed-container",
Name: "test-no-running-container",
ContainerID: testContainerID,
State: corev1.ContainerState{},
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{},
},
},
},
},
Expand All @@ -125,7 +127,7 @@ DirectMap1G: 0 kB`
ObjectMeta: metav1.ObjectMeta{
Name: "test-failed-pod",
Namespace: "test",
UID: "yyyyyy",
UID: "yyyyyyyy",
},
Status: corev1.PodStatus{
Phase: corev1.PodFailed,
Expand All @@ -146,10 +148,13 @@ DirectMap1G: 0 kB`
SetSysUtil func(helper *system.FileTestUtil)
}
tests := []struct {
name string
fields fields
wantEnable bool
wantStarted bool
name string
fields fields
wantEnable bool
wantStarted bool
wantNodeMetric float64
wantPodMetric float64
wantContainerMetric float64
}{
{
name: "collect pagecache info",
Expand Down Expand Up @@ -179,8 +184,11 @@ DirectMap1G: 0 kB`
helper.WriteCgroupFileContents(testContainerParentDir, system.MemoryStat, testMemStat)
},
},
wantEnable: true,
wantStarted: true,
wantEnable: true,
wantStarted: true,
wantNodeMetric: (1048576 - 262144) << 10,
wantPodMetric: 104857600 + 0 + 0 + 104857600 + 0,
wantContainerMetric: 104857600 + 0 + 0 + 104857600 + 0,
},
{
name: "test failed pod and failed container",
Expand Down Expand Up @@ -235,7 +243,7 @@ DirectMap1G: 0 kB`
}()
statesInformer := mock_statesinformer.NewMockStatesInformer(ctrl)
statesInformer.EXPECT().HasSynced().Return(true).AnyTimes()
statesInformer.EXPECT().GetAllPods().Return(tt.fields.getPodMetas).Times(1)
statesInformer.EXPECT().GetAllPods().Return(tt.fields.getPodMetas).AnyTimes()
collector := New(&framework.Options{
Config: &framework.Config{
EnablePageCacheCollector: true,
Expand All @@ -253,7 +261,78 @@ DirectMap1G: 0 kB`
})
assert.Equal(t, tt.wantEnable, c.Enabled())
assert.Equal(t, tt.wantStarted, c.Started())
if tt.name == "collect pagecache info" {
BUPT-wxq marked this conversation as resolved.
Show resolved Hide resolved
nodeGot := testGetNodePageCacheMetrics(t, metricCache, testNow, 5*time.Second)
assert.Equal(t, tt.wantNodeMetric, nodeGot)
podGot := testGetPodPageCacheMetrics(t, metricCache, string(c.statesInformer.GetAllPods()[0].Pod.UID), testNow, 5*time.Second)
assert.Equal(t, tt.wantPodMetric, podGot)
containerGot := testGetContainerPageCacheMetrics(t, metricCache, c.statesInformer.GetAllPods()[0].Pod.Status.ContainerStatuses[0].ContainerID, testNow, 5*time.Second)
assert.Equal(t, tt.wantContainerMetric, containerGot)
}
})

}
}

func testGetNodePageCacheMetrics(t *testing.T, metricCache metriccache.TSDBStorage, testNow time.Time, d time.Duration) float64 {
testStart := testNow.Add(-d)
testEnd := testNow.Add(d)
queryParam := metriccache.QueryParam{
Start: &testStart,
End: &testEnd,
Aggregate: metriccache.AggregationTypeAVG,
}
querier, err := metricCache.Querier(*queryParam.Start, *queryParam.End)
assert.NoError(t, err)
nodeMemWithPageCacheAggregateResult, err := testQuery(querier, metriccache.NodeMemoryUsageWithPageCacheMetric, nil)
assert.NoError(t, err)
nodeMemWithPageCacheUsed, err := nodeMemWithPageCacheAggregateResult.Value(queryParam.Aggregate)
assert.NoError(t, err)
return nodeMemWithPageCacheUsed
}

func testGetPodPageCacheMetrics(t *testing.T, metricCache metriccache.TSDBStorage, podUID string, testNow time.Time, d time.Duration) float64 {
testStart := testNow.Add(-d)
testEnd := testNow.Add(d)
queryParam := metriccache.QueryParam{
Start: &testStart,
End: &testEnd,
Aggregate: metriccache.AggregationTypeAVG,
}
querier, err := metricCache.Querier(*queryParam.Start, *queryParam.End)
assert.NoError(t, err)
podMemWithPageCacheAggregateResult, err := testQuery(querier, metriccache.PodMemoryUsageWithPageCacheMetric, metriccache.MetricPropertiesFunc.Pod(podUID))
assert.NoError(t, err)
podMemWithPageCacheUsed, err := podMemWithPageCacheAggregateResult.Value(queryParam.Aggregate)
assert.NoError(t, err)
return podMemWithPageCacheUsed
}

func testGetContainerPageCacheMetrics(t *testing.T, metricCache metriccache.TSDBStorage, containerUID string, testNow time.Time, d time.Duration) float64 {
testStart := testNow.Add(-d)
testEnd := testNow.Add(d)
queryParam := metriccache.QueryParam{
Start: &testStart,
End: &testEnd,
Aggregate: metriccache.AggregationTypeAVG,
}
querier, err := metricCache.Querier(*queryParam.Start, *queryParam.End)
assert.NoError(t, err)
containerMemWithPageCacheAggregateResult, err := testQuery(querier, metriccache.ContainerMemoryUsageWithPageCacheMetric, metriccache.MetricPropertiesFunc.Container(containerUID))
assert.NoError(t, err)
containerMemWithPageCacheUsed, err := containerMemWithPageCacheAggregateResult.Value(queryParam.Aggregate)
assert.NoError(t, err)
return containerMemWithPageCacheUsed
}

func testQuery(querier metriccache.Querier, resource metriccache.MetricResource, properties map[metriccache.MetricProperty]string) (metriccache.AggregateResult, error) {
queryMeta, err := resource.BuildQueryMeta(properties)
if err != nil {
return nil, err
}
aggregateResult := metriccache.DefaultAggregateResultFactory.New(queryMeta)
if err = querier.Query(queryMeta, nil, aggregateResult); err != nil {
return nil, err
}
return aggregateResult, nil
}