Skip to content

Commit

Permalink
test: support running integration test with envoy bin (#810)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Nov 29, 2024
1 parent 97a14ea commit 855823f
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 104 deletions.
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
}
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{}) {
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 {
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

0 comments on commit 855823f

Please sign in to comment.