Skip to content

Commit

Permalink
test: support running integration test with envoy bin
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Nov 28, 2024
1 parent 97a14ea commit 73d1921
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 104 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ jobs:
- name: Build
run: make build-test-so
# this part is envoy version agnostic so we only run it once
- if: ${{ matrix.envoy_version == 'dev' }}
name: Test plugin integration test framework
run: |
docker run --rm -e ENVOY_API_VERSION \
-v $(pwd):/go/src/github.com/mosn/htnn $PROXY_IMAGE \
./api/plugins/tests/integration/test_binary_mode.sh
- name: Integration test
run: make integration-test
- name: Upload logs
Expand Down
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
)
replace github.com/envoyproxy/envoy => github.com/envoyproxy/envoy v1.32.1-0.20241112025658-4fd9bb670eeb
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 73d1921

Please sign in to comment.