From 4ccb786c81f6e97d7e14816554cc9d308b26312b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Thu, 24 Oct 2024 10:46:39 +0800 Subject: [PATCH 01/49] dev: fix broken 'make prebuild' (#780) Signed-off-by: spacewander --- .github/workflows/build-and-push-dev-image.yml | 1 - Makefile | 4 +++- manifests/images/cp/Dockerfile | 12 ++++++------ manifests/images/dp/Dockerfile | 14 +++++++------- patch/istio/1.21/20240410-htnn-go-mod.patch | 6 +++--- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-and-push-dev-image.yml b/.github/workflows/build-and-push-dev-image.yml index 9304b93b..740c334a 100644 --- a/.github/workflows/build-and-push-dev-image.yml +++ b/.github/workflows/build-and-push-dev-image.yml @@ -44,7 +44,6 @@ jobs: # 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 diff --git a/Makefile b/Makefile index 00454a66..c6b890a7 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/manifests/images/cp/Dockerfile b/manifests/images/cp/Dockerfile index 1c2800da..b955df3e 100644 --- a/manifests/images/cp/Dockerfile +++ b/manifests/images/cp/Dockerfile @@ -23,12 +23,12 @@ ARG TARGETARCH ARG GOPROXY ENV GOPROXY=$GOPROXY -WORKDIR /workspace +WORKDIR /htnn # Copy the source COPY go.* ./ -RUN sed -i 's/.\/site/.\/external\/istio/' go.work && sed -i '/.\/e2e/d' go.work && sed -i '/.\/tools/d' go.work +RUN sed -i '/.\/site/d' go.work && sed -i '/.\/e2e/d' go.work && sed -i '/.\/tools/d' go.work # use single layer to copy only works on files, so we have to list all the directories COPY api/ api/ COPY types/ types/ @@ -49,9 +49,9 @@ _EOF # hadolint ignore=DL3008 RUN apt-get update && apt-get install -y patch --no-install-recommends -RUN TARGET_ISTIO_DIR=$(pwd)/external/istio make prebuild -WORKDIR /workspace/external/istio -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -C pilot/cmd/pilot-discovery -a -o /workspace/pilot-discovery +RUN make prebuild +WORKDIR /istio +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -C pilot/cmd/pilot-discovery -a -o /htnn/pilot-discovery # hadolint ignore=DL3006 FROM ${CONTROLLER_BASE_IMAGE} @@ -62,4 +62,4 @@ LABEL org.opencontainers.image.source=https://github.com/mosn/htnn LABEL org.opencontainers.image.description="This is image used in the HTNN control plane." LABEL org.opencontainers.image.licenses="Apache-2.0" -COPY --from=builder /workspace/pilot-discovery /usr/local/bin/ +COPY --from=builder /htnn/pilot-discovery /usr/local/bin/ diff --git a/manifests/images/dp/Dockerfile b/manifests/images/dp/Dockerfile index 75c9f0cf..2842c6ac 100644 --- a/manifests/images/dp/Dockerfile +++ b/manifests/images/dp/Dockerfile @@ -23,12 +23,12 @@ ARG TARGETARCH ARG GOPROXY ENV GOPROXY=$GOPROXY -WORKDIR /workspace +WORKDIR /htnn # Copy the source COPY go.* ./ -RUN sed -i 's/.\/site/.\/external\/istio/' go.work && sed -i '/.\/e2e/d' go.work && sed -i '/.\/tools/d' go.work +RUN sed -i '/.\/site/d' go.work && sed -i '/.\/e2e/d' go.work && sed -i '/.\/tools/d' go.work COPY api/ api/ COPY types/ types/ COPY plugins/ plugins/ @@ -48,7 +48,7 @@ _EOF # hadolint ignore=DL3008 RUN apt-get update && apt-get install -y patch --no-install-recommends -RUN TARGET_ISTIO_DIR=$(pwd)/external/istio make prebuild +RUN make prebuild COPY patch/switch-envoy-go-version.sh patch/switch-envoy-go-version.sh COPY common.mk common.mk @@ -57,8 +57,8 @@ RUN ./patch/switch-envoy-go-version.sh 1.29.5 && \ cd plugins/ && \ ENVOY_API_VERSION=1.29 make build-so-local -WORKDIR /workspace/external/istio -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -C pilot/cmd/pilot-agent -a -o /workspace/pilot-agent +WORKDIR /istio +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -C pilot/cmd/pilot-agent -a -o /htnn/pilot-agent # hadolint ignore=DL3006 FROM ${PROXY_BASE_IMAGE} @@ -69,6 +69,6 @@ LABEL org.opencontainers.image.source=https://github.com/mosn/htnn LABEL org.opencontainers.image.description="This is image used in the HTNN data plane." LABEL org.opencontainers.image.licenses="Apache-2.0" -COPY --from=builder /workspace/pilot-agent /usr/local/bin/ -COPY --from=builder /workspace/plugins/libgolang.so /etc/libgolang.so +COPY --from=builder /htnn/pilot-agent /usr/local/bin/ +COPY --from=builder /htnn/plugins/libgolang.so /etc/libgolang.so CMD ["envoy"] diff --git a/patch/istio/1.21/20240410-htnn-go-mod.patch b/patch/istio/1.21/20240410-htnn-go-mod.patch index 8944209b..c0df3851 100644 --- a/patch/istio/1.21/20240410-htnn-go-mod.patch +++ b/patch/istio/1.21/20240410-htnn-go-mod.patch @@ -12,9 +12,9 @@ index e7f308e890..def9507093 100644 +) + +replace ( -+ mosn.io/htnn/api => ../../api -+ mosn.io/htnn/controller => ../../controller -+ mosn.io/htnn/types => ../../types ++ mosn.io/htnn/api => ../htnn/api ++ mosn.io/htnn/controller => ../htnn/controller ++ mosn.io/htnn/types => ../htnn/types +) + +// Downgrade some deps to match the one used in istio From f5e0d1424f3fddcf11703d3a8e69e249a209c9ee Mon Sep 17 00:00:00 2001 From: shimengwang Date: Thu, 24 Oct 2024 11:30:15 +0800 Subject: [PATCH 02/49] Update bootstrap.yml to fix host.docker.internal resolve as ip v6 address in docker v4.31.0 (#781) Update bootstrap.yml fix host.docker.internal resolve as ip v6 address in docker v4.31.0, see docker issue[7332](https://github.com/docker/for-mac/issues/7332) --- api/plugins/tests/integration/dataplane/bootstrap.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/api/plugins/tests/integration/dataplane/bootstrap.yml b/api/plugins/tests/integration/dataplane/bootstrap.yml index c26e0c06..ee1b30f6 100644 --- a/api/plugins/tests/integration/dataplane/bootstrap.yml +++ b/api/plugins/tests/integration/dataplane/bootstrap.yml @@ -258,6 +258,7 @@ static_resources: socket_address: address: host.docker.internal port_value: 9999 + dns_lookup_family: V4_ONLY admin: address: From e0c9ce2c7a75505707e8e4a08db6bea947715b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Mon, 28 Oct 2024 09:58:34 +0800 Subject: [PATCH 03/49] fix: change inner req hdr caused race (#782) https://github.com/mosn/htnn/pull/775 doesn't really fix the problem. Since we already create the wrapper, we should pass the wrapper directly to OnLog, instead of setting the reqHdr field. Signed-off-by: spacewander --- api/pkg/filtermanager/filtermanager_dev.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/api/pkg/filtermanager/filtermanager_dev.go b/api/pkg/filtermanager/filtermanager_dev.go index 85aac872..8502847c 100644 --- a/api/pkg/filtermanager/filtermanager_dev.go +++ b/api/pkg/filtermanager/filtermanager_dev.go @@ -32,10 +32,7 @@ func (m *filterManager) OnLog(reqHdr capi.RequestHeaderMap, reqTrailer capi.Requ wrappedReqHdr := &filterManagerRequestHeaderMap{ RequestHeaderMap: reqHdr, } - m.hdrLock.Lock() - m.reqHdr = wrappedReqHdr - m.hdrLock.Unlock() - m.runOnLogPhase(m.reqHdr, reqTrailer, rspHdr, rspTrailer) + m.runOnLogPhase(wrappedReqHdr, reqTrailer, rspHdr, rspTrailer) } func wrapFilterManager(fm *filterManager) capi.StreamFilter { From d20f408cc78b3da8fdcf2f51817695a563cda589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Mon, 28 Oct 2024 09:58:51 +0800 Subject: [PATCH 04/49] debugmode: reduce the data we collect (#784) Signed-off-by: spacewander --- api/pkg/filtermanager/model/model.go | 2 +- api/pkg/filtermanager/wrapper.go | 28 ++++++++++---------- api/pkg/filtermanager/wrapper_test.go | 23 +++++++++++----- plugins/plugins/debugmode/filter.go | 13 ++++----- plugins/tests/integration/debug_mode_test.go | 6 ++--- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/api/pkg/filtermanager/model/model.go b/api/pkg/filtermanager/model/model.go index 0ae4bf89..008ee258 100644 --- a/api/pkg/filtermanager/model/model.go +++ b/api/pkg/filtermanager/model/model.go @@ -51,5 +51,5 @@ func NewFilterWrapper(name string, f api.Filter) *FilterWrapper { type ExecutionRecord struct { PluginName string - Record map[string]time.Duration + Record time.Duration } diff --git a/api/pkg/filtermanager/wrapper.go b/api/pkg/filtermanager/wrapper.go index 570195c8..b29bb245 100644 --- a/api/pkg/filtermanager/wrapper.go +++ b/api/pkg/filtermanager/wrapper.go @@ -129,57 +129,57 @@ func NewDebugFilter(name string, internal api.Filter, callbacks api.FilterCallba } } -func (f *debugFilter) recordExecution(start time.Time, method string) { +func (f *debugFilter) recordExecution(start time.Time) { duration := time.Since(start) executionRecords := f.callbacks.PluginState().Get("debugMode", "executionRecords") if executionRecords == nil { - executionRecords = []model.ExecutionRecord{} + executionRecords = []*model.ExecutionRecord{} f.callbacks.PluginState().Set("debugMode", "executionRecords", executionRecords) } - records, ok := executionRecords.([]model.ExecutionRecord) + records, ok := executionRecords.([]*model.ExecutionRecord) if !ok { panic(fmt.Sprintf("unexpected type: %s", reflect.TypeOf(executionRecords))) } for _, record := range records { if record.PluginName == f.name { - record.Record[method] += duration + record.Record += duration return } } - f.callbacks.PluginState().Set("debugMode", "executionRecords", append(records, model.ExecutionRecord{ + f.callbacks.PluginState().Set("debugMode", "executionRecords", append(records, &model.ExecutionRecord{ PluginName: f.name, - Record: map[string]time.Duration{method: duration}, + Record: duration, })) } func (f *debugFilter) DecodeHeaders(headers api.RequestHeaderMap, endStream bool) api.ResultAction { - defer f.recordExecution(time.Now(), "DecodeHeaders") + defer f.recordExecution(time.Now()) return f.internal.DecodeHeaders(headers, endStream) } func (f *debugFilter) DecodeData(data api.BufferInstance, endStream bool) api.ResultAction { - defer f.recordExecution(time.Now(), "DecodeData") + defer f.recordExecution(time.Now()) return f.internal.DecodeData(data, endStream) } func (f *debugFilter) DecodeTrailers(trailers api.RequestTrailerMap) api.ResultAction { - defer f.recordExecution(time.Now(), "DecodeTrailers") + defer f.recordExecution(time.Now()) return f.internal.DecodeTrailers(trailers) } func (f *debugFilter) EncodeHeaders(headers api.ResponseHeaderMap, endStream bool) api.ResultAction { - defer f.recordExecution(time.Now(), "EncodeHeaders") + defer f.recordExecution(time.Now()) return f.internal.EncodeHeaders(headers, endStream) } func (f *debugFilter) EncodeData(data api.BufferInstance, endStream bool) api.ResultAction { - defer f.recordExecution(time.Now(), "EncodeData") + defer f.recordExecution(time.Now()) return f.internal.EncodeData(data, endStream) } func (f *debugFilter) EncodeTrailers(trailers api.ResponseTrailerMap) api.ResultAction { - defer f.recordExecution(time.Now(), "EncodeTrailers") + defer f.recordExecution(time.Now()) return f.internal.EncodeTrailers(trailers) } @@ -191,11 +191,11 @@ func (f *debugFilter) OnLog(reqHeaders api.RequestHeaderMap, reqTrailers api.Req } func (f *debugFilter) DecodeRequest(headers api.RequestHeaderMap, data api.BufferInstance, trailers api.RequestTrailerMap) api.ResultAction { - defer f.recordExecution(time.Now(), "DecodeRequest") + defer f.recordExecution(time.Now()) return f.internal.DecodeRequest(headers, data, trailers) } func (f *debugFilter) EncodeResponse(headers api.ResponseHeaderMap, data api.BufferInstance, trailers api.ResponseTrailerMap) api.ResultAction { - defer f.recordExecution(time.Now(), "EncodeResponse") + defer f.recordExecution(time.Now()) return f.internal.EncodeResponse(headers, data, trailers) } diff --git a/api/pkg/filtermanager/wrapper_test.go b/api/pkg/filtermanager/wrapper_test.go index 55604d96..92bbe50b 100644 --- a/api/pkg/filtermanager/wrapper_test.go +++ b/api/pkg/filtermanager/wrapper_test.go @@ -35,29 +35,40 @@ func TestDebugFilter(t *testing.T) { f2.DecodeHeaders(nil, true) f1.DecodeHeaders(nil, true) - records := cb.PluginState().Get("debugMode", "executionRecords").([]model.ExecutionRecord) + records := cb.PluginState().Get("debugMode", "executionRecords").([]*model.ExecutionRecord) t.Logf("get records %+v\n", records) // for debug when test failed assert.Equal(t, 2, len(records)) assert.Equal(t, "two", records[0].PluginName) - assert.True(t, records[0].Record["DecodeHeaders"] > 0) + assert.True(t, records[0].Record > 0) assert.Equal(t, "one", records[1].PluginName) - assert.True(t, records[1].Record["DecodeHeaders"] > 0) + assert.True(t, records[1].Record > 0) + decodeHeadersCost := records[1].Record patches := gomonkey.ApplyMethodFunc(raw1, "DecodeData", func(data api.BufferInstance, endStream bool) api.ResultAction { time.Sleep(100 * time.Millisecond) return api.Continue }) + patches.ApplyMethodFunc(raw1, "EncodeHeaders", func(headers api.ResponseHeaderMap, endStream bool) api.ResultAction { + time.Sleep(50 * time.Millisecond) + return api.Continue + }) + patches.ApplyMethodFunc(raw1, "EncodeData", func(data api.BufferInstance, endStream bool) api.ResultAction { + time.Sleep(20 * time.Millisecond) + return api.Continue + }) defer patches.Reset() f1.DecodeData(nil, false) f1.DecodeData(nil, true) + f1.EncodeHeaders(nil, false) + f1.EncodeData(nil, true) - records = cb.PluginState().Get("debugMode", "executionRecords").([]model.ExecutionRecord) + records = cb.PluginState().Get("debugMode", "executionRecords").([]*model.ExecutionRecord) t.Logf("get records %+v\n", records) // for debug when test failed assert.Equal(t, 2, len(records)) assert.Equal(t, "one", records[1].PluginName) // Should be the sum of multiple calls delta := 10 * time.Millisecond - rec := records[1].Record["DecodeData"] - assert.True(t, 200*time.Millisecond-delta < rec && rec < 200*time.Millisecond+delta, rec) + rec := records[1].Record - decodeHeadersCost + assert.True(t, 270*time.Millisecond-delta < rec && rec < 270*time.Millisecond+delta, rec) } diff --git a/plugins/plugins/debugmode/filter.go b/plugins/plugins/debugmode/filter.go index 4e3bfd05..2e1f9706 100644 --- a/plugins/plugins/debugmode/filter.go +++ b/plugins/plugins/debugmode/filter.go @@ -38,8 +38,8 @@ type filter struct { } type executionPlugin struct { - Name string `json:"name"` - PerPhaseCostSeconds map[string]float64 `json:"per_phase_cost_seconds"` + Name string `json:"name"` + CostSeconds float64 `json:"cost_seconds"` } type SlowLogReport struct { @@ -104,14 +104,11 @@ func (f *filter) OnLog(reqHeaders api.RequestHeaderMap, reqTrailers api.RequestT // This is a private API and we don't guarantee its stablibity r := f.callbacks.PluginState().Get("debugMode", "executionRecords") if r != nil { - executionRecords := r.([]model.ExecutionRecord) + executionRecords := r.([]*model.ExecutionRecord) for _, record := range executionRecords { p := executionPlugin{ - Name: record.PluginName, - } - p.PerPhaseCostSeconds = make(map[string]float64) - for k, v := range record.Record { - p.PerPhaseCostSeconds[k] = v.Seconds() + Name: record.PluginName, + CostSeconds: record.Record.Seconds(), } report.ExecutedPlugins = append(report.ExecutedPlugins, p) } diff --git a/plugins/tests/integration/debug_mode_test.go b/plugins/tests/integration/debug_mode_test.go index 2bf15e16..dd3b4a49 100644 --- a/plugins/tests/integration/debug_mode_test.go +++ b/plugins/tests/integration/debug_mode_test.go @@ -31,7 +31,7 @@ func TestDebugModeSlowLog(t *testing.T) { dp, err := dataplane.StartDataPlane(t, &dataplane.Option{ NoErrorLogCheck: true, ExpectLogPattern: []string{ - `slow log report:.+"executed_plugins":\[.+"name":"limitReq","per_phase_cost_seconds":\{"DecodeHeaders":.+`, + `slow log report:.+"executed_plugins":\[.+"name":"limitReq","cost_seconds":.+`, }, }) if err != nil { @@ -75,7 +75,7 @@ func TestDebugModeSlowLogNoPlugin(t *testing.T) { dp, err := dataplane.StartDataPlane(t, &dataplane.Option{ NoErrorLogCheck: true, ExpectNoLogPattern: []string{ - `slow log report:.+"executed_plugins":\[.+"name":"limitReq","per_phase_cost_seconds":\{"DecodeHeaders":.+`, + `slow log report:.+"executed_plugins":\[.+"name":"limitReq","cost_seconds":.+`, }, ExpectLogPattern: []string{ `slow log report:.+"server":\["envoy"\]`, @@ -196,7 +196,7 @@ func TestDebugModeSlowLogWithFiltersFromConsumer(t *testing.T) { LogLevel: "debug", NoErrorLogCheck: true, ExpectLogPattern: []string{ - `slow log report:.+"executed_plugins":\[.+"name":"limitReq","per_phase_cost_seconds":\{"DecodeHeaders":.+`, + `slow log report:.+"executed_plugins":\[.+"name":"limitReq","cost_seconds":.+`, }, }) if err != nil { From 63f0785cc126d3f60fa8ec52983dbb1862869d15 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:40:55 +0800 Subject: [PATCH 05/49] build(deps): bump pascalgn/size-label-action from 0.5.4 to 0.5.5 (#785) Bumps [pascalgn/size-label-action](https://github.com/pascalgn/size-label-action) from 0.5.4 to 0.5.5. - [Release notes](https://github.com/pascalgn/size-label-action/releases) - [Commits](https://github.com/pascalgn/size-label-action/compare/v0.5.4...v0.5.5) --- updated-dependencies: - dependency-name: pascalgn/size-label-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index b7ddbc0a..6d23e235 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: size-label - uses: "pascalgn/size-label-action@v0.5.4" + uses: "pascalgn/size-label-action@v0.5.5" env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" IGNORED: "**/*.pb.*\n*.sum\ntypes/pkg/client/**\n**/zz_generated.deepcopy.go" From 862558a32fd10deb1fa488369ce0c3db15aed39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Tue, 29 Oct 2024 15:45:43 +0800 Subject: [PATCH 06/49] test: avoid being conflict with well-known ports (#779) Signed-off-by: spacewander --- .github/workflows/test.yml | 5 ++ .../integration/controlplane/control_plane.go | 13 +++- .../tests/integration/dataplane/bootstrap.go | 14 ++++ .../tests/integration/dataplane/data_plane.go | 47 ++++++++--- .../integration/filtermanager_latest_test.go | 2 +- .../integration/testdata/grpc_backend.yml | 2 +- .../testdata/services/docker-compose.yml | 2 +- .../testdata/services/grpc/main.go | 4 +- plugins/tests/integration/oidc_test.go | 5 +- plugins/tests/integration/sentinel_test.go | 78 +++++++------------ .../plugin_integration_test_framework.md | 11 +-- .../plugin_integration_test_framework.md | 11 +-- 12 files changed, 119 insertions(+), 75 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88532700..c01e46d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -153,6 +153,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 diff --git a/api/plugins/tests/integration/controlplane/control_plane.go b/api/plugins/tests/integration/controlplane/control_plane.go index 92dcf7a2..41967cb1 100644 --- a/api/plugins/tests/integration/controlplane/control_plane.go +++ b/api/plugins/tests/integration/controlplane/control_plane.go @@ -99,7 +99,18 @@ func (cp *ControlPlane) Start() { // only use it on Linux. } - lis, _ := net.Listen("tcp", host+":9999") + port := ":9999" + portEnv := os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT") + if portEnv != "" { + port = ":" + portEnv + } + + lis, err := net.Listen("tcp", host+port) + if err != nil { + logger.Error(err, "failed to listen") + return + } + if err := cp.grpcServer.Serve(lis); err != nil { logger.Error(err, "failed to start control plane") } diff --git a/api/plugins/tests/integration/dataplane/bootstrap.go b/api/plugins/tests/integration/dataplane/bootstrap.go index 105d48e2..21ffad7e 100644 --- a/api/plugins/tests/integration/dataplane/bootstrap.go +++ b/api/plugins/tests/integration/dataplane/bootstrap.go @@ -149,6 +149,20 @@ 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 = 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 + break + } + } + newClusters := []interface{}{} for _, c := range b.clusters { newClusters = append(newClusters, c) diff --git a/api/plugins/tests/integration/dataplane/data_plane.go b/api/plugins/tests/integration/dataplane/data_plane.go index 5d3a79b3..8b95359a 100644 --- a/api/plugins/tests/integration/dataplane/data_plane.go +++ b/api/plugins/tests/integration/dataplane/data_plane.go @@ -30,6 +30,7 @@ import ( "path/filepath" "regexp" "runtime" + "strconv" "strings" "testing" "time" @@ -54,6 +55,9 @@ type DataPlane struct { t *testing.T opt *Option done chan error + + dataPlanePort string + adminAPIPort string } type Option struct { @@ -189,6 +193,20 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) { return nil, err } + adminAPIPort := "9998" + adminAPIPortEnv := os.Getenv("TEST_ENVOY_ADMIN_API_PORT") + if adminAPIPortEnv != "" { + adminAPIPort = adminAPIPortEnv + } + dp.adminAPIPort = adminAPIPort + + dataPlanePort := "10000" + dataPlanePortEnv := os.Getenv("TEST_ENVOY_DATA_PLANE_PORT") + if dataPlanePortEnv != "" { + dataPlanePort = dataPlanePortEnv + } + dp.dataPlanePort = dataPlanePort + cmdline := "docker run" + " --name " + containerName + " --network " + networkName + @@ -199,7 +217,8 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) { " -v /tmp:/tmp" + " -e GOCOVERDIR=" + coverDir + " " + strings.Join(envs, " ") + - " -p 10000:10000 -p 9998:9998 " + hostAddr + " " + + " -p " + dataPlanePort + ":10000 -p " + adminAPIPort + ":9998 " + + hostAddr + " " + image content, _ := os.ReadFile(cfgFile.Name()) @@ -256,7 +275,7 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) { go func() { done <- cmd.Wait() }() }() - helper.WaitServiceUp(t, ":10000", "") + helper.WaitServiceUp(t, ":"+dataPlanePort, "") select { case err := <-done: @@ -381,7 +400,7 @@ func (dp *DataPlane) Patch(path string, header http.Header, body io.Reader) (*ht } func (dp *DataPlane) SendAndCancelRequest(path string, after time.Duration) error { - conn, err := net.DialTimeout("tcp", ":10000", 1*time.Second) + conn, err := net.DialTimeout("tcp", ":"+dp.dataPlanePort, 1*time.Second) if err != nil { return err } @@ -404,13 +423,13 @@ func (dp *DataPlane) SendAndCancelRequest(path string, after time.Duration) erro } func (dp *DataPlane) do(method string, path string, header http.Header, body io.Reader) (*http.Response, error) { - req, err := http.NewRequest(method, "http://localhost:10000"+path, body) + req, err := http.NewRequest(method, "http://localhost:"+dp.dataPlanePort+path, body) if err != nil { return nil, err } req.Header = header tr := &http.Transport{DialContext: func(ctx context.Context, proto, addr string) (conn net.Conn, err error) { - return net.DialTimeout("tcp", ":10000", 1*time.Second) + return net.DialTimeout("tcp", ":"+dp.dataPlanePort, 1*time.Second) }} client := &http.Client{Transport: tr, @@ -424,7 +443,7 @@ func (dp *DataPlane) do(method string, path string, header http.Header, body io. } func (dp *DataPlane) doWithTrailer(method string, path string, header http.Header, body io.Reader, trailer http.Header) (*http.Response, error) { - req, err := http.NewRequest(method, "http://localhost:10000"+path, body) + req, err := http.NewRequest(method, "http://localhost:"+dp.dataPlanePort+path, body) if err != nil { return nil, err } @@ -434,7 +453,7 @@ func (dp *DataPlane) doWithTrailer(method string, path string, header http.Heade req.TransferEncoding = []string{"chunked"} tr := &http.Transport{ DialContext: func(ctx context.Context, proto, addr string) (conn net.Conn, err error) { - return net.DialTimeout("tcp", ":10000", 1*time.Second) + return net.DialTimeout("tcp", ":"+dp.dataPlanePort, 1*time.Second) }, } @@ -451,7 +470,7 @@ func (dp *DataPlane) doWithTrailer(method string, path string, header http.Heade // Use grpcurl so that the caller can specify the proto file without building the Go code. // TODO: we can rewrite this in Go. func (dp *DataPlane) Grpcurl(importPath, protoFile, fullMethodName, req string) ([]byte, error) { - cmd := exec.Command("grpcurl", "-v", "-format-error", "-import-path", importPath, "-proto", protoFile, "-plaintext", "-d", req, ":10000", fullMethodName) + cmd := exec.Command("grpcurl", "-v", "-format-error", "-import-path", importPath, "-proto", protoFile, "-plaintext", "-d", req, ":"+dp.dataPlanePort, fullMethodName) dp.t.Logf("run grpcurl command: %s", cmd.String()) return cmd.CombinedOutput() } @@ -479,7 +498,7 @@ func (dp *DataPlane) FlushCoverage() error { } func (dp *DataPlane) SetLogLevel(loggerName string, level string) error { - req, err := http.NewRequest("POST", fmt.Sprintf("http://0.0.0.0:9998/logging?%s=%s", loggerName, level), bytes.NewReader([]byte{})) + req, err := http.NewRequest("POST", fmt.Sprintf("http://0.0.0.0:%s/logging?%s=%s", dp.adminAPIPort, loggerName, level), bytes.NewReader([]byte{})) if err != nil { return err } @@ -497,3 +516,13 @@ func (dp *DataPlane) SetLogLevel(loggerName string, level string) error { return nil } + +func (dp *DataPlane) AdminAPIPort() int { + p, _ := strconv.Atoi(dp.adminAPIPort) + return p +} + +func (dp *DataPlane) Port() int { + p, _ := strconv.Atoi(dp.dataPlanePort) + return p +} diff --git a/api/tests/integration/filtermanager_latest_test.go b/api/tests/integration/filtermanager_latest_test.go index 6af1a0bc..4e56616f 100644 --- a/api/tests/integration/filtermanager_latest_test.go +++ b/api/tests/integration/filtermanager_latest_test.go @@ -242,7 +242,7 @@ func TestFilterManagerTrailersWithGrpcBackend(t *testing.T) { } defer dp.Stop() - helper.WaitServiceUp(t, ":50051", "grpc") + helper.WaitServiceUp(t, ":50001", "grpc") s := &filtermanager.FilterManagerConfig{ Plugins: []*model.FilterConfig{ diff --git a/api/tests/integration/testdata/grpc_backend.yml b/api/tests/integration/testdata/grpc_backend.yml index 4b35d155..a11e33ed 100644 --- a/api/tests/integration/testdata/grpc_backend.yml +++ b/api/tests/integration/testdata/grpc_backend.yml @@ -10,4 +10,4 @@ load_assignment: address: socket_address: address: grpc - port_value: 50051 + port_value: 50001 diff --git a/api/tests/integration/testdata/services/docker-compose.yml b/api/tests/integration/testdata/services/docker-compose.yml index 534b2201..94704bf9 100644 --- a/api/tests/integration/testdata/services/docker-compose.yml +++ b/api/tests/integration/testdata/services/docker-compose.yml @@ -3,7 +3,7 @@ services: grpc: build: ./grpc ports: - - "50051:50051" + - "50001:50001" restart: unless-stopped networks: service: diff --git a/api/tests/integration/testdata/services/grpc/main.go b/api/tests/integration/testdata/services/grpc/main.go index 86084d3f..c68f2513 100644 --- a/api/tests/integration/testdata/services/grpc/main.go +++ b/api/tests/integration/testdata/services/grpc/main.go @@ -30,7 +30,7 @@ func (s *sampleServer) Ouch(ctx context.Context, req *HelloRequest) (*HelloRespo func main() { // Create a TCP listener - lis, err := net.Listen("tcp", ":50051") + lis, err := net.Listen("tcp", ":50001") if err != nil { log.Fatalf("Failed to listen: %v", err) } @@ -42,7 +42,7 @@ func main() { RegisterSampleServer(s, &sampleServer{}) // Start the server - fmt.Println("Server started. Listening on port :50051") + fmt.Println("Server started. Listening on port :50001") if err := s.Serve(lis); err != nil { log.Fatalf("Failed to serve: %v", err) } diff --git a/plugins/tests/integration/oidc_test.go b/plugins/tests/integration/oidc_test.go index ced42f50..cde5ff28 100644 --- a/plugins/tests/integration/oidc_test.go +++ b/plugins/tests/integration/oidc_test.go @@ -17,6 +17,7 @@ package integration import ( "encoding/base64" "encoding/json" + "fmt" "net/http" "net/url" "os/exec" @@ -41,7 +42,7 @@ func TestOIDC(t *testing.T) { helper.WaitServiceUp(t, ":4444", "hydra") - redirectURL := "http://127.0.0.1:10000/echo" + redirectURL := fmt.Sprintf("http://127.0.0.1:%d/echo", dp.Port()) hydraCmd := "hydra create client --response-type code,id_token " + "--grant-type authorization_code,refresh_token -e http://127.0.0.1:4445 " + "--redirect-uri " + redirectURL + " --format json" @@ -89,7 +90,7 @@ func TestOIDC(t *testing.T) { encodedURL := strings.Split(u.Query().Get("state"), ".")[1] b, _ := base64.URLEncoding.DecodeString(encodedURL) originURL := string(b) - require.Equal(t, "http://localhost:10000/echo?a=1", originURL) + require.Equal(t, fmt.Sprintf("http://localhost:%d/echo?a=1", dp.Port()), originURL) require.NotEmpty(t, u.Query().Get("nonce")) require.NotEmpty(t, u.Query().Get("code_challenge")) cookie := resp.Header.Get("Set-Cookie") diff --git a/plugins/tests/integration/sentinel_test.go b/plugins/tests/integration/sentinel_test.go index 585f547f..a606793d 100644 --- a/plugins/tests/integration/sentinel_test.go +++ b/plugins/tests/integration/sentinel_test.go @@ -15,11 +15,9 @@ package integration import ( - "context" _ "embed" "fmt" "io" - "net" "net/http" "net/url" "sync" @@ -38,28 +36,12 @@ var ( sentinelRoute string ) -func doGet(respStatus int, header http.Header, query url.Values) (*http.Response, error) { - u := fmt.Sprintf("http://localhost:10000/sentinel/status/%d", respStatus) +func doGet(dp *dataplane.DataPlane, respStatus int, header http.Header, query url.Values) (*http.Response, error) { + u := fmt.Sprintf("/sentinel/status/%d", respStatus) if query != nil { u += "?" + query.Encode() } - req, err := http.NewRequest(http.MethodGet, u, nil) - if err != nil { - return nil, err - } - req.Header = header - tr := &http.Transport{DialContext: func(ctx context.Context, proto, addr string) (conn net.Conn, err error) { - return net.DialTimeout("tcp", ":10000", 1*time.Second) - }} - - client := &http.Client{Transport: tr, - Timeout: 10 * time.Second, - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - }, - } - resp, err := client.Do(req) - return resp, err + return dp.Get(u, header) } func TestSentinelFlow(t *testing.T) { @@ -107,12 +89,12 @@ func TestSentinelFlow(t *testing.T) { hdr := http.Header{} hdr.Add("X-Sentinel", "f1") - resp, err := doGet(200, hdr, nil) + resp, err := doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "", resp.Header.Get("X-Sentinel-Blocked")) - resp, err = doGet(200, hdr, nil) + resp, err = doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 503, resp.StatusCode) assert.Equal(t, "true", resp.Header.Get("X-Sentinel-Blocked")) @@ -122,7 +104,7 @@ func TestSentinelFlow(t *testing.T) { time.Sleep(1100 * time.Millisecond) - resp, err = doGet(200, hdr, nil) + resp, err = doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "", resp.Header.Get("X-Sentinel-Blocked")) @@ -154,10 +136,10 @@ func TestSentinelFlow(t *testing.T) { run: func(t *testing.T) { query := url.Values{} query.Set("query", "f2") - resp, _ := doGet(200, nil, query) + resp, _ := doGet(dp, 200, nil, query) assert.Equal(t, 200, resp.StatusCode) - resp, _ = doGet(200, nil, query) + resp, _ = doGet(dp, 200, nil, query) assert.Equal(t, 503, resp.StatusCode) b, _ := io.ReadAll(resp.Body) assert.Equal(t, "{\"msg\":\"custom block resp: f2\"}", string(b)) @@ -192,7 +174,7 @@ func TestSentinelFlow(t *testing.T) { m := make(map[int64]int) mLock := sync.Mutex{} for i := 0; i < 20; i++ { - resp, _ := doGet(200, hdr, nil) + resp, _ := doGet(dp, 200, hdr, nil) if resp.StatusCode == 200 { k := time.Now().UnixMilli() / 100 // interval is 100ms mLock.Lock() @@ -242,10 +224,10 @@ func TestSentinelFlow(t *testing.T) { hdr := http.Header{} hdr.Add("X-Sentinel", "f4") - resp, _ := doGet(200, hdr, nil) + resp, _ := doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 503, resp.StatusCode) b, err := io.ReadAll(resp.Body) assert.NoError(t, err) @@ -258,7 +240,7 @@ func TestSentinelFlow(t *testing.T) { // when f3 triggers the traffic limiting, f4 also triggers the traffic limiting, // because the two resources are related - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 503, resp.StatusCode) b, err = io.ReadAll(resp.Body) assert.NoError(t, err) @@ -323,12 +305,12 @@ func TestSentinelHotSpot(t *testing.T) { hdr := http.Header{} hdr.Add("X-Sentinel", "hs1") - resp, err := doGet(200, hdr, nil) + resp, err := doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "", resp.Header.Get("X-Sentinel-Blocked")) - resp, err = doGet(200, hdr, nil) + resp, err = doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 503, resp.StatusCode) assert.Equal(t, "true", resp.Header.Get("X-Sentinel-Blocked")) @@ -337,7 +319,7 @@ func TestSentinelHotSpot(t *testing.T) { time.Sleep(1100 * time.Millisecond) - resp, err = doGet(200, hdr, nil) + resp, err = doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "", resp.Header.Get("X-Sentinel-Blocked")) @@ -382,10 +364,10 @@ func TestSentinelHotSpot(t *testing.T) { hdr.Add("X-Sentinel", "hs2") hdr.Add("X-A1", "test") - resp, _ := doGet(200, hdr, nil) + resp, _ := doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 503, resp.StatusCode) // attachment from query a2, but attachment key is `X-A1`, so there's no traffic control @@ -394,7 +376,7 @@ func TestSentinelHotSpot(t *testing.T) { query := url.Values{} query.Add("a2", "test") for i := 0; i < 5; i++ { - resp, _ = doGet(200, hdr, query) + resp, _ = doGet(dp, 200, hdr, query) assert.Equal(t, 200, resp.StatusCode) } }, @@ -428,11 +410,11 @@ func TestSentinelHotSpot(t *testing.T) { hdr := http.Header{} hdr.Add("X-Sentinel", "hs3") - resp, _ := doGet(200, hdr, nil) + resp, _ := doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) // although the threshold is 10, the threshold for `abc` is specified to be 1 through `specificItems` - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 503, resp.StatusCode) }, }, @@ -497,7 +479,7 @@ func TestSentinelCircuitBreaker(t *testing.T) { isBreakerOpened := false // 10 requests, 5 of them will trigger the circuit breaker for i := 0; i < 10; i++ { - resp, err := doGet(500, hdr, nil) + resp, err := doGet(dp, 500, hdr, nil) assert.NoError(t, err) b, _ := io.ReadAll(resp.Body) if resp.StatusCode == 503 && @@ -512,7 +494,7 @@ func TestSentinelCircuitBreaker(t *testing.T) { time.Sleep(3100 * time.Millisecond) for i := 0; i < 3; i++ { - resp, err := doGet(200, hdr, nil) + resp, err := doGet(dp, 200, hdr, nil) assert.NoError(t, err) assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "", resp.Header.Get("X-Sentinel-Blocked")) @@ -611,10 +593,10 @@ func TestSentinelMixture(t *testing.T) { hdr := http.Header{} hdr.Add("X-Sentinel", "flow") - resp, _ := doGet(200, hdr, nil) + resp, _ := doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 503, resp.StatusCode) assert.Equal(t, "flow", resp.Header.Get("X-Sentinel-Type")) b, _ := io.ReadAll(resp.Body) @@ -622,7 +604,7 @@ func TestSentinelMixture(t *testing.T) { time.Sleep(1100 * time.Millisecond) - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) // flow end @@ -630,10 +612,10 @@ func TestSentinelMixture(t *testing.T) { hdr = http.Header{} hdr.Add("X-Sentinel", "hotspot") - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 503, resp.StatusCode) assert.Equal(t, "hotspot", resp.Header.Get("X-Sentinel-Type")) b, _ = io.ReadAll(resp.Body) @@ -641,7 +623,7 @@ func TestSentinelMixture(t *testing.T) { time.Sleep(1100 * time.Millisecond) - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) // hot spot end @@ -652,7 +634,7 @@ func TestSentinelMixture(t *testing.T) { isBreakerOpened := false // 10 requests, 5 of them will trigger the circuit breaker for i := 0; i < 10; i++ { - resp, _ = doGet(500, hdr, nil) + resp, _ = doGet(dp, 500, hdr, nil) b, _ = io.ReadAll(resp.Body) if resp.StatusCode == 503 && resp.Header.Get("X-Sentinel-Type") == "circuitbreaker" && @@ -666,7 +648,7 @@ func TestSentinelMixture(t *testing.T) { time.Sleep(3100 * time.Millisecond) for i := 0; i < 3; i++ { - resp, _ = doGet(200, hdr, nil) + resp, _ = doGet(dp, 200, hdr, nil) assert.Equal(t, 200, resp.StatusCode) } // circuit breaker end diff --git a/site/content/en/docs/developer-guide/plugin_integration_test_framework.md b/site/content/en/docs/developer-guide/plugin_integration_test_framework.md index 8fbce53c..f11f180b 100644 --- a/site/content/en/docs/developer-guide/plugin_integration_test_framework.md +++ b/site/content/en/docs/developer-guide/plugin_integration_test_framework.md @@ -20,9 +20,10 @@ You may have noticed that when executing `go test`, we added `-tags envoy1.29`. ## Port usage -The test framework will use: +The test framework will occupy the following ports on the host machine: -* `:2023` to represent invalid port -* `:9999` for the control plane -* `:10000` for the Envoy proxy -* `:10001` for the backend server and mock external server +* `:9998` for the Envoy's Admin API, which can be modified by the environment variable `TEST_ENVOY_ADMIN_API_PORT` +* `:9999` for the control plane, which can be modified by the environment variable `TEST_ENVOY_CONTROL_PLANE_PORT` +* `:10000` for the Envoy proxy, which can be modified by the environment variable `TEST_ENVOY_DATA_PLANE_PORT` + +For example, `TEST_ENVOY_CONTROL_PLANE_PORT=19999 go test -v ./tests/integration -run TestPluginXX` will use `:19999` as the control plane port. diff --git a/site/content/zh-hans/docs/developer-guide/plugin_integration_test_framework.md b/site/content/zh-hans/docs/developer-guide/plugin_integration_test_framework.md index f67b1b6d..e4d5c26a 100644 --- a/site/content/zh-hans/docs/developer-guide/plugin_integration_test_framework.md +++ b/site/content/zh-hans/docs/developer-guide/plugin_integration_test_framework.md @@ -20,9 +20,10 @@ title: 插件集成测试框架 ## 端口使用 -测试框架将使用: +测试框架将占用 host 上的下述端口: -* `:2023` 用于表示错误的端口 -* `:9999` 用于控制平面 -* `:10000` 用于数据面 -* `:10001` 用于后端服务器和模拟外部服务器 +* `:9998` 用于 Envoy 管理 API,可通过环境变量 `TEST_ENVOY_ADMIN_API_PORT` 修改 +* `:9999` 用于控制平面,可通过环境变量 `TEST_ENVOY_CONTROL_PLANE_PORT` 修改 +* `:10000` 用于数据面,可通过环境变量 `TEST_ENVOY_DATA_PLANE_PORT` 修改 + +例如,`TEST_ENVOY_CONTROL_PLANE_PORT=19999 go test -v ./tests/integration -run TestPluginXX` 将使用 `:19999` 端口作为控制平面端口。 From 81b54afb198501a61e26071be8bde069f0bcd655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Tue, 29 Oct 2024 15:56:13 +0800 Subject: [PATCH 07/49] add @WeixinX as the owner of sentinel (#783) Signed-off-by: spacewander --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index fbf48959..4cb54496 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -5,7 +5,7 @@ # See https://github.com/orgs/community/discussions/23042 # Plugins - +/*/plugins/sentinel @WeixinX # Registries /*/registries/consul @lyt122 From d9a5c254de21e7c89b57342d68f310d6e2a23fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Thu, 31 Oct 2024 13:57:56 +0800 Subject: [PATCH 08/49] fix: previous error log is too strict (#788) Signed-off-by: spacewander --- api/pkg/filtermanager/filtermanager.go | 12 +- api/tests/integration/consumer_test.go | 51 ++++++ api/tests/integration/test_plugins.go | 43 +++++ .../testdata/services/grpc/sample.pb.go | 169 +++++++++++------- .../developer-guide/plugin_development.md | 2 +- .../developer-guide/plugin_development.md | 2 +- 6 files changed, 204 insertions(+), 75 deletions(-) diff --git a/api/pkg/filtermanager/filtermanager.go b/api/pkg/filtermanager/filtermanager.go index 862d305a..c86546f6 100644 --- a/api/pkg/filtermanager/filtermanager.go +++ b/api/pkg/filtermanager/filtermanager.go @@ -195,11 +195,13 @@ func FilterManagerFactory(c interface{}, cb capi.FilterCallbackHandler) (streamF api.LogErrorf("plugin %s has DecodeRequest but not DecodeHeaders. To run DecodeRequest, we need to return api.WaitAllData from DecodeHeaders", fc.Name) } - p := pkgPlugins.LoadPluginType(fc.Name) - if p != nil { - order := p.Order() - if order.Position <= pkgPlugins.OrderPositionAuthn { - api.LogErrorf("plugin %s has DecodeRequest which is not supported because the order of plugin", fc.Name) + if conf.consumerFiltersEndAt != 0 { + p := pkgPlugins.LoadPluginType(fc.Name) + if p != nil { + order := p.Order() + if order.Position <= pkgPlugins.OrderPositionAuthn { + api.LogErrorf("plugin %s has DecodeRequest which is not supported because the order of plugin", fc.Name) + } } } } diff --git a/api/tests/integration/consumer_test.go b/api/tests/integration/consumer_test.go index a8152d0f..a367fe68 100644 --- a/api/tests/integration/consumer_test.go +++ b/api/tests/integration/consumer_test.go @@ -225,3 +225,54 @@ func TestConsumerFilterNotAfterConsumerRunInLaterPhase(t *testing.T) { }) } } + +func TestConsumerFilterNotAfterConsumerRunDecodeRequest(t *testing.T) { + dp, err := dataplane.StartDataPlane(t, &dataplane.Option{ + Bootstrap: dataplane.Bootstrap().AddConsumer("marvin", map[string]interface{}{ + "auth": map[string]interface{}{ + "consumer": `{"name":"marvin"}`, + }, + }), + NoErrorLogCheck: true, + ExpectLogPattern: []string{ + `plugin beforeConsumerAndHasDecodeRequest has DecodeRequest which is not supported because the order of plugin`, + }, + }) + if err != nil { + t.Fatalf("failed to start data plane: %v", err) + return + } + defer dp.Stop() + + tests := []struct { + name string + config *filtermanager.FilterManagerConfig + run func(t *testing.T) + }{ + { + name: "authn & exec", + config: controlplane.NewPluginConfig([]*model.FilterConfig{ + { + Name: "beforeConsumerAndHasDecodeRequest", + Config: map[string]interface{}{}, + }, + { + Name: "consumer", + Config: map[string]interface{}{}, + }, + }), + run: func(t *testing.T) { + resp, _ := dp.Get("/echo", http.Header{"Authorization": []string{"marvin"}}) + assert.Equal(t, 200, resp.StatusCode) + assert.Equal(t, []string{"beforeConsumerAndHasDecodeRequest"}, resp.Header.Values("Echo-Run")) + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + controlPlane.UseGoPluginConfig(t, tt.config, dp) + tt.run(t) + }) + } +} diff --git a/api/tests/integration/test_plugins.go b/api/tests/integration/test_plugins.go index 9fe9359d..7245af38 100644 --- a/api/tests/integration/test_plugins.go +++ b/api/tests/integration/test_plugins.go @@ -532,6 +532,48 @@ func (f *beforeConsumerAndHasOtherMethodFilter) EncodeHeaders(headers api.Respon return api.Continue } +type beforeConsumerAndHasDecodeRequestPlugin struct { + plugins.PluginMethodDefaultImpl +} + +func (p *beforeConsumerAndHasDecodeRequestPlugin) Order() plugins.PluginOrder { + return plugins.PluginOrder{ + Position: plugins.OrderPositionAccess, + } +} + +func (p *beforeConsumerAndHasDecodeRequestPlugin) Config() api.PluginConfig { + return &Config{} +} + +func (p *beforeConsumerAndHasDecodeRequestPlugin) Factory() api.FilterFactory { + return beforeConsumerAndHasDecodeRequestFactory +} + +func beforeConsumerAndHasDecodeRequestFactory(c interface{}, callbacks api.FilterCallbackHandler) api.Filter { + return &beforeConsumerAndHasDecodeRequestFilter{ + callbacks: callbacks, + config: c.(*Config), + } +} + +type beforeConsumerAndHasDecodeRequestFilter struct { + api.PassThroughFilter + + callbacks api.FilterCallbackHandler + config *Config +} + +func (f *beforeConsumerAndHasDecodeRequestFilter) DecodeHeaders(headers api.RequestHeaderMap, endStream bool) api.ResultAction { + headers.Add("run", "beforeConsumerAndHasDecodeRequest") + return api.Continue +} + +func (f *beforeConsumerAndHasDecodeRequestFilter) DecodeRequest(headers api.RequestHeaderMap, data api.BufferInstance, trailers api.RequestTrailerMap) api.ResultAction { + headers.Add("run", "beforeConsumerAndHasDecodeRequest:DecodeRequest") + return api.Continue +} + type onLogPlugin struct { plugins.PluginMethodDefaultImpl } @@ -587,5 +629,6 @@ func init() { plugins.RegisterPlugin("benchmark", &benchmarkPlugin{}) plugins.RegisterPlugin("benchmark2", &benchmarkPlugin{}) plugins.RegisterPlugin("beforeConsumerAndHasOtherMethod", &beforeConsumerAndHasOtherMethodPlugin{}) + plugins.RegisterPlugin("beforeConsumerAndHasDecodeRequest", &beforeConsumerAndHasDecodeRequestPlugin{}) plugins.RegisterPlugin("onLog", &onLogPlugin{}) } diff --git a/api/tests/integration/testdata/services/grpc/sample.pb.go b/api/tests/integration/testdata/services/grpc/sample.pb.go index 1d87c9b1..c9e75689 100644 --- a/api/tests/integration/testdata/services/grpc/sample.pb.go +++ b/api/tests/integration/testdata/services/grpc/sample.pb.go @@ -1,8 +1,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 +// protoc-gen-go v1.31.0 // protoc v4.24.4 -// source: sample.proto +// source: api/tests/integration/testdata/services/grpc/sample.proto package main @@ -31,9 +31,11 @@ type HelloRequest struct { func (x *HelloRequest) Reset() { *x = HelloRequest{} - mi := &file_sample_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) + if protoimpl.UnsafeEnabled { + mi := &file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } func (x *HelloRequest) String() string { @@ -43,8 +45,8 @@ func (x *HelloRequest) String() string { func (*HelloRequest) ProtoMessage() {} func (x *HelloRequest) ProtoReflect() protoreflect.Message { - mi := &file_sample_proto_msgTypes[0] - if x != nil { + mi := &file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -56,7 +58,7 @@ func (x *HelloRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. func (*HelloRequest) Descriptor() ([]byte, []int) { - return file_sample_proto_rawDescGZIP(), []int{0} + return file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescGZIP(), []int{0} } func (x *HelloRequest) GetName() string { @@ -76,9 +78,11 @@ type HelloResponse struct { func (x *HelloResponse) Reset() { *x = HelloResponse{} - mi := &file_sample_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) + if protoimpl.UnsafeEnabled { + mi := &file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } func (x *HelloResponse) String() string { @@ -88,8 +92,8 @@ func (x *HelloResponse) String() string { func (*HelloResponse) ProtoMessage() {} func (x *HelloResponse) ProtoReflect() protoreflect.Message { - mi := &file_sample_proto_msgTypes[1] - if x != nil { + mi := &file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -101,7 +105,7 @@ func (x *HelloResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use HelloResponse.ProtoReflect.Descriptor instead. func (*HelloResponse) Descriptor() ([]byte, []int) { - return file_sample_proto_rawDescGZIP(), []int{1} + return file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescGZIP(), []int{1} } func (x *HelloResponse) GetMessage() string { @@ -111,60 +115,63 @@ func (x *HelloResponse) GetMessage() string { return "" } -var File_sample_proto protoreflect.FileDescriptor - -var file_sample_proto_rawDesc = []byte{ - 0x0a, 0x0c, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2c, - 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x22, 0x22, 0x0a, 0x0c, - 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x22, 0x29, 0x0a, 0x0d, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x94, 0x02, 0x0a, 0x06, - 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x85, 0x01, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, - 0x6c, 0x6c, 0x6f, 0x12, 0x3a, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, - 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, - 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, - 0x70, 0x63, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x3b, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, - 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, - 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x48, - 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x81, - 0x01, 0x0a, 0x04, 0x4f, 0x75, 0x63, 0x68, 0x12, 0x3a, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, - 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, - 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x3b, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, - 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, - 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, - 0x70, 0x63, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x40, 0x5a, 0x3e, 0x6d, 0x6f, 0x73, 0x6e, 0x2e, 0x69, 0x6f, 0x2f, 0x68, 0x74, - 0x6e, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x69, 0x6e, 0x74, - 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, - 0x61, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, - 0x6d, 0x61, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +var File_api_tests_integration_testdata_services_grpc_sample_proto protoreflect.FileDescriptor + +var file_api_tests_integration_testdata_services_grpc_sample_proto_rawDesc = []byte{ + 0x0a, 0x39, 0x61, 0x70, 0x69, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, + 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, + 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x73, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2c, 0x61, 0x70, 0x69, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, 0x6c, + 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, + 0x0d, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x94, 0x02, 0x0a, 0x06, 0x53, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x12, 0x85, 0x01, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, + 0x12, 0x3a, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, + 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, + 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x3b, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x65, 0x6c, 0x6c, + 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x81, 0x01, 0x0a, 0x04, + 0x4f, 0x75, 0x63, 0x68, 0x12, 0x3a, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, + 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, + 0x72, 0x70, 0x63, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x3b, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2e, 0x69, 0x6e, 0x74, + 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, + 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x40, 0x5a, 0x3e, 0x6d, 0x6f, 0x73, 0x6e, 0x2e, 0x69, 0x6f, 0x2f, 0x68, 0x74, 0x6e, 0x6e, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x6d, 0x61, 0x69, + 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_sample_proto_rawDescOnce sync.Once - file_sample_proto_rawDescData = file_sample_proto_rawDesc + file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescOnce sync.Once + file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescData = file_api_tests_integration_testdata_services_grpc_sample_proto_rawDesc ) -func file_sample_proto_rawDescGZIP() []byte { - file_sample_proto_rawDescOnce.Do(func() { - file_sample_proto_rawDescData = protoimpl.X.CompressGZIP(file_sample_proto_rawDescData) +func file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescGZIP() []byte { + file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescOnce.Do(func() { + file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescData) }) - return file_sample_proto_rawDescData + return file_api_tests_integration_testdata_services_grpc_sample_proto_rawDescData } -var file_sample_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_sample_proto_goTypes = []any{ +var file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_api_tests_integration_testdata_services_grpc_sample_proto_goTypes = []interface{}{ (*HelloRequest)(nil), // 0: api.tests.integration.testdata.services.grpc.HelloRequest (*HelloResponse)(nil), // 1: api.tests.integration.testdata.services.grpc.HelloResponse } -var file_sample_proto_depIdxs = []int32{ +var file_api_tests_integration_testdata_services_grpc_sample_proto_depIdxs = []int32{ 0, // 0: api.tests.integration.testdata.services.grpc.Sample.SayHello:input_type -> api.tests.integration.testdata.services.grpc.HelloRequest 0, // 1: api.tests.integration.testdata.services.grpc.Sample.Ouch:input_type -> api.tests.integration.testdata.services.grpc.HelloRequest 1, // 2: api.tests.integration.testdata.services.grpc.Sample.SayHello:output_type -> api.tests.integration.testdata.services.grpc.HelloResponse @@ -176,27 +183,53 @@ var file_sample_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for field type_name } -func init() { file_sample_proto_init() } -func file_sample_proto_init() { - if File_sample_proto != nil { +func init() { file_api_tests_integration_testdata_services_grpc_sample_proto_init() } +func file_api_tests_integration_testdata_services_grpc_sample_proto_init() { + if File_api_tests_integration_testdata_services_grpc_sample_proto != nil { return } + if !protoimpl.UnsafeEnabled { + file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HelloRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HelloResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_sample_proto_rawDesc, + RawDescriptor: file_api_tests_integration_testdata_services_grpc_sample_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_sample_proto_goTypes, - DependencyIndexes: file_sample_proto_depIdxs, - MessageInfos: file_sample_proto_msgTypes, + GoTypes: file_api_tests_integration_testdata_services_grpc_sample_proto_goTypes, + DependencyIndexes: file_api_tests_integration_testdata_services_grpc_sample_proto_depIdxs, + MessageInfos: file_api_tests_integration_testdata_services_grpc_sample_proto_msgTypes, }.Build() - File_sample_proto = out.File - file_sample_proto_rawDesc = nil - file_sample_proto_goTypes = nil - file_sample_proto_depIdxs = nil + File_api_tests_integration_testdata_services_grpc_sample_proto = out.File + file_api_tests_integration_testdata_services_grpc_sample_proto_rawDesc = nil + file_api_tests_integration_testdata_services_grpc_sample_proto_goTypes = nil + file_api_tests_integration_testdata_services_grpc_sample_proto_depIdxs = nil } diff --git a/site/content/en/docs/developer-guide/plugin_development.md b/site/content/en/docs/developer-guide/plugin_development.md index c064321d..35f1c227 100644 --- a/site/content/en/docs/developer-guide/plugin_development.md +++ b/site/content/en/docs/developer-guide/plugin_development.md @@ -143,7 +143,7 @@ The same process applies to the Encode path in a reverse order, and the method i Note: `EncodeResponse` is only executed if `EncodeHeaders` returns `WaitAllData`. So if `EncodeResponse` is defined, `EncodeHeaders` must be defined as well. When both `EncodeResponse` and `EncodeData/EncodeTrailers` are defined in the plugin: if `EncodeHeaders` returns `WaitAllData`, only `EncodeResponse` is executed, otherwise, only `EncodeData/EncodeTrailers` is executed. -Currently, `DecodeRequest` is not supported by plugins whose order is `Access` or `Authn`. +Currently, if Consumer plugins are configured, `DecodeRequest` is not supported by plugins whose order is `Access` or `Authn`. ## Consumer Plugins diff --git a/site/content/zh-hans/docs/developer-guide/plugin_development.md b/site/content/zh-hans/docs/developer-guide/plugin_development.md index 75787ec5..26f3c4c9 100644 --- a/site/content/zh-hans/docs/developer-guide/plugin_development.md +++ b/site/content/zh-hans/docs/developer-guide/plugin_development.md @@ -138,7 +138,7 @@ filter manager 实现了以下特性: 注意:`EncodeResponse` 仅在 `EncodeHeaders` 返回 `WaitAllData` 时才被执行。所以如果定义了 `EncodeResponse`,一定要定义 `EncodeHeaders`。当插件里同时定义了 `EncodeResponse` 和 `EncodeData/EncodeTrailers`:如果 `EncodeHeaders` 返回 `WaitAllData`,只有 `EncodeResponse` 会运行,否则只有 `EncodeData/EncodeTrailers` 会运行。 -目前顺序为 `Access` 或 `Authn` 的插件不支持 `DecodeRequest` 方法。 +目前如果配置了消费者插件,顺序为 `Access` 或 `Authn` 的插件的 `DecodeRequest` 方法将不会被执行。 ## 消费者插件 From 8971f1420656889dd555059aa284f41d7f48259a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Fri, 1 Nov 2024 11:54:43 +0800 Subject: [PATCH 09/49] dev: make Fix #[issue] optional (#787) Signed-off-by: spacewander --- .github/PULL_REQUEST_TEMPLATE.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5e33e942..cbbdd700 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,12 +1,11 @@ -Fix #[issue] +