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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 4 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_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_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 @@ -47,10 +47,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_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_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