Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/shimengwang/htnn
Browse files Browse the repository at this point in the history
  • Loading branch information
shimengwang committed Dec 24, 2024
2 parents 3ff6759 + 4a561be commit 45afd09
Show file tree
Hide file tree
Showing 110 changed files with 3,507 additions and 907 deletions.
7 changes: 3 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<!--
Please change the [issue] below to the number of issue which is addressed by this
pull request if there is one.
Please uncomment and change the [issue] below to the number of issue which is
addressed by this pull request if there is one.
If the pull request references an issue X but does not close it, please change the
prompt to "Ref #X".
If there is no issue, please remove this prompt.
-->

Fix #[issue]
<!--Fix #[issue]-->

<!--
Before submitting a pull request, please make sure the following is done:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build-and-push-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

# The built image can be found in:
# https://github.com/mosn/htnn/pkgs/container/htnn-controller
# https://github.com/mosn/htnn/pkgs/container/htnn-proxy
- name: Build and push Docker image
run: |
make prebuild
cd ./manifests
# push image with the dev tag
export PROXY_IMAGE=${{ env.PROXY_IMAGE_NAME }}:dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: size-label
uses: "pascalgn/[email protected].4"
uses: "pascalgn/[email protected].5"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
IGNORED: "**/*.pb.*\n*.sum\ntypes/pkg/client/**\n**/zz_generated.deepcopy.go"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: binary-cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"
- name: Check helm files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

# The built image can be found in:
Expand Down
36 changes: 25 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
envoy_version:
- 1.29
- 1.31
- 1.32
- dev
env:
ENVOY_API_VERSION: ${{ matrix.envoy_version }}
Expand All @@ -43,20 +44,20 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"
- name: Choose the Envoy API
run: |
FULL_ENVOY_VERSION=${ENVOY_API_VERSION}.0
if [[ $ENVOY_API_VERSION == dev ]]; then
# update this once there are more breaking changes
FULL_ENVOY_VERSION=1.31.1-0.20240909145059-353737786a7f
# This is the envoy:contrib-dev image pull in 2024-09-25.
FULL_ENVOY_VERSION=1.32.1-0.20241112025658-4fd9bb670eeb
# This is the envoy:contrib-dev image pull in 2024-11-12.
# Use docker inspect --format='{{index .RepoDigests 0}}' envoyproxy/envoy:contrib-dev to get the sha256 ID.
# We don't use the envoy:contrib-dev tag directly because it will be rewritten by the latest commit and
# our test suite uses IfPresent policy to pull image.
# We don't use the CI to catch the breaking change from the upstream so far.
export PROXY_IMAGE=envoyproxy/envoy@sha256:845c392c1f128a00c49439d129ca9f2c12ff8748aeb42c8aa2b3b8240d6e0d5b
export PROXY_IMAGE=envoyproxy/envoy@sha256:0eec2cbd45c2055ea37c2321e8b83f6907a95e98c250492b48ad9dab6a20a8cb
echo PROXY_IMAGE=$PROXY_IMAGE >> $GITHUB_ENV
fi
pushd ..
Expand Down Expand Up @@ -100,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 All @@ -112,7 +119,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: Unit test
Expand All @@ -138,7 +145,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: Test
Expand All @@ -153,6 +160,11 @@ jobs:
plugins-integration-test:
timeout-minutes: 10
runs-on: ubuntu-latest
env:
# to test the custom port feature
TEST_ENVOY_ADMIN_API_PORT: 9901
TEST_ENVOY_CONTROL_PLANE_PORT: 9902
TEST_ENVOY_DATA_PLANE_PORT: 9903
defaults:
run:
working-directory: ./plugins
Expand All @@ -162,7 +174,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: Set up services
Expand Down Expand Up @@ -204,7 +216,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: binary cache
Expand Down Expand Up @@ -241,14 +253,16 @@ jobs:
- name: Download artifact
uses: actions/download-artifact@v4
- name: Upload to codecov
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.1.2
with:
fail_ci_if_error: true
files: |
./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,
./api-module-test-cover-1.32/cover.out,
./api-module-test-cover-1.32/cover_integration.out,
./api-module-test-cover-dev/cover.out,
./api-module-test-cover-dev/cover_integration.out,
./types-module-test-cover/cover.out,
Expand All @@ -268,7 +282,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: Example
Expand All @@ -292,7 +306,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
cache-dependency-path: "**/*.sum"

- name: binary cache
Expand Down
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
run:
deadline: 5m
timeout: 5m

