Merge pull request #129542 from serathius/watchcache-benchmark-namespace

Add benchmarking of namespace index
This commit is contained in:
Kubernetes Prow Robot 2025-01-09 03:22:32 -08:00 committed by GitHub
commit 30de989fb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 7 deletions

View File

@ -257,7 +257,7 @@ func TestListResourceVersionMatch(t *testing.T) {
} }
func TestNamespaceScopedList(t *testing.T) { func TestNamespaceScopedList(t *testing.T) {
ctx, cacher, terminate := testSetup(t, withSpecNodeNameIndexerFuncs) ctx, cacher, terminate := testSetup(t, withNodeNameAndNamespaceIndex)
t.Cleanup(terminate) t.Cleanup(terminate)
storagetesting.RunTestNamespaceScopedList(ctx, t, cacher) storagetesting.RunTestNamespaceScopedList(ctx, t, cacher)
} }
@ -355,13 +355,13 @@ func TestWatchInitializationSignal(t *testing.T) {
} }
func TestClusterScopedWatch(t *testing.T) { func TestClusterScopedWatch(t *testing.T) {
ctx, cacher, terminate := testSetup(t, withClusterScopedKeyFunc, withSpecNodeNameIndexerFuncs) ctx, cacher, terminate := testSetup(t, withClusterScopedKeyFunc, withNodeNameAndNamespaceIndex)
t.Cleanup(terminate) t.Cleanup(terminate)
storagetesting.RunTestClusterScopedWatch(ctx, t, cacher) storagetesting.RunTestClusterScopedWatch(ctx, t, cacher)
} }
func TestNamespaceScopedWatch(t *testing.T) { func TestNamespaceScopedWatch(t *testing.T) {
ctx, cacher, terminate := testSetup(t, withSpecNodeNameIndexerFuncs) ctx, cacher, terminate := testSetup(t, withNodeNameAndNamespaceIndex)
t.Cleanup(terminate) t.Cleanup(terminate)
storagetesting.RunTestNamespaceScopedWatch(ctx, t, cacher) storagetesting.RunTestNamespaceScopedWatch(ctx, t, cacher)
} }
@ -432,7 +432,8 @@ func withClusterScopedKeyFunc(options *setupOptions) {
} }
} }
func withSpecNodeNameIndexerFuncs(options *setupOptions) { // mirror indexer configuration from pkg/registry/core/pod/strategy.go
func withNodeNameAndNamespaceIndex(options *setupOptions) {
options.indexerFuncs = map[string]storage.IndexerFunc{ options.indexerFuncs = map[string]storage.IndexerFunc{
"spec.nodeName": func(obj runtime.Object) string { "spec.nodeName": func(obj runtime.Object) string {
pod, ok := obj.(*example.Pod) pod, ok := obj.(*example.Pod)
@ -447,6 +448,10 @@ func withSpecNodeNameIndexerFuncs(options *setupOptions) {
pod := obj.(*example.Pod) pod := obj.(*example.Pod)
return []string{pod.Spec.NodeName}, nil return []string{pod.Spec.NodeName}, nil
}, },
"f:metadata.namespace": func(obj interface{}) ([]string, error) {
pod := obj.(*example.Pod)
return []string{pod.ObjectMeta.Namespace}, nil
},
} }
} }
@ -571,7 +576,7 @@ func BenchmarkStoreCreateList(b *testing.B) {
b.Run(fmt.Sprintf("Indexed=%v", useIndex), func(b *testing.B) { b.Run(fmt.Sprintf("Indexed=%v", useIndex), func(b *testing.B) {
opts := []setupOption{} opts := []setupOption{}
if useIndex { if useIndex {
opts = append(opts, withSpecNodeNameIndexerFuncs) opts = append(opts, withNodeNameAndNamespaceIndex)
} }
ctx, cacher, _, terminate := testSetupWithEtcdServer(b, opts...) ctx, cacher, _, terminate := testSetupWithEtcdServer(b, opts...)
b.Cleanup(terminate) b.Cleanup(terminate)
@ -627,7 +632,7 @@ func BenchmarkStoreList(b *testing.B) {
for _, store := range storeOptions { for _, store := range storeOptions {
b.Run(fmt.Sprintf("Store=%s", store.name), func(b *testing.B) { b.Run(fmt.Sprintf("Store=%s", store.name), func(b *testing.B) {
featuregatetesting.SetFeatureGateDuringTest(b, utilfeature.DefaultFeatureGate, features.BtreeWatchCache, store.btreeEnabled) featuregatetesting.SetFeatureGateDuringTest(b, utilfeature.DefaultFeatureGate, features.BtreeWatchCache, store.btreeEnabled)
ctx, cacher, _, terminate := testSetupWithEtcdServer(b, withSpecNodeNameIndexerFuncs) ctx, cacher, _, terminate := testSetupWithEtcdServer(b, withNodeNameAndNamespaceIndex)
b.Cleanup(terminate) b.Cleanup(terminate)
var out example.Pod var out example.Pod
for _, pod := range data.Pods { for _, pod := range data.Pods {

View File

@ -2945,7 +2945,7 @@ func forceRequestWatchProgressSupport(t *testing.T) {
} }
func TestListIndexer(t *testing.T) { func TestListIndexer(t *testing.T) {
ctx, cacher, terminate := testSetup(t, withSpecNodeNameIndexerFuncs) ctx, cacher, terminate := testSetup(t, withNodeNameAndNamespaceIndex)
t.Cleanup(terminate) t.Cleanup(terminate)
tests := []struct { tests := []struct {
name string name string

View File

@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apiserver/pkg/apis/example" "k8s.io/apiserver/pkg/apis/example"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage"
) )
@ -149,6 +150,11 @@ func runBenchmarkStoreList(ctx context.Context, b *testing.B, store storage.Inte
objectCount.Add(uint64(objects)) objectCount.Add(uint64(objects))
pageCount.Add(uint64(pages)) pageCount.Add(uint64(pages))
case namespace: case namespace:
ctx := ctx
if useIndex {
opts.Predicate.IndexFields = []string{"metadata.namespace"}
ctx = request.WithRequestInfo(ctx, &request.RequestInfo{Namespace: namespaceName})
}
objects, pages := paginateList(ctx, store, "/pods/"+namespaceName, opts) objects, pages := paginateList(ctx, store, "/pods/"+namespaceName, opts)
objectCount.Add(uint64(objects)) objectCount.Add(uint64(objects))
pageCount.Add(uint64(pages)) pageCount.Add(uint64(pages))