Skip to content

Commit

Permalink
Add integration tests for gRPC APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Sep 19, 2024
1 parent 1e1e0c5 commit 18576c5
Show file tree
Hide file tree
Showing 41 changed files with 4,603 additions and 63 deletions.
32 changes: 28 additions & 4 deletions adapter/internal/oasparser/envoyconf/http_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
cors_filter_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/cors/v3"
ext_authv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_authz/v3"
ext_process "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3"
grpc_stats_filter_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_stats/v3"
luav3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/lua/v3"
ratelimit "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ratelimit/v3"
routerv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
Expand All @@ -48,9 +49,9 @@ import (
"github.com/golang/protobuf/ptypes/any"
)


// HTTPExternalProcessor HTTP filter
const HTTPExternalProcessor = "envoy.filters.http.ext_proc"

// RatelimitFilterName Ratelimit filter name
const RatelimitFilterName = "envoy.filters.http.ratelimit"

Expand Down Expand Up @@ -114,6 +115,27 @@ func getRouterHTTPFilter() *hcmv3.HttpFilter {
return &filter
}

// getGRPCStatsHTTPFilter gets grpc_stats http filter.
func getGRPCStatsHTTPFilter() *hcmv3.HttpFilter {

gprcStatsFilterConf := grpc_stats_filter_v3.FilterConfig{
EnableUpstreamStats: true,
EmitFilterState: true,
}
gprcStatsFilterTypedConf, err := anypb.New(&gprcStatsFilterConf)

if err != nil {
logger.LoggerOasparser.Error("Error marshaling grpc stats filter configs. ", err)
}

filter := hcmv3.HttpFilter{
Name: "grpc_stats",
ConfigType: &hcmv3.HttpFilter_TypedConfig{TypedConfig: gprcStatsFilterTypedConf},
}

return &filter
}

// getCorsHTTPFilter gets cors http filter.
func getCorsHTTPFilter() *hcmv3.HttpFilter {

Expand All @@ -136,11 +158,13 @@ func getCorsHTTPFilter() *hcmv3.HttpFilter {
func getUpgradeFilters() []*hcmv3.HttpFilter {

cors := getCorsHTTPFilter()
grpcStats := getGRPCStatsHTTPFilter()
extAauth := getExtAuthzHTTPFilter()
apkWebSocketWASM := getAPKWebSocketWASMFilter()
router := getRouterHTTPFilter()
upgradeFilters := []*hcmv3.HttpFilter{
cors,
grpcStats,
extAauth,
apkWebSocketWASM,
router,
Expand Down Expand Up @@ -215,16 +239,16 @@ func getExtProcessHTTPFilter() *hcmv3.HttpFilter {
},
},
ProcessingMode: &ext_process.ProcessingMode{
ResponseBodyMode: ext_process.ProcessingMode_BUFFERED,
RequestHeaderMode: ext_process.ProcessingMode_SKIP,
ResponseBodyMode: ext_process.ProcessingMode_BUFFERED,
RequestHeaderMode: ext_process.ProcessingMode_SKIP,
ResponseHeaderMode: ext_process.ProcessingMode_SKIP,
},
MetadataOptions: &ext_process.MetadataOptions{
ForwardingNamespaces: &ext_process.MetadataOptions_MetadataNamespaces{
Untyped: []string{"envoy.filters.http.ext_authz", "envoy.filters.http.ext_proc"},
},
},
RequestAttributes: []string{"xds.route_metadata"},
RequestAttributes: []string{"xds.route_metadata"},
ResponseAttributes: []string{"xds.route_metadata"},
}
ext, err2 := anypb.New(externalProcessor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public String init(Api api) {
.mutualSSL(mutualSSL)
.applicationSecurity(applicationSecurity).jwtConfigurationDto(jwtConfigurationDto)
.apiDefinition(apiDefinition).environment(api.getEnvironment())
.environment(api.getEnvironment())
.subscriptionValidation(api.getSubscriptionValidation()).build();
.subscriptionValidation(api.getSubscriptionValidation()).transportSecurity(api.getTransportSecurity())
.build();
initFilters();
logger.info("APIConfig: " + this.apiConfig);
return basePath;
Expand Down
48 changes: 48 additions & 0 deletions test/cucumber-tests/CRs/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1729,3 +1729,51 @@ spec:
in: "Body"
value: "usage.total_tokens"
---
apiVersion: v1
kind: Service
metadata:
name: grpc-backend
namespace: apk-integration-test
spec:
selector:
app: grpc-backend
ports:
- protocol: TCP
port: 6565
targetPort: 6565
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: grpc-backend
namespace: apk-integration-test
labels:
app: grpc-backend
spec:
replicas: 1
selector:
matchLabels:
app: grpc-backend
template:
metadata:
labels:
app: grpc-backend
spec:
containers:
- name: grpc-backend
image: ddh13/dineth-grpc-demo-server:1.0.0
imagePullPolicy: Always
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources:
requests:
cpu: 10m
---

8 changes: 8 additions & 0 deletions test/cucumber-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ dependencies {
testImplementation 'commons-io:commons-io:2.13.0'
testImplementation 'com.nimbusds:nimbus-jose-jwt:9.31'
testImplementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'io.grpc:grpc-netty:1.48.0'
implementation 'io.grpc:grpc-protobuf:1.48.0'
implementation 'io.grpc:grpc-stub:1.48.0'
implementation 'io.grpc:grpc-auth:1.48.0'
implementation 'io.grpc:grpc-netty-shaded:1.57.0'
implementation 'io.grpc:grpc-protobuf:1.57.0'
implementation 'io.grpc:grpc-stub:1.57.0'
}

test {
Expand Down
1 change: 1 addition & 0 deletions test/cucumber-tests/scripts/setup-hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ kubectl wait deployment/llm-deployment-subs -n apk-integration-test --for=condit
kubectl wait deployment/llm-deployment-header -n apk-integration-test --for=condition=available --timeout=600s
kubectl wait deployment/interceptor-service-deployment -n apk-integration-test --for=condition=available --timeout=600s
kubectl wait deployment/graphql-faker -n apk-integration-test --for=condition=available --timeout=600s
kubectl wait deployment/grpc-backend -n apk-integration-test --for=condition=available --timeout=600s
kubectl wait --timeout=5m -n apk-integration-test deployment/apk-test-setup-wso2-apk-adapter-deployment --for=condition=Available
kubectl wait --timeout=15m -n apk-integration-test deployment/apk-test-setup-wso2-apk-gateway-runtime-deployment --for=condition=Available
IP=$(kubectl get svc apk-test-setup-wso2-apk-gateway-service -n apk-integration-test --output jsonpath='{.status.loadBalancer.ingress[0].ip}')
Expand Down
Loading

0 comments on commit 18576c5

Please sign in to comment.