diff --git a/pkg/plugins/policies/meshfaultinjection/plugin/v1alpha1/plugin.go b/pkg/plugins/policies/meshfaultinjection/plugin/v1alpha1/plugin.go index 7365266e29b4..7ee81adbae01 100644 --- a/pkg/plugins/policies/meshfaultinjection/plugin/v1alpha1/plugin.go +++ b/pkg/plugins/policies/meshfaultinjection/plugin/v1alpha1/plugin.go @@ -181,7 +181,7 @@ func configure( protocol core_mesh.Protocol, ) error { switch protocol { - case core_mesh.ProtocolHTTP, core_mesh.ProtocolHTTP2: + case core_mesh.ProtocolHTTP, core_mesh.ProtocolHTTP2, core_mesh.ProtocolGRPC: for _, rule := range fromRules { conf := rule.Conf.(api.Conf) from := rule.Subset diff --git a/test/e2e_env/universal/meshretry/grpc.go b/test/e2e_env/universal/meshretry/grpc.go index 1565553383f4..fb501f0a74f2 100644 --- a/test/e2e_env/universal/meshretry/grpc.go +++ b/test/e2e_env/universal/meshretry/grpc.go @@ -28,8 +28,6 @@ func GrpcRetry() { WithProtocol("grpc"), WithTransparentProxy(true), )). - // remove default policies after https://github.com/kumahq/kuma/issues/3325 - Install(TrafficRouteUniversal(meshName)). Setup(universal.Cluster) Expect(err).ToNot(HaveOccurred()) @@ -45,23 +43,27 @@ func GrpcRetry() { E2EAfterAll(func() { Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed()) - Expect(universal.Cluster.GetKumactlOptions().RunKumactl("delete", "dataplane", "fake-echo-server", "-m", meshName)).To(Succeed()) Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed()) }) It("should retry on GRPC connection failure", func() { - echoServerDataplane := fmt.Sprintf(` -type: Dataplane + faultInjection := fmt.Sprintf(` +type: MeshFaultInjection mesh: "%s" -name: fake-echo-server -networking: - address: 241.0.0.1 - inbound: - - port: 7777 - servicePort: 7777 - tags: - kuma.io/service: test-server - kuma.io/protocol: grpc +name: mesh-fault-injecton-500-grpc +spec: + targetRef: + kind: MeshService + name: test-server + from: + - targetRef: + kind: MeshService + name: test-client + default: + http: + - abort: + httpStatus: 503 + percentage: "50.0" `, meshName) meshRetryPolicy := fmt.Sprintf(` type: MeshRetry @@ -100,8 +102,8 @@ spec: g.Expect(grpcSuccessStats(g)).To(stats.BeGreaterThanZero()) }, "30s", "1s").Should(Succeed()) - By("Adding a faulty dataplane") - Expect(universal.Cluster.Install(YamlUniversal(echoServerDataplane))).To(Succeed()) + By("Adding a fault injection") + Expect(universal.Cluster.Install(YamlUniversal(faultInjection))).To(Succeed()) By("Clean counters") Expect(admin.ResetCounters()).To(Succeed()) @@ -112,7 +114,7 @@ spec: defer func() { lastFailureStats = failureStats.Stats[0] }() g.Expect(failureStats).To(stats.BeGreaterThanZero()) g.Expect(failureStats).To(stats.BeGreaterThan(lastFailureStats)) - }, "60s", "5s").MustPassRepeatedly(3).Should(Succeed()) + }, "30s", "5s").Should(Succeed()) By("Apply a MeshRetry policy") Expect(universal.Cluster.Install(YamlUniversal(meshRetryPolicy))).To(Succeed()) @@ -127,6 +129,6 @@ spec: defer func() { lastFailureStats = failureStats.Stats[0] }() g.Expect(failureStats).To(Not(stats.BeGreaterThan(lastFailureStats))) g.Expect(grpcSuccessStats(g)).To(stats.BeGreaterThanZero()) - }, "30s", "5s").MustPassRepeatedly(3).Should(Succeed()) + }, "30s", "5s").Should(Succeed()) }) } diff --git a/test/e2e_env/universal/retry/retry.go b/test/e2e_env/universal/retry/retry.go index 32f84b53db37..b191be104b09 100644 --- a/test/e2e_env/universal/retry/retry.go +++ b/test/e2e_env/universal/retry/retry.go @@ -2,7 +2,6 @@ package retry import ( "fmt" - "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -36,24 +35,25 @@ func Policy() { E2EAfterAll(func() { Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed()) - Expect(universal.Cluster.GetKumactlOptions().RunKumactl("delete", "dataplane", "fake-echo-server", "-m", meshName)).To(Succeed()) Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed()) }) It("should retry on HTTP connection failure", func() { - echoServerDataplane := fmt.Sprintf(` -type: Dataplane + fiPolicy := fmt.Sprintf(` +type: FaultInjection mesh: "%s" -name: fake-echo-server -networking: - address: 241.0.0.1 - inbound: - - port: 7777 - servicePort: 7777 - tags: - kuma.io/service: test-server - kuma.io/protocol: http -`, meshName) +name: fi-retry +sources: + - match: + kuma.io/service: demo-client +destinations: + - match: + kuma.io/service: test-server + kuma.io/protocol: http +conf: + abort: + httpStatus: 500 + percentage: 50`, meshName) retryPolicy := fmt.Sprintf(` type: Retry mesh: "%s" @@ -75,32 +75,22 @@ conf: universal.Cluster, "demo-client", "test-server.mesh", ) g.Expect(err).ToNot(HaveOccurred()) - }).Should(Succeed()) - Consistently(func(g Gomega) { - // -m 8 to wait for 8 seconds to beat the default 5s connect timeout - _, err := client.CollectEchoResponse( - universal.Cluster, "demo-client", "test-server.mesh", - client.WithMaxTime(8), - ) - g.Expect(err).ToNot(HaveOccurred()) - }).Should(Succeed()) + }, "30s", "1s").MustPassRepeatedly(3).Should(Succeed()) - By("Adding a faulty dataplane") - Expect(universal.Cluster.Install(YamlUniversal(echoServerDataplane))).To(Succeed()) + By("Adding a fault injection") + Expect(universal.Cluster.Install(YamlUniversal(fiPolicy))).To(Succeed()) By("Check some errors happen") - var errs []error - for i := 0; i < 50; i++ { - time.Sleep(time.Millisecond * 100) - _, err := client.CollectEchoResponse( + Eventually(func(g Gomega) { + response, err := client.CollectFailure( universal.Cluster, "demo-client", "test-server.mesh", - client.WithMaxTime(8), + client.NoFail(), + client.OutputFormat(`{ "received": { "status": %{response_code} } }`), ) - if err != nil { - errs = append(errs, err) - } - } - Expect(errs).ToNot(BeEmpty()) + + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(response.ResponseCode).To(Equal(500)) + }, "30s", "100ms").Should(Succeed()) By("Apply a retry policy") Expect(universal.Cluster.Install(YamlUniversal(retryPolicy))).To(Succeed()) @@ -109,9 +99,8 @@ conf: Eventually(func(g Gomega) { _, err := client.CollectEchoResponse( universal.Cluster, "demo-client", "test-server.mesh", - client.WithMaxTime(8), ) g.Expect(err).ToNot(HaveOccurred()) - }, "1m", "1s", MustPassRepeatedly(3)).Should(Succeed()) + }, "60s", "1s").MustPassRepeatedly(3).Should(Succeed()) }) }