-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: a prototype for enhancing E2E test framework (#424)
This code change demonstrate a prototype to enhance current E2E testing framework. The prototype includes the following two changes and updates an existing test case - TestFiltering. 1. Send data to input http vertex through E2E api instead of http vertex port forwarding. 2. Replace log verification with checking output data in redis sink. Next step is to iteratively generalize the testing APIs to meet requirements from all existing and future test cases. e.g. supporting specifying message headers, support per-sink data validations etc. Signed-off-by: Keran Yang <yangkr920208@gmail.com>
- Loading branch information
Showing
13 changed files
with
443 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
# redis-minimal.yaml is used in E2E testing to create a redis instance before we start a test pipeline which writes to redis. | ||
resources: | ||
- redis-minimal.yaml | ||
|
||
commonLabels: | ||
"numaflow-e2e": "true" | ||
|
This file contains 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,80 @@ | ||
--- | ||
# | ||
# Redis service | ||
# | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: redis | ||
labels: | ||
app: redis | ||
spec: | ||
ports: | ||
- port: 6379 | ||
targetPort: 6379 | ||
name: client | ||
clusterIP: None | ||
selector: | ||
app: redis | ||
--- | ||
# | ||
# Redis configuration file | ||
# | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: redis-config | ||
labels: | ||
app: redis | ||
data: | ||
redis-config: | | ||
maxmemory 10mb | ||
maxmemory-policy allkeys-lru | ||
--- | ||
# | ||
# Redis stateful set | ||
# | ||
apiVersion: apps/v1 | ||
kind: StatefulSet | ||
metadata: | ||
name: redis | ||
spec: | ||
serviceName: redis | ||
replicas: 1 | ||
minReadySeconds: 10 # by default is 0 | ||
selector: | ||
matchLabels: | ||
app: redis # has to match .spec.template.metadata.labels | ||
template: | ||
metadata: | ||
labels: | ||
app: redis | ||
name: redis | ||
spec: | ||
terminationGracePeriodSeconds: 10 | ||
containers: | ||
- name: redis | ||
image: redis:5.0.4 | ||
ports: | ||
- containerPort: 6379 | ||
name: client | ||
command: | ||
- redis-server | ||
- "/redis-master/redis.conf" | ||
env: | ||
- name: MASTER | ||
value: "true" | ||
volumeMounts: | ||
- mountPath: /redis-master-data | ||
name: data | ||
- mountPath: /redis-master | ||
name: config | ||
volumes: | ||
- name: data | ||
emptyDir: {} | ||
- name: config | ||
configMap: | ||
name: redis-config | ||
items: | ||
- key: redis-config | ||
path: redis.conf |
This file contains 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 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 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,55 @@ | ||
/* | ||
Copyright 2022 The Numaproj 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 main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/tls" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
var httpClient *http.Client | ||
|
||
func init() { | ||
httpClient = &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
}, | ||
} | ||
|
||
// send-message API is used to post data to a http source vertex pod. | ||
// The API takes in two parameters(podIp and vertexName) and constructs the target url as | ||
// https://{podIp}:8443/vertices/{vertexName}. | ||
http.HandleFunc("/http/send-message", func(w http.ResponseWriter, r *http.Request) { | ||
podIp := r.URL.Query().Get("podIp") | ||
vertexName := r.URL.Query().Get("vertexName") | ||
buf, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
w.WriteHeader(500) | ||
_, _ = w.Write([]byte(err.Error())) | ||
} | ||
|
||
_, err = httpClient.Post(fmt.Sprintf("https://%s:8443/vertices/%s", podIp, vertexName), "application/json", bytes.NewBuffer(buf)) | ||
|
||
if err != nil { | ||
w.WriteHeader(500) | ||
_, _ = w.Write([]byte(err.Error())) | ||
} | ||
}) | ||
} |
This file contains 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,63 @@ | ||
/* | ||
Copyright 2022 The Numaproj 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 main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/go-redis/redis/v8" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
var redisClient *redis.Client | ||
|
||
func init() { | ||
|
||
// When we use this API to validate e2e test result, we always assume a redis UDSink is used | ||
// to persist data to a redis instance listening on port 6379. | ||
redisClient = redis.NewClient(&redis.Options{ | ||
Addr: "redis:6379", | ||
}) | ||
|
||
// get-msg-count-contains takes a targetRegex and returns number of keys in redis | ||
// which contain a substring matching the targetRegex. | ||
http.HandleFunc("/redis/get-msg-count-contains", func(w http.ResponseWriter, r *http.Request) { | ||
targetRegex, err := url.QueryUnescape(r.URL.Query().Get("targetRegex")) | ||
|
||
if err != nil { | ||
log.Println(err) | ||
w.WriteHeader(500) | ||
_, _ = w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
// Redis Keys API uses scan to retrieve data, which is not best practice in terms of performance. | ||
// TODO - Look into replacing it with a more efficient API or data structure. | ||
keyList, err := redisClient.Keys(context.Background(), fmt.Sprintf("*%s*", targetRegex)).Result() | ||
if err != nil { | ||
log.Println(err) | ||
w.WriteHeader(500) | ||
_, _ = w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
w.WriteHeader(200) | ||
_, _ = w.Write([]byte(fmt.Sprint(len(keyList)))) | ||
}) | ||
} |
This file contains 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 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 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 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,22 @@ | ||
/* | ||
Copyright 2022 The Numaproj 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 fixtures | ||
|
||
// SendMessageTo sends msg to a pod in http source vertex. | ||
func SendMessageTo(podIp string, vertexName string, msg []byte) { | ||
InvokeE2EAPIPOST("/http/send-message?podIp=%s&vertexName=%s", string(msg[:]), podIp, vertexName) | ||
} |
Oops, something went wrong.