From 43a15cd97f78c304dfb26b57569783e50d48d533 Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Fri, 10 May 2024 17:33:35 +0800 Subject: [PATCH 1/5] add benchmark of workload Signed-off-by: LiZhenCheng9527 --- pkg/cache/v2/cluster_test.go | 8 +- pkg/cache/v2/listener_test.go | 8 +- pkg/controller/ads/ads_processor_test.go | 29 ++++++- pkg/controller/client_test.go | 80 ++++++++++++++++++- pkg/controller/workload/workload_processor.go | 4 + pkg/utils/test/bpf_map.go | 18 +++-- 6 files changed, 131 insertions(+), 16 deletions(-) diff --git a/pkg/cache/v2/cluster_test.go b/pkg/cache/v2/cluster_test.go index d7e4d8193..ef25ec6e3 100644 --- a/pkg/cache/v2/cluster_test.go +++ b/pkg/cache/v2/cluster_test.go @@ -28,6 +28,7 @@ import ( cluster_v2 "kmesh.net/kmesh/api/v2/cluster" core_v2 "kmesh.net/kmesh/api/v2/core" "kmesh.net/kmesh/api/v2/endpoint" + "kmesh.net/kmesh/daemon/options" maps_v2 "kmesh.net/kmesh/pkg/cache/v2/maps" "kmesh.net/kmesh/pkg/nets" "kmesh.net/kmesh/pkg/utils/hash" @@ -178,7 +179,12 @@ func TestClusterFlush(t *testing.T) { func BenchmarkClusterFlush(b *testing.B) { t := &testing.T{} - cleanup := test.InitBpfMap(t) + config := options.BpfConfig{ + Mode: "ads", + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + } + cleanup := test.InitBpfMap(t, config) b.Cleanup(cleanup) cluster := cluster_v2.Cluster{ diff --git a/pkg/cache/v2/listener_test.go b/pkg/cache/v2/listener_test.go index 606fc4d33..4ad9d6026 100644 --- a/pkg/cache/v2/listener_test.go +++ b/pkg/cache/v2/listener_test.go @@ -28,6 +28,7 @@ import ( core_v2 "kmesh.net/kmesh/api/v2/core" "kmesh.net/kmesh/api/v2/filter" listener_v2 "kmesh.net/kmesh/api/v2/listener" + "kmesh.net/kmesh/daemon/options" maps_v2 "kmesh.net/kmesh/pkg/cache/v2/maps" "kmesh.net/kmesh/pkg/nets" "kmesh.net/kmesh/pkg/utils/hash" @@ -187,7 +188,12 @@ func TestListenerFlush(t *testing.T) { func BenchmarkFlush(b *testing.B) { t := &testing.T{} - cleanup := test.InitBpfMap(t) + config := options.BpfConfig{ + Mode: "ads", + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + } + cleanup := test.InitBpfMap(t, config) b.Cleanup(cleanup) listener := &listener_v2.Listener{ diff --git a/pkg/controller/ads/ads_processor_test.go b/pkg/controller/ads/ads_processor_test.go index 05a3b428f..ba4c88365 100644 --- a/pkg/controller/ads/ads_processor_test.go +++ b/pkg/controller/ads/ads_processor_test.go @@ -32,13 +32,19 @@ import ( cluster_v2 "kmesh.net/kmesh/api/v2/cluster" core_v2 "kmesh.net/kmesh/api/v2/core" + "kmesh.net/kmesh/daemon/options" cache_v2 "kmesh.net/kmesh/pkg/cache/v2" "kmesh.net/kmesh/pkg/utils/hash" "kmesh.net/kmesh/pkg/utils/test" ) func TestHandleCdsResponse(t *testing.T) { - cleanup := test.InitBpfMap(t) + config := options.BpfConfig{ + Mode: "ads", + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + } + cleanup := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("new cluster, cluster type is eds", func(t *testing.T) { p := newProcessor() @@ -246,7 +252,12 @@ func TestHandleCdsResponse(t *testing.T) { } func TestHandleEdsResponse(t *testing.T) { - cleanup := test.InitBpfMap(t) + config := options.BpfConfig{ + Mode: "ads", + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + } + cleanup := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("cluster's apiStatus is UPDATE", func(t *testing.T) { p := newProcessor() @@ -402,7 +413,12 @@ func TestHandleEdsResponse(t *testing.T) { } func TestHandleLdsResponse(t *testing.T) { - cleanup := test.InitBpfMap(t) + config := options.BpfConfig{ + Mode: "ads", + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + } + cleanup := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("normal function test", func(t *testing.T) { adsLoader := NewAdsCache() @@ -574,7 +590,12 @@ func TestHandleLdsResponse(t *testing.T) { } func TestHandleRdsResponse(t *testing.T) { - cleanup := test.InitBpfMap(t) + config := options.BpfConfig{ + Mode: "ads", + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + } + cleanup := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("normal function test", func(t *testing.T) { p := newProcessor() diff --git a/pkg/controller/client_test.go b/pkg/controller/client_test.go index 4e952b6d5..d0ea244c7 100644 --- a/pkg/controller/client_test.go +++ b/pkg/controller/client_test.go @@ -20,14 +20,18 @@ import ( "context" "errors" "net" + "net/netip" "reflect" "testing" "github.com/agiledragon/gomonkey/v2" + "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "gotest.tools/assert" + "k8s.io/apimachinery/pkg/util/rand" + "kmesh.net/kmesh/api/v2/workloadapi" + "kmesh.net/kmesh/daemon/options" "kmesh.net/kmesh/pkg/bpf" "kmesh.net/kmesh/pkg/constants" "kmesh.net/kmesh/pkg/controller/workload" @@ -80,7 +84,7 @@ func TestClientResponseProcess(t *testing.T) { utClient := NewXdsClient(constants.AdsMode, &bpf.BpfKmeshWorkload{}) err := utClient.createGrpcStreamClient() - assert.NilError(t, err) + assert.NoError(t, err) reConnectPatches := gomonkey.NewPatches() defer reConnectPatches.Reset() @@ -127,7 +131,7 @@ func TestClientResponseProcess(t *testing.T) { utClient := NewXdsClient(constants.WorkloadMode, &bpf.BpfKmeshWorkload{}) err := utClient.createGrpcStreamClient() - assert.NilError(t, err) + assert.NoError(t, err) reConnectPatches := gomonkey.NewPatches() defer reConnectPatches.Reset() @@ -157,3 +161,73 @@ func TestClientResponseProcess(t *testing.T) { assert.Equal(t, 2, iteration) }) } + +func BenchmarkHandleDataWithService(b *testing.B) { + t := &testing.T{} + config := options.BpfConfig{ + Mode: constants.WorkloadMode, + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + EnableMda: false, + } + + workload := &workloadapi.Workload{ + Uid: "cluster0/networking.istio.io/WorkloadEntry/ns/name", + Namespace: "ns", + Addresses: [][]byte{netip.AddrFrom4([4]byte{1, 2, 3, 4}).AsSlice()}, + Network: "testnetwork", + CanonicalName: "foo", + CanonicalRevision: "latest", + WorkloadType: workloadapi.WorkloadType_POD, + WorkloadName: "name", + Status: workloadapi.WorkloadStatus_HEALTHY, + ClusterId: "cluster0", + Services: map[string]*workloadapi.PortList{ + "ns/hostname": { + Ports: []*workloadapi.Port{ + { + ServicePort: 80, + TargetPort: 8080, + }, + { + ServicePort: 81, + TargetPort: 8180, + }, + { + ServicePort: 82, + TargetPort: 82, + }, + }, + }, + }, + } + + netPatches := gomonkey.NewPatches() + defer netPatches.Reset() + netPatches.ApplyFunc(nets.GrpcConnect, func(addr string) (*grpc.ClientConn, error) { + mockDiscovery := xdstest.NewMockServer(t) + return grpc.Dial("buffcon", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithBlock(), + grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { + return mockDiscovery.Listener.Dial() + })) + }) + + utBpfLoad := bpf.NewBpfLoader(&config) + err := utBpfLoad.Start(&config) + assert.NoError(t, err) + defer utBpfLoad.Stop() + controller := NewController(config.Mode, utBpfLoad.GetBpfKmeshWorkload()) + controller.client = NewXdsClient(controller.mode, controller.bpfWorkloadObj) + err = controller.client.createGrpcStreamClient() + assert.NoError(t, err) + + utClient := controller.client + b.ResetTimer() + for i := 0; i < b.N; i++ { + workload.Name = rand.String(6) + err := utClient.workloadController.Processor.HandleDataWithService(workload) + assert.NoError(t, err) + } +} diff --git a/pkg/controller/workload/workload_processor.go b/pkg/controller/workload/workload_processor.go index 4d05e3ef5..d8baaa031 100644 --- a/pkg/controller/workload/workload_processor.go +++ b/pkg/controller/workload/workload_processor.go @@ -359,6 +359,10 @@ func (p *Processor) storeBackendData(uid uint32, ips [][]byte, portList *workloa return nil } +func (p *Processor) HandleDataWithService(workload *workloadapi.Workload) error { + return p.handleDataWithService(workload) +} + func (p *Processor) handleDataWithService(workload *workloadapi.Workload) error { var ( err error diff --git a/pkg/utils/test/bpf_map.go b/pkg/utils/test/bpf_map.go index a273717d6..b95b51110 100644 --- a/pkg/utils/test/bpf_map.go +++ b/pkg/utils/test/bpf_map.go @@ -24,11 +24,12 @@ import ( "kmesh.net/kmesh/daemon/options" "kmesh.net/kmesh/pkg/bpf" + "kmesh.net/kmesh/pkg/constants" ) type CleanupFn func() -func InitBpfMap(t *testing.T) CleanupFn { +func InitBpfMap(t *testing.T, config options.BpfConfig) CleanupFn { err := os.MkdirAll("/mnt/kmesh_cgroup2", 0755) if err != nil { t.Fatalf("Failed to create dir /mnt/kmesh_cgroup2: %v", err) @@ -43,13 +44,16 @@ func InitBpfMap(t *testing.T) CleanupFn { CleanupBpfMap() t.Fatalf("Failed to mount /sys/fs/bpf: %v", err) } - config := options.BpfConfig{ - Mode: "ads", - BpfFsPath: "/sys/fs/bpf", - Cgroup2Path: "/mnt/kmesh_cgroup2", - } + loader := bpf.NewBpfLoader(&config) - err = loader.StartAdsMode() + + if config.Mode == constants.AdsMode { + err = loader.StartAdsMode() + } + if config.Mode == constants.WorkloadMode { + err = loader.StartWorkloadMode() + } + if err != nil { CleanupBpfMap() t.Fatalf("bpf init failed: %v", err) From 62b3e54fd992aac164b1ef9b5bdccc7adcfe5461 Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Sat, 11 May 2024 10:40:30 +0800 Subject: [PATCH 2/5] chang the location of the workload benchmark test Signed-off-by: LiZhenCheng9527 --- pkg/controller/client_test.go | 74 ----------------- .../workload/workload_processor_test.go | 81 +++++++++++++++++++ pkg/utils/test/bpf_map.go | 4 +- 3 files changed, 83 insertions(+), 76 deletions(-) create mode 100644 pkg/controller/workload/workload_processor_test.go diff --git a/pkg/controller/client_test.go b/pkg/controller/client_test.go index d0ea244c7..ca091cce9 100644 --- a/pkg/controller/client_test.go +++ b/pkg/controller/client_test.go @@ -20,7 +20,6 @@ import ( "context" "errors" "net" - "net/netip" "reflect" "testing" @@ -28,10 +27,7 @@ import ( "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "k8s.io/apimachinery/pkg/util/rand" - "kmesh.net/kmesh/api/v2/workloadapi" - "kmesh.net/kmesh/daemon/options" "kmesh.net/kmesh/pkg/bpf" "kmesh.net/kmesh/pkg/constants" "kmesh.net/kmesh/pkg/controller/workload" @@ -161,73 +157,3 @@ func TestClientResponseProcess(t *testing.T) { assert.Equal(t, 2, iteration) }) } - -func BenchmarkHandleDataWithService(b *testing.B) { - t := &testing.T{} - config := options.BpfConfig{ - Mode: constants.WorkloadMode, - BpfFsPath: "/sys/fs/bpf", - Cgroup2Path: "/mnt/kmesh_cgroup2", - EnableMda: false, - } - - workload := &workloadapi.Workload{ - Uid: "cluster0/networking.istio.io/WorkloadEntry/ns/name", - Namespace: "ns", - Addresses: [][]byte{netip.AddrFrom4([4]byte{1, 2, 3, 4}).AsSlice()}, - Network: "testnetwork", - CanonicalName: "foo", - CanonicalRevision: "latest", - WorkloadType: workloadapi.WorkloadType_POD, - WorkloadName: "name", - Status: workloadapi.WorkloadStatus_HEALTHY, - ClusterId: "cluster0", - Services: map[string]*workloadapi.PortList{ - "ns/hostname": { - Ports: []*workloadapi.Port{ - { - ServicePort: 80, - TargetPort: 8080, - }, - { - ServicePort: 81, - TargetPort: 8180, - }, - { - ServicePort: 82, - TargetPort: 82, - }, - }, - }, - }, - } - - netPatches := gomonkey.NewPatches() - defer netPatches.Reset() - netPatches.ApplyFunc(nets.GrpcConnect, func(addr string) (*grpc.ClientConn, error) { - mockDiscovery := xdstest.NewMockServer(t) - return grpc.Dial("buffcon", - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return mockDiscovery.Listener.Dial() - })) - }) - - utBpfLoad := bpf.NewBpfLoader(&config) - err := utBpfLoad.Start(&config) - assert.NoError(t, err) - defer utBpfLoad.Stop() - controller := NewController(config.Mode, utBpfLoad.GetBpfKmeshWorkload()) - controller.client = NewXdsClient(controller.mode, controller.bpfWorkloadObj) - err = controller.client.createGrpcStreamClient() - assert.NoError(t, err) - - utClient := controller.client - b.ResetTimer() - for i := 0; i < b.N; i++ { - workload.Name = rand.String(6) - err := utClient.workloadController.Processor.HandleDataWithService(workload) - assert.NoError(t, err) - } -} diff --git a/pkg/controller/workload/workload_processor_test.go b/pkg/controller/workload/workload_processor_test.go new file mode 100644 index 000000000..ce574e778 --- /dev/null +++ b/pkg/controller/workload/workload_processor_test.go @@ -0,0 +1,81 @@ +/* + * Copyright 2024 The Kmesh 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 workload + +import ( + "net/netip" + "testing" + + "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/rand" + "kmesh.net/kmesh/api/v2/workloadapi" + "kmesh.net/kmesh/daemon/options" + "kmesh.net/kmesh/pkg/constants" + "kmesh.net/kmesh/pkg/utils/test" +) + +func BenchmarkHandleDataWithService(b *testing.B) { + t := &testing.T{} + config := options.BpfConfig{ + Mode: constants.WorkloadMode, + BpfFsPath: "/sys/fs/bpf", + Cgroup2Path: "/mnt/kmesh_cgroup2", + EnableMda: false, + } + cleanup, bpfLoader := test.InitBpfMap(t, config) + b.Cleanup(cleanup) + + workload := &workloadapi.Workload{ + Uid: "cluster0/networking.istio.io/WorkloadEntry/ns/name", + Namespace: "ns", + Addresses: [][]byte{netip.AddrFrom4([4]byte{1, 2, 3, 4}).AsSlice()}, + Network: "testnetwork", + CanonicalName: "foo", + CanonicalRevision: "latest", + WorkloadType: workloadapi.WorkloadType_POD, + WorkloadName: "name", + Status: workloadapi.WorkloadStatus_HEALTHY, + ClusterId: "cluster0", + Services: map[string]*workloadapi.PortList{ + "ns/hostname": { + Ports: []*workloadapi.Port{ + { + ServicePort: 80, + TargetPort: 8080, + }, + { + ServicePort: 81, + TargetPort: 8180, + }, + { + ServicePort: 82, + TargetPort: 82, + }, + }, + }, + }, + } + + workloadController := NewController(bpfLoader.GetBpfKmeshWorkload().SockConn.KmeshCgroupSockWorkloadMaps) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + workload.Name = rand.String(6) + err := workloadController.Processor.HandleDataWithService(workload) + assert.NoError(t, err) + } +} diff --git a/pkg/utils/test/bpf_map.go b/pkg/utils/test/bpf_map.go index b95b51110..9c38f08ec 100644 --- a/pkg/utils/test/bpf_map.go +++ b/pkg/utils/test/bpf_map.go @@ -29,7 +29,7 @@ import ( type CleanupFn func() -func InitBpfMap(t *testing.T, config options.BpfConfig) CleanupFn { +func InitBpfMap(t *testing.T, config options.BpfConfig) (CleanupFn, *bpf.BpfLoader) { err := os.MkdirAll("/mnt/kmesh_cgroup2", 0755) if err != nil { t.Fatalf("Failed to create dir /mnt/kmesh_cgroup2: %v", err) @@ -61,7 +61,7 @@ func InitBpfMap(t *testing.T, config options.BpfConfig) CleanupFn { return func() { loader.Stop() CleanupBpfMap() - } + }, loader } func CleanupBpfMap() { From 04b51aa17177257d52d4f119d14fd6c31ee4d10b Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Sat, 11 May 2024 10:41:55 +0800 Subject: [PATCH 3/5] fix ut Signed-off-by: LiZhenCheng9527 --- pkg/cache/v2/cluster_test.go | 2 +- pkg/cache/v2/listener_test.go | 2 +- pkg/controller/ads/ads_processor_test.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/cache/v2/cluster_test.go b/pkg/cache/v2/cluster_test.go index ef25ec6e3..523941331 100644 --- a/pkg/cache/v2/cluster_test.go +++ b/pkg/cache/v2/cluster_test.go @@ -184,7 +184,7 @@ func BenchmarkClusterFlush(b *testing.B) { BpfFsPath: "/sys/fs/bpf", Cgroup2Path: "/mnt/kmesh_cgroup2", } - cleanup := test.InitBpfMap(t, config) + cleanup, _ := test.InitBpfMap(t, config) b.Cleanup(cleanup) cluster := cluster_v2.Cluster{ diff --git a/pkg/cache/v2/listener_test.go b/pkg/cache/v2/listener_test.go index 4ad9d6026..7474f7f56 100644 --- a/pkg/cache/v2/listener_test.go +++ b/pkg/cache/v2/listener_test.go @@ -193,7 +193,7 @@ func BenchmarkFlush(b *testing.B) { BpfFsPath: "/sys/fs/bpf", Cgroup2Path: "/mnt/kmesh_cgroup2", } - cleanup := test.InitBpfMap(t, config) + cleanup, _ := test.InitBpfMap(t, config) b.Cleanup(cleanup) listener := &listener_v2.Listener{ diff --git a/pkg/controller/ads/ads_processor_test.go b/pkg/controller/ads/ads_processor_test.go index ba4c88365..62a0384cf 100644 --- a/pkg/controller/ads/ads_processor_test.go +++ b/pkg/controller/ads/ads_processor_test.go @@ -44,7 +44,7 @@ func TestHandleCdsResponse(t *testing.T) { BpfFsPath: "/sys/fs/bpf", Cgroup2Path: "/mnt/kmesh_cgroup2", } - cleanup := test.InitBpfMap(t, config) + cleanup, _ := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("new cluster, cluster type is eds", func(t *testing.T) { p := newProcessor() @@ -257,7 +257,7 @@ func TestHandleEdsResponse(t *testing.T) { BpfFsPath: "/sys/fs/bpf", Cgroup2Path: "/mnt/kmesh_cgroup2", } - cleanup := test.InitBpfMap(t, config) + cleanup, _ := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("cluster's apiStatus is UPDATE", func(t *testing.T) { p := newProcessor() @@ -418,7 +418,7 @@ func TestHandleLdsResponse(t *testing.T) { BpfFsPath: "/sys/fs/bpf", Cgroup2Path: "/mnt/kmesh_cgroup2", } - cleanup := test.InitBpfMap(t, config) + cleanup, _ := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("normal function test", func(t *testing.T) { adsLoader := NewAdsCache() @@ -595,7 +595,7 @@ func TestHandleRdsResponse(t *testing.T) { BpfFsPath: "/sys/fs/bpf", Cgroup2Path: "/mnt/kmesh_cgroup2", } - cleanup := test.InitBpfMap(t, config) + cleanup, _ := test.InitBpfMap(t, config) t.Cleanup(cleanup) t.Run("normal function test", func(t *testing.T) { p := newProcessor() From 3eb999793a38c78c4a99dd62dbae86dd85c32c16 Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Sat, 11 May 2024 10:48:11 +0800 Subject: [PATCH 4/5] fix format error Signed-off-by: LiZhenCheng9527 --- pkg/controller/workload/workload_processor_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/workload/workload_processor_test.go b/pkg/controller/workload/workload_processor_test.go index ce574e778..7571eeaef 100644 --- a/pkg/controller/workload/workload_processor_test.go +++ b/pkg/controller/workload/workload_processor_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/util/rand" + "kmesh.net/kmesh/api/v2/workloadapi" "kmesh.net/kmesh/daemon/options" "kmesh.net/kmesh/pkg/constants" From 90cde49af07d095491586768ce74b11de2030aff Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Sat, 11 May 2024 14:58:12 +0800 Subject: [PATCH 5/5] fix by comment Signed-off-by: LiZhenCheng9527 --- pkg/controller/workload/workload_processor.go | 4 --- .../workload/workload_processor_test.go | 26 +++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/controller/workload/workload_processor.go b/pkg/controller/workload/workload_processor.go index d8baaa031..4d05e3ef5 100644 --- a/pkg/controller/workload/workload_processor.go +++ b/pkg/controller/workload/workload_processor.go @@ -359,10 +359,6 @@ func (p *Processor) storeBackendData(uid uint32, ips [][]byte, portList *workloa return nil } -func (p *Processor) HandleDataWithService(workload *workloadapi.Workload) error { - return p.handleDataWithService(workload) -} - func (p *Processor) handleDataWithService(workload *workloadapi.Workload) error { var ( err error diff --git a/pkg/controller/workload/workload_processor_test.go b/pkg/controller/workload/workload_processor_test.go index 7571eeaef..dcc107276 100644 --- a/pkg/controller/workload/workload_processor_test.go +++ b/pkg/controller/workload/workload_processor_test.go @@ -40,9 +40,20 @@ func BenchmarkHandleDataWithService(b *testing.B) { cleanup, bpfLoader := test.InitBpfMap(t, config) b.Cleanup(cleanup) - workload := &workloadapi.Workload{ - Uid: "cluster0/networking.istio.io/WorkloadEntry/ns/name", + workloadController := NewController(bpfLoader.GetBpfKmeshWorkload().SockConn.KmeshCgroupSockWorkloadMaps) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + workload := createTestWorkload() + err := workloadController.Processor.handleDataWithService(workload) + assert.NoError(t, err) + } +} + +func createTestWorkload() *workloadapi.Workload { + workload := workloadapi.Workload{ Namespace: "ns", + Name: "name", Addresses: [][]byte{netip.AddrFrom4([4]byte{1, 2, 3, 4}).AsSlice()}, Network: "testnetwork", CanonicalName: "foo", @@ -70,13 +81,6 @@ func BenchmarkHandleDataWithService(b *testing.B) { }, }, } - - workloadController := NewController(bpfLoader.GetBpfKmeshWorkload().SockConn.KmeshCgroupSockWorkloadMaps) - - b.ResetTimer() - for i := 0; i < b.N; i++ { - workload.Name = rand.String(6) - err := workloadController.Processor.HandleDataWithService(workload) - assert.NoError(t, err) - } + workload.Uid = "cluster0/" + rand.String(6) + return &workload }