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

adapt Envoy 1.31 #732

Merged
merged 8 commits into from
Sep 24, 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
26 changes: 22 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ jobs:
api-module-test:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
envoy_version:
- 1.29
- 1.31
env:
ENVOY_API_VERSION: ${{ matrix.envoy_version }}
# patch version should not contain API breaking changes, so we just pick the first one
FULL_ENVOY_VERSION: ${{ matrix.envoy_version }}.0
PROXY_IMAGE: envoyproxy/envoy:contrib-v${{ matrix.envoy_version }}.0
defaults:
run:
working-directory: ./api
Expand All @@ -34,6 +45,11 @@ jobs:
with:
go-version: '1.21'
cache-dependency-path: "**/*.sum"
- name: Choose the Envoy API
run: |
pushd ..
./patch/switch-envoy-go-version.sh ${FULL_ENVOY_VERSION}
popd

- name: Unit test
run: make unit-test
Expand All @@ -47,7 +63,7 @@ jobs:
if: failure()
with:
# upload artifact can be found in https://github.com/mosn/htnn/actions/runs/$id
name: api-module-test-logs
name: api-module-test-logs-${{ matrix.envoy_version }}
path: ./test-envoy

- name: Generate coverage
Expand All @@ -58,7 +74,7 @@ jobs:
if: always() # always upload coverage, so the coverage percents won't affect by the failed tests
uses: actions/upload-artifact@v4
with:
name: api-module-test-cover
name: api-module-test-cover-${{ matrix.envoy_version }}
path: |
./api/cover.out
./api/cover_integration.out
Expand Down Expand Up @@ -213,8 +229,10 @@ jobs:
with:
fail_ci_if_error: true
files: |
./api-module-test-cover/cover.out,
./api-module-test-cover/cover_integration.out,
./api-module-test-cover-1.29/cover.out,
./api-module-test-cover-1.29/cover_integration.out,
./api-module-test-cover-1.31/cover.out,
./api-module-test-cover-1.31/cover_integration.out,
./types-module-test-cover/cover.out,
./plugins-unit-test-cover/cover.out,
./plugins-integration-test-cover/cover.out,
Expand Down
3 changes: 1 addition & 2 deletions MAINTAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ To release a new version, please follow the steps below:
To upgrade Istio, please follow the steps below:

