Skip to content
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

test: support running integration test with envoy bin #810

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ jobs:
go install github.com/codesenberg/bombardier@latest
HTNN_DATA_PLANE_BENCHMARK_DURATION=1s make benchmark

# this part is envoy version agnostic so we only run it once
- if: ${{ matrix.envoy_version == 'dev' }}
name: Test plugin integration test framework
run: |
make test-integration-framework-in-docker

types-module-test:
timeout-minutes: 10
runs-on: ubuntu-latest
Expand Down
14 changes: 14 additions & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ integration-test:
go test -tags envoy${ENVOY_API_VERSION} -v ${PKG} || exit 1; \
)

.PHONY: test-integration-framework-in-docker
test-integration-framework-in-docker:
docker build -t test-integration-framework-in-docker \
--build-arg PROXY_BASE_IMAGE=${PROXY_IMAGE} \
--build-arg GO_BUILD_BASE_IMAGE=${BUILD_IMAGE} \
plugins/tests/integration/testdata
docker run --rm ${MOUNT_GOMOD_CACHE} \
-v $(PWD)/..:/go/src/${PROJECT_NAME} \
-w /go/src/${PROJECT_NAME}/api \
-e GOPROXY \
-e ENVOY_API_VERSION \
test-integration-framework-in-docker \
/go/src/${PROJECT_NAME}/api/plugins/tests/integration/test_binary_mode.sh

# The benchmark running time can be controlled via env var HTNN_DATA_PLANE_BENCHMARK_DURATION
.PHONY: benchmark
benchmark:
Expand Down
29 changes: 29 additions & 0 deletions api/plugins/tests/integration/dataplane/binary_mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright The HTNN 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 dataplane

import "os"

var (
binaryPath = ""
)

func init() {
binaryPath = os.Getenv("TEST_ENVOY_BINARY_PATH")
}

func isBinaryMode() bool {
return binaryPath != ""
}
37 changes: 34 additions & 3 deletions api/plugins/tests/integration/dataplane/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"math/rand"
"os"
"strconv"

"gopkg.in/yaml.v3"
)
Expand All @@ -34,6 +35,8 @@ type bootstrap struct {
httpFilterGolang map[string]interface{}
accessLogFormat string
clusters []map[string]interface{}

dp *DataPlane
}

func Bootstrap() *bootstrap {
Expand All @@ -44,6 +47,10 @@ func Bootstrap() *bootstrap {
}
}

func (b *bootstrap) SetDataPlane(dp *DataPlane) {
b.dp = dp
}

func (b *bootstrap) AddBackendRoute(s string) *bootstrap {
var n map[string]interface{}
err := yaml.Unmarshal([]byte(s), &n)
Expand Down Expand Up @@ -150,15 +157,19 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) {
staticResources := root["static_resources"].(map[string]interface{})
clusters := staticResources["clusters"].([]interface{})

port := "9999"
portEnv := os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")
if portEnv != "" {
port := 9999
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT"))
if portEnv != 0 {
port = portEnv
}
Comment on lines +161 to 164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the following method, but yours is okay.

Suggested change
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT"))
if portEnv != 0 {
port = portEnv
}
if p, err := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")); err == nil && p != 0 {
port = p
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thanks! My code style is more concise.

for _, c := range clusters {
if c.(map[string]interface{})["name"] == "config_server" {
load := c.(map[string]interface{})["load_assignment"].(map[string]interface{})["endpoints"].([]interface{})[0].(map[string]interface{})["lb_endpoints"].([]interface{})[0].(map[string]interface{})["endpoint"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{})
load["port_value"] = port

if isBinaryMode() {
load["address"] = "0.0.0.0"
}
break
}
}
Expand All @@ -168,6 +179,26 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) {
newClusters = append(newClusters, c)
}
staticResources["clusters"] = append(clusters, newClusters...)

addr := root["admin"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{})
addr["port_value"] = b.dp.AdminAPIPort()
addr = staticResources["listeners"].([]interface{})[0].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{})
addr["port_value"] = b.dp.Port()

if isBinaryMode() {
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use staticResource defined above here?

Suggested change
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) {
for _, l := range staticResource["listeners"].([]interface{}) {

listener := l.(map[string]interface{})
hcm := listener["filter_chains"].([]interface{})[0].(map[string]interface{})["filters"].([]interface{})[0].(map[string]interface{})["typed_config"].(map[string]interface{})
httpFilters := hcm["http_filters"].([]interface{})
for _, hf := range httpFilters {
Comment on lines +192 to +193
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like httpFilters is only used once. I prefer to remove this middle variable. But reserving it is also good.

Suggested change
httpFilters := hcm["http_filters"].([]interface{})
for _, hf := range httpFilters {
for _, hf := range hcm["http_filters"].([]interface{}) {

cfg := hf.(map[string]interface{})["typed_config"].(map[string]interface{})
if cfg["@type"] == "type.googleapis.com/envoy.extensions.filters.http.golang.v3alpha.Config" {
cfg["library_path"] = b.dp.soPath
}
}
}
}

return root, nil
}

Expand Down
Loading
Loading