generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 598
Conformance test for GRPCRouteRequestMirror #3514 #4015
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
Open
TaranpreetNatt
wants to merge
6
commits into
kubernetes-sigs:main
Choose a base branch
from
TaranpreetNatt:tests/add-grpcRoute-coverage-in-request-mirror-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17d6b50
Added conformance test for GRPCRouteRequestMirror, incomplete testing…
TaranpreetNatt 3f1a7ec
Added logic to check if the headers were modified correctly by the GR…
TaranpreetNatt 2fd8d8e
Finished GRPCRouteRequestMirror conformance test
TaranpreetNatt f78a5ae
Improved variable naming: receivedMap -> receivedHeadersMap for clarity
TaranpreetNatt c758ff1
Refactored ExprectMirroredRequest to one function and be shared betwe…
TaranpreetNatt f7852a0
Fixed linting errors
TaranpreetNatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
TaranpreetNatt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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 tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/metadata" | ||
"k8s.io/apimachinery/pkg/types" | ||
v1 "sigs.k8s.io/gateway-api/apis/v1" | ||
pb "sigs.k8s.io/gateway-api/conformance/echo-basic/grpcechoserver" | ||
"sigs.k8s.io/gateway-api/conformance/utils/grpc" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
"sigs.k8s.io/gateway-api/pkg/features" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, GRPCRouteRequestMirror) | ||
} | ||
|
||
var GRPCRouteRequestMirror = suite.ConformanceTest{ | ||
ShortName: "GRPCRouteRequestMirror", | ||
Description: "A GRPCRoute with request mirror filter", | ||
Manifests: []string{"tests/grpcroute-request-mirror.yaml"}, | ||
Features: []features.FeatureName{ | ||
features.SupportGRPCRoute, | ||
features.SupportGateway, | ||
features.SupportGRPCRouteRequestMirror, | ||
}, | ||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { | ||
ns := "gateway-conformance-infra" | ||
routeNN := types.NamespacedName{Name: "grpc-request-mirror", Namespace: ns} | ||
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} | ||
gwAddr := kubernetes.GatewayAndRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), &v1.GRPCRoute{}, true, routeNN) | ||
|
||
testCases := []grpc.ExpectedResponse{ | ||
{ | ||
EchoRequest: &pb.EchoRequest{}, | ||
Backend: "grpc-infra-backend-v1", | ||
Namespace: ns, | ||
MirroredTo: []grpc.MirroredBackend{ | ||
{ | ||
BackendRef: grpc.BackendRef{ | ||
Name: "grpc-infra-backend-v2", | ||
Namespace: ns, | ||
}, | ||
}, | ||
}, | ||
Response: grpc.Response{ | ||
Code: codes.OK, | ||
}, | ||
}, | ||
{ | ||
EchoTwoRequest: &pb.EchoRequest{}, | ||
Backend: "grpc-infra-backend-v1", | ||
RequestMetadata: &grpc.RequestMetadata{ | ||
Metadata: map[string]string{ | ||
"X-Header-Remove": "remove-val", | ||
"X-Header-Add-Append": "append-val-1", | ||
}, | ||
}, | ||
Namespace: ns, | ||
MirroredTo: []grpc.MirroredBackend{ | ||
{ | ||
BackendRef: grpc.BackendRef{ | ||
Name: "grpc-infra-backend-v2", | ||
Namespace: ns, | ||
}, | ||
}, | ||
}, | ||
Response: grpc.Response{ | ||
Code: codes.OK, | ||
Headers: func() *metadata.MD { | ||
md := metadata.Pairs( | ||
"x-header-set", "set-overwrites-values", | ||
"x-header-add", "header-val-1", | ||
"x-header-add-append", "append-val-1", | ||
"x-header-add-append", "header-val-2", | ||
) | ||
return &md | ||
}(), | ||
AbsentHeaders: []string{"X-Header-Remove"}, | ||
}, | ||
}, | ||
} | ||
for i := range testCases { | ||
tc := testCases[i] | ||
t.Run(tc.GetTestCaseName(i), func(t *testing.T) { | ||
t.Parallel() | ||
grpc.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.GRPCClient, suite.TimeoutConfig, gwAddr, tc) | ||
grpc.ExpectMirroredRequest(t, suite.Client, suite.Clientset, tc.MirroredTo) | ||
}) | ||
} | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: GRPCRoute | ||
metadata: | ||
name: grpc-request-mirror | ||
namespace: gateway-conformance-infra | ||
spec: | ||
parentRefs: | ||
- name: same-namespace | ||
rules: | ||
- matches: | ||
- method: | ||
service: gateway_api_conformance.echo_basic.grpcecho.GrpcEcho | ||
method: Echo | ||
filters: | ||
- type: RequestMirror | ||
requestMirror: | ||
backendRef: | ||
name: grpc-infra-backend-v2 | ||
namespace: gateway-conformance-infra | ||
port: 8080 | ||
backendRefs: | ||
- name: grpc-infra-backend-v1 | ||
port: 8080 | ||
namespace: gateway-conformance-infra | ||
- matches: | ||
- method: | ||
service: gateway_api_conformance.echo_basic.grpcecho.GrpcEcho | ||
method: EchoTwo | ||
filters: | ||
- type: RequestHeaderModifier | ||
requestHeaderModifier: | ||
set: | ||
- name: X-Header-Set | ||
value: set-overwrites-values | ||
add: | ||
- name: X-Header-Add | ||
value: header-val-1 | ||
- name: X-Header-Add-Append | ||
value: header-val-2 | ||
remove: | ||
- X-Header-Remove | ||
- type: RequestMirror | ||
requestMirror: | ||
backendRef: | ||
name: grpc-infra-backend-v2 | ||
namespace: gateway-conformance-infra | ||
port: 8080 | ||
backendRefs: | ||
- name: grpc-infra-backend-v1 | ||
port: 8080 | ||
namespace: gateway-conformance-infra |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
TaranpreetNatt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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 grpc | ||
|
||
import ( | ||
"regexp" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/tlog" | ||
|
||
clientset "k8s.io/client-go/kubernetes" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func ExpectMirroredRequest(t *testing.T, client client.Client, clientset clientset.Interface, mirrorPods []MirroredBackend) { | ||
TaranpreetNatt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
for i, mirrorPod := range mirrorPods { | ||
if mirrorPod.Name == "" { | ||
tlog.Fatalf(t, "Mirrored BackendRef[%d].Name wasn't provided in the testcase, this test should only check grpc request mirror.", i) | ||
} | ||
} | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(len(mirrorPods)) | ||
|
||
assertionStart := time.Now() | ||
|
||
for _, mirrorPod := range mirrorPods { | ||
go func(mirrorPod MirroredBackend) { | ||
defer wg.Done() | ||
|
||
require.Eventually(t, func() bool { | ||
mirrorLogRegexp := regexp.MustCompile("Received over plaintext:") | ||
|
||
tlog.Log(t, "Searching for the mirrored request log") | ||
tlog.Logf(t, `Reading "%s/%s" logs`, mirrorPod.Namespace, mirrorPod.Name) | ||
logs, err := kubernetes.DumpEchoLogs(mirrorPod.Namespace, mirrorPod.Name, client, clientset, assertionStart) | ||
if err != nil { | ||
tlog.Logf(t, `Couldn't read "%s/%s" logs: %v`, mirrorPod.Namespace, mirrorPod.Name, err) | ||
return false | ||
} | ||
|
||
for _, log := range logs { | ||
if mirrorLogRegexp.MatchString(log) { | ||
return true | ||
} | ||
} | ||
return false | ||
}, 60*time.Second, time.Millisecond*100, `Couldn't find mirrored request in "%s/%s" logs`, mirrorPod.Namespace, mirrorPod.Name) | ||
}(mirrorPod) | ||
} | ||
|
||
wg.Wait() | ||
|
||
tlog.Log(t, "Found mirrored request log in all desired backends") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add a test under conformance/tests/mesh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can look into it
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Lior, I tried to implement gRPC conformance tests under mesh, but I ran into some issues that aren't trivial for me to solve. I encountered the following issues below and what I tried. Maybe my approach is wrong? Is this needed for this issue and PR?
`application@echo-v1-699dd9bfc7-5rxvl:/$ client --http2 -H "content-type: application/grpc" --method=POST http://echo:7070/gateway_api_conformance.echo_basic.grpcecho.GrpcEcho/Echo
[0] Url=http://echo:7070/gateway_api_conformance.echo_basic.grpcecho.GrpcEcho/Echo
[0] Header=content-type:application/grpc
[0] Latency=24.388708ms
[0] ActiveRequests=1
[0] StatusCode=200
[0] ResponseHeader=Content-Type:application/grpc
[0] ResponseHeader=Grpc-Message:unknown service gateway_api_conformance.echo_basic.grpcecho.GrpcEcho
[0] ResponseHeader=Grpc-Status:12
2025-09-04T09:05:37.461782Z info All requests succeeded`