linters:
enable:
# sorted in alphabetic order
- bodyclose
- contextcheck
- errcheck
- exportloopref
- copyloopvar
- forcetypeassert
- gocheckcompilerdirectives
- gocritic
Expand All @@ -31,6 +31,7 @@ linters-settings:
- opinionated
gosec:
excludes:
- G115 # Ignore "integer overflow conversion int". Since we call the conversion explicitly, we know what we do.
- G402 # TLS InsecureSkipVerify may be true.
revive:
rules:
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# See https://github.com/orgs/community/discussions/23042

# Plugins

/*/plugins/sentinel @WeixinX

# Registries
/*/registries/consul @lyt122
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ build-dev-tools:
build-dev-tools-local:
docker build --network=host --build-arg GOPROXY=${GOPROXY} -t ${DEV_TOOLS_IMAGE} -f tools/Dockerfile.dev ./tools

GOLANGCI_LINT_VERSION = 1.56.1
GOLANGCI_LINT_VERSION = 1.61.0
.PHONY: lint-go
lint-go:
if ! test -x $(LOCALBIN)/golangci-lint || ! $(LOCALBIN)/golangci-lint --version | grep $(GOLANGCI_LINT_VERSION) >/dev/null; then \
Expand Down Expand Up @@ -215,8 +215,10 @@ verify-example:
cd ./examples/dev_your_plugin && ./verify.sh

# use a path outside repo so the linters won't lint the istio files
TARGET_ISTIO_DIR ?= $(shell pwd)/../istio
TARGET_ISTIO_DIR = $(shell pwd)/../istio

# When you run `prebuild`, please ensure the HTNN is downloaded as `./htnn`, so the patch can work correctly.
# And if the `istio` exists, ensure it is in the correct $ISTIO_VERSION. Otherwise, the patch may not be applied correctly.
.PHONY: prebuild
prebuild:
if [[ ! -d $(TARGET_ISTIO_DIR) ]]; then \
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
6 changes: 3 additions & 3 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ module mosn.io/htnn/api

// This module puts the filtermanager and the API and test framework which can be used in the plugins.

go 1.21
go 1.22

require (
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa
github.com/envoyproxy/envoy v1.31.0
github.com/envoyproxy/envoy v1.32.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.34.1
google.golang.org/protobuf v1.35.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.31.0 h1:NsTo+medzu0bMffXAjl+zKaViLOShKuIZWQnKKYq0/4=
github.com/envoyproxy/envoy v1.31.0/go.mod h1:ujBFxE543X8OePZG+FbeR9LnpBxTLu64IAU7A20EB9A=
github.com/envoyproxy/envoy v1.32.0 h1:l3WDpm1VsQ+HuvTTKV01p+hIEvoRPB4Mndt9pAg5B2Y=
github.com/envoyproxy/envoy v1.32.0/go.mod h1:KGS+IUehDX1mSIdqodPTWskKOo7bZMLLy3GHxvOKcJk=
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.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
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
17 changes: 10 additions & 7 deletions api/internal/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ type Consumer struct {
FilterConfigs map[string]*fmModel.ParsedFilterConfig

// fields that generated from the configuration
CanSkipMethod map[string]bool
FilterNames []string
InitOnce sync.Once
CanSkipMethodOnce sync.Once
FilterNames []string
InitOnce sync.Once
CanSkipMethods map[string]bool
CanSkipMethodsOnce sync.Once
CanSyncRunMethod map[string]bool
// CanSyncRunMethod share the same sync.Once with CanSkipMethodOnce
}

func (c *Consumer) Unmarshal(s string) error {
Expand Down Expand Up @@ -92,9 +94,10 @@ func (c *Consumer) InitConfigs() error {
}

c.FilterConfigs[name] = &fmModel.ParsedFilterConfig{
Name: name,
ParsedConfig: conf,
Factory: p.Factory,
Name: name,
ParsedConfig: conf,
Factory: p.Factory,
SyncRunPhases: p.ConfigParser.NonBlockingPhases(),
}
}

Expand Down
6 changes: 6 additions & 0 deletions api/pkg/filtermanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ type StreamFilterCallbacks interface {
// 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()
// RefreshRouteCache works like ClearRouteCache, but it will re-fetch the route immediately.
RefreshRouteCache()

// Methods added by HTNN

Expand Down Expand Up @@ -248,6 +250,10 @@ 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()
// AddData add extra data when processing headers/trailers.
// For example, turn a headers only request into a request with a body, add more body when processing trailers, and so on.
// The second argument isStreaming supplies if this caller streams data or buffers the full body.
AddData(data []byte, isStreaming bool)

// hide Continue() method from the user
}
Expand Down
Loading

0 comments on commit 45afd09

Please sign in to comment.