* Discuss the impact of the upgrade. For example, is there any break change, do we need to upgrade K8S, etc.
* Update the base image used in the integration tests.
* Update the ISTIO_VERSION we define in the `common.mk`.
* Update the ISTIO_VERSION we define in the `common.mk` and the dataplane image's Dockerfile.
* Update the link `/envoy/v1.xx.y/configuration/` in the doc to the new Envoy version. And `istio/istio/xxx` to the new Istio version.
* Update the charts' dependency versions used in the `manifests/charts/*/Chart.yaml`.

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ HTNN (Hyper Trust-Native Network) is Ant Group's internally developed cloud-nati
* [Quick Start](https://github.com/mosn/htnn/blob/main/site/content/en/docs/getting-started/quick_start.md)
* [Get Involved](https://github.com/mosn/htnn/blob/main/site/content/en/docs/developer-guide/get_involved.md)

If you want to extend Envoy via Go, you can consider using the dataplane of HTNN only. Please read the documentation:

* [Dataplane Support](https://github.com/mosn/htnn/blob/main/site/content/en/docs/developer-guide/dataplane_support.md)

## Community

### Chinese
Expand Down
9 changes: 5 additions & 4 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ include ../common.mk

.PHONY: unit-test
unit-test:
go test ${TEST_OPTION} $(shell go list ./... | \
go test -tags envoy${ENVOY_API_VERSION} ${TEST_OPTION} $(shell go list ./... | \
grep -v tests/integration)

# We can't specify -race to `go build` because it seems that
# race detector assumes that the executable is loaded around the 0 address. When loaded by the Envoy,
# the race detector will allocate memory out of 48bits address which is not allowed in x64.
.PHONY: build-test-so-local
build-test-so-local:
CGO_ENABLED=1 go build -tags so \
CGO_ENABLED=1 go build -tags so,envoy${ENVOY_API_VERSION} \
-ldflags "-B 0x$(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') " \
--buildmode=c-shared \
-cover -covermode=atomic -coverpkg=${PROJECT_NAME}/... \
Expand All @@ -39,6 +39,7 @@ build-test-so:
-v $(PWD)/..:/go/src/${PROJECT_NAME} \
-w /go/src/${PROJECT_NAME}/api \
-e GOPROXY \
-e ENVOY_API_VERSION \
${BUILD_IMAGE} \
bash -c "git config --global --add safe.directory '*' && make build-test-so-local"

Expand All @@ -47,10 +48,10 @@ build-test-so:
integration-test:
test -d /tmp/htnn_coverage && rm -rf /tmp/htnn_coverage || true
$(foreach PKG, $(shell go list ./tests/integration/...), \
go test -v ${PKG} || exit 1; \
go test -tags envoy${ENVOY_API_VERSION} -v ${PKG} || exit 1; \
)

# The benchmark running time can be controlled via env var HTNN_DATA_PLANE_BENCHMARK_DURATION
.PHONY: benchmark
benchmark:
go test -tags benchmark -v ./tests/integration/ -run TestBenchmark
go test -tags benchmark,envoy${ENVOY_API_VERSION} -v ./tests/integration/ -run TestBenchmark
4 changes: 2 additions & 2 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go 1.21
require (
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa
github.com/envoyproxy/envoy v1.29.4
github.com/envoyproxy/envoy v1.31.0
github.com/envoyproxy/go-control-plane v0.12.1-0.20240117015050-472addddff92 // version used by istio 1.21
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/go-logr/logr v1.4.1
Expand All @@ -31,7 +31,7 @@ require (
go.uber.org/zap v1.27.0
golang.org/x/net v0.24.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
8 changes: 4 additions & 4 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/P
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/envoy v1.29.4 h1:1c52LYxzA6arnSjpTfDyxCSrtztwVAnzekcGHirvq8Y=
github.com/envoyproxy/envoy v1.29.4/go.mod h1:c2OGLXJVY9BaTYPiWFRz6eUNaC+3TfqFKmkWS9brdKo=
github.com/envoyproxy/envoy v1.31.0 h1:NsTo+medzu0bMffXAjl+zKaViLOShKuIZWQnKKYq0/4=
github.com/envoyproxy/envoy v1.31.0/go.mod h1:ujBFxE543X8OePZG+FbeR9LnpBxTLu64IAU7A20EB9A=
github.com/envoyproxy/go-control-plane v0.12.1-0.20240117015050-472addddff92 h1:/3bsjkhOTh0swUKDBxL1+3MrXCxrf/sEEMseiIEJg00=
github.com/envoyproxy/go-control-plane v0.12.1-0.20240117015050-472addddff92/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0=
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
Expand Down Expand Up @@ -59,8 +59,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
10 changes: 4 additions & 6 deletions api/pkg/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@
conf *consumerManagerConfig
}

func ConsumerManagerFactory(c interface{}) capi.StreamFilterFactory {
func ConsumerManagerFactory(c interface{}, callbacks capi.FilterCallbackHandler) capi.StreamFilter {
conf, ok := c.(*consumerManagerConfig)
if !ok {
panic(fmt.Sprintf("wrong config type: %s", reflect.TypeOf(c)))
}
return func(callbacks capi.FilterCallbackHandler) capi.StreamFilter {
return &consumerManager{
callbacks: callbacks,
conf: conf,
}
return &consumerManager{
callbacks: callbacks,
conf: conf,

Check warning on line 46 in api/pkg/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

api/pkg/consumer/consumer.go#L44-L46

Added lines #L44 - L46 were not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/pkg/consumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ func TestParse(t *testing.T) {

func TestConsumerManagerFactory(t *testing.T) {
assert.PanicsWithValuef(t, "wrong config type: *struct {}", func() {
ConsumerManagerFactory(&struct{}{})
ConsumerManagerFactory(&struct{}{}, nil)
}, "check if the panic message contains the wrong type")
}
8 changes: 3 additions & 5 deletions api/pkg/dynamicconfig/dynamicconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@
callbacks capi.FilterCallbackHandler
}

func DynamicConfigFactory(c interface{}) capi.StreamFilterFactory {
return func(callbacks capi.FilterCallbackHandler) capi.StreamFilter {
return &dynamicConfigFilter{
callbacks: callbacks,
}
func DynamicConfigFactory(_ interface{}, callbacks capi.FilterCallbackHandler) capi.StreamFilter {
return &dynamicConfigFilter{
callbacks: callbacks,

Check warning on line 46 in api/pkg/dynamicconfig/dynamicconfig.go

View check run for this annotation

Codecov / codecov/patch

api/pkg/dynamicconfig/dynamicconfig.go#L44-L46

Added lines #L44 - L46 were not covered by tests
}
}

Expand Down
136 changes: 33 additions & 103 deletions api/pkg/filtermanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package api
import (
"net/http"
"net/url"
"sync/atomic"

"github.com/envoyproxy/envoy/contrib/golang/common/go/api"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down Expand Up @@ -172,6 +171,8 @@ type StreamInfo interface {
FilterState() FilterState
// VirtualClusterName returns the name of the virtual cluster which got matched
VirtualClusterName() (string, bool)
// WorkerID returns the ID of the Envoy worker thread
WorkerID() uint32

// Methods added by HTNN

Expand All @@ -194,13 +195,10 @@ type Consumer interface {
PluginConfig(name string) PluginConsumerConfig
}

// FilterCallbackHandler provides API that is used during request processing
type FilterCallbackHandler interface {
// StreamFilterCallbacks provides API that is used during request processing
type StreamFilterCallbacks interface {
// StreamInfo provides API to get/set current stream's context.
StreamInfo() StreamInfo
// RecoverPanic covers panic to 500 response to avoid crashing Envoy. If you create goroutine
// in your Filter, please add `defer RecoverPanic()` to avoid crash by panic.
RecoverPanic()
// GetProperty fetch Envoy attribute and return the value as a string.
// The list of attributes can be found in https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes.
// If the fetch succeeded, a string will be returned.
Expand All @@ -212,6 +210,9 @@ type FilterCallbackHandler interface {
// * ErrSerializationFailure (Currently, fetching attributes in List/Map type are unsupported)
// * ErrValueNotFound
GetProperty(key string) (string, error)
// ClearRouteCache clears the route cache for the current request, and filtermanager will re-fetch the route in the next filter.
// Please be careful to invoke it, since filtermanager will raise an 404 route_not_found response when failed to re-fetch a route.
ClearRouteCache()

// Methods added by HTNN

Expand All @@ -229,7 +230,7 @@ type FilterCallbackHandler interface {
// WithLogArg injectes `key: value` as the suffix of application log created by this
// callback's Log* methods. The injected log arguments are only valid in the current request.
// This method can be used to inject IDs or other context information into the logs.
WithLogArg(key string, value any) FilterCallbackHandler
WithLogArg(key string, value any) StreamFilterCallbacks
LogTracef(format string, v ...any)
LogTrace(message string)
LogDebugf(format string, v ...any)
Expand All @@ -242,6 +243,31 @@ type FilterCallbackHandler interface {
LogError(message string)
}

// FilterProcessCallbacks is the interface for filter to process request/response in decode/encode phase.
type FilterProcessCallbacks interface {
SendLocalReply(responseCode int, bodyText string, headers map[string][]string, grpcStatus int64, details string)
// RecoverPanic recover panic in defer and terminate the request by SendLocalReply with 500 status code.
RecoverPanic()

// hide Continue() method from the user
}

type DecoderFilterCallbacks interface {
FilterProcessCallbacks
}

type EncoderFilterCallbacks interface {
FilterProcessCallbacks
}

type FilterCallbackHandler interface {
StreamFilterCallbacks
// DecoderFilterCallbacks could only be used in DecodeXXX phases.
DecoderFilterCallbacks() DecoderFilterCallbacks
// EncoderFilterCallbacks could only be used in EncodeXXX phases.
EncoderFilterCallbacks() EncoderFilterCallbacks
}

// FilterFactory returns a per-request Filter which has configuration bound to it.
// This function should be a pure builder and should not have any side effect.
type FilterFactory func(config interface{}, callbacks FilterCallbackHandler) Filter
Expand Down Expand Up @@ -282,102 +308,6 @@ var (
LogLevelCritical = api.Critical
)

// Drop our log optimization once https://github.com/envoyproxy/envoy/commit/591fb13817ddf1f54945186e3c6de4e0345508d2
// is used.

var (
currLogLevel atomic.Int32
)

func GetLogLevel() LogType {
lv := currLogLevel.Load()
return LogType(lv)
}

func LogTrace(message string) {
if GetLogLevel() > LogLevelTrace {
return
}
api.LogTrace(message)
}

func LogDebug(message string) {
if GetLogLevel() > LogLevelDebug {
return
}
api.LogDebug(message)
}

func LogInfo(message string) {
if GetLogLevel() > LogLevelInfo {
return
}
api.LogInfo(message)
}

func LogWarn(message string) {
if GetLogLevel() > LogLevelWarn {
return
}
api.LogWarn(message)
}

func LogError(message string) {
if GetLogLevel() > LogLevelError {
return
}
api.LogError(message)
}

func LogCritical(message string) {
if GetLogLevel() > LogLevelCritical {
return
}
api.LogCritical(message)
}

func LogTracef(format string, v ...any) {
if GetLogLevel() > LogLevelTrace {
return
}
api.LogTracef(format, v...)
}

func LogDebugf(format string, v ...any) {
if GetLogLevel() > LogLevelDebug {
return
}
api.LogDebugf(format, v...)
}

func LogInfof(format string, v ...any) {
if GetLogLevel() > LogLevelInfo {
return
}
api.LogInfof(format, v...)
}

func LogWarnf(format string, v ...any) {
if GetLogLevel() > LogLevelWarn {
return
}
api.LogWarnf(format, v...)
}

func LogErrorf(format string, v ...any) {
if GetLogLevel() > LogLevelError {
return
}
api.LogErrorf(format, v...)
}

func LogCriticalf(format string, v ...any) {
if GetLogLevel() > LogLevelCritical {
return
}
api.LogCriticalf(format, v...)
}

var (
ErrInternalFailure = api.ErrInternalFailure
ErrSerializationFailure = api.ErrSerializationFailure
Expand Down
Loading
Loading