├── .asf.yaml ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ └── enhancement.md ├── PULL_REQUEST_TEMPLATE.md ├── auto-comment.yml └── workflows │ ├── github-actions.yml │ ├── release.yml │ └── reviewdog.yml ├── .gitignore ├── .gitmodules ├── .golangci.yaml ├── .licenserc.yaml ├── CHANGE.md ├── Dockerfile ├── LICENSE ├── Makefile ├── NOTICE ├── README.md ├── README_CN.md ├── before_ut.sh ├── before_validate_license.sh ├── cmd └── pixiu │ └── pixiu.go ├── configcenter ├── configclient.go ├── load.go ├── load_test.go ├── nacos_load.go └── nacos_load_test.go ├── configs ├── conf.yaml ├── conf_with_nacos.yaml └── log.yml ├── docker-entrypoint.sh ├── docs ├── common │ ├── README.md │ └── faq.md ├── developer │ ├── README.md │ ├── auto-registy.md │ ├── concept.md │ ├── filter.md │ └── log.md ├── images │ ├── dubbgopixiu-infrastructure.png │ ├── dubbogopixiu-new-infrastructure.png │ ├── dubbogopixiu-procedure.png │ ├── group-pixiu-dingding.jpg │ ├── pixiu-logo-v4.png │ ├── pixiu-logo.png │ └── pixiu-old-logo.png ├── index.md ├── sample │ ├── README.md │ ├── dubbo │ │ ├── dubbo-body(http).md │ │ ├── dubbo-body.md │ │ ├── dubbo-error.md │ │ ├── dubbo-incomplete.md │ │ ├── dubbo-mix.md │ │ ├── dubbo-multi.md │ │ ├── dubbo-query(http).md │ │ ├── dubbo-query.md │ │ ├── dubbo-registry.md │ │ ├── dubbo-simple-run.md │ │ ├── dubbo-universality.md │ │ ├── dubbo-uri.md │ │ ├── dubbo.md │ │ ├── dubbo_sample_startup.sh │ │ ├── http-body.md │ │ ├── http-query.md │ │ └── http-uri.md │ ├── http │ │ ├── http-grpc.md │ │ ├── http-http.md │ │ └── http.md │ ├── mock.md │ ├── others │ │ ├── auth-filter.md │ │ ├── fail-inject.md │ │ ├── jaeger.md │ │ └── prometheus.md │ ├── springcloud │ │ └── README.md │ └── zh-cn │ │ ├── README.md │ │ └── dubbo │ │ ├── dubbo-body.md │ │ ├── dubbo-mix.md │ │ ├── dubbo-multi.md │ │ ├── dubbo-query.md │ │ ├── dubbo-simple-run.md │ │ ├── dubbo-universality.md │ │ ├── dubbo-uri.md │ │ └── dubbo.md └── user │ ├── README.md │ ├── api.md │ ├── config.md │ ├── metric.md │ └── start.md ├── go.mod ├── go.sum ├── igt └── Makefile ├── integrate_test.sh ├── pkg ├── adapter │ ├── dubboregistry │ │ ├── common │ │ │ └── common.go │ │ ├── registry │ │ │ ├── base │ │ │ │ ├── baseregistry.go │ │ │ │ └── baseregistry_test.go │ │ │ ├── listener.go │ │ │ ├── nacos │ │ │ │ ├── application_listener.go │ │ │ │ ├── application_service_listener.go │ │ │ │ ├── interface_listener.go │ │ │ │ ├── registry.go │ │ │ │ └── service_listener.go │ │ │ ├── registry.go │ │ │ ├── util.go │ │ │ └── zookeeper │ │ │ │ ├── application_listener.go │ │ │ │ ├── application_service_listener.go │ │ │ │ ├── interface_listener.go │ │ │ │ ├── registry.go │ │ │ │ ├── registry_test.go │ │ │ │ └── service_listener.go │ │ ├── registrycenter.go │ │ └── remoting │ │ │ └── zookeeper │ │ │ └── client.go │ └── springcloud │ │ ├── cloud.go │ │ ├── common │ │ └── common.go │ │ └── servicediscovery │ │ ├── nacos │ │ └── nacos.go │ │ ├── servicediscovery.go │ │ └── zookeeper │ │ ├── application_listener.go │ │ ├── service_listener.go │ │ └── zk_discovery.go ├── client │ ├── client.go │ ├── dubbo │ │ ├── config.go │ │ ├── default.go │ │ ├── dubbo.go │ │ ├── dubbo_test.go │ │ ├── mapper.go │ │ ├── mapper_test.go │ │ ├── option.go │ │ └── option_test.go │ ├── http │ │ ├── http.go │ │ ├── http_test.go │ │ ├── mapper.go │ │ └── mapper_test.go │ ├── mapper.go │ ├── mapper_test.go │ ├── metadata.go │ ├── mq │ │ ├── config.go │ │ ├── facade.go │ │ ├── kafka_facade.go │ │ ├── mq.go │ │ └── msg.go │ ├── proxy │ │ ├── descriptor_source.go │ │ ├── proxy.go │ │ └── reflection.go │ ├── request.go │ ├── response.go │ └── triple │ │ └── triple.go ├── cluster │ ├── cluster.go │ ├── healthcheck │ │ ├── healthcheck.go │ │ ├── healthcheck_test.go │ │ ├── http.go │ │ ├── https.go │ │ ├── tcp.go │ │ └── utils.go │ └── loadbalancer │ │ ├── load_balancer.go │ │ ├── maglev │ │ ├── maglev_hash.go │ │ ├── maglev_hash_test.go │ │ ├── permutation.go │ │ └── permutation_test.go │ │ ├── rand │ │ └── load_balancer_rand.go │ │ ├── ringhash │ │ ├── ring_hash.go │ │ └── ring_hash_test.go │ │ ├── roundrobin │ │ └── round_robin.go │ │ └── weightrandom │ │ ├── weight_random.go │ │ └── weight_random_test.go ├── cmd │ ├── deployer.go │ ├── gateway.go │ └── sidecar.go ├── common │ ├── constant │ │ ├── env.go │ │ ├── filter.go │ │ ├── hotreload.go │ │ ├── http.go │ │ ├── jtypes.go │ │ ├── key.go │ │ ├── pixiu.go │ │ ├── remote.go │ │ └── url.go │ ├── extension │ │ ├── adapter │ │ │ ├── adapter.go │ │ │ └── adapter_test.go │ │ └── filter │ │ │ ├── filter.go │ │ │ ├── filter_chain.go │ │ │ ├── filter_manager.go │ │ │ ├── filter_manager_test.go │ │ │ └── filter_status.go │ ├── grpc │ │ ├── RoundTripper.go │ │ └── manager.go │ ├── http │ │ ├── manager.go │ │ └── manager_test.go │ ├── mock │ │ ├── router.go │ │ └── routerfilter.go │ ├── router │ │ ├── router.go │ │ ├── router_test.go │ │ └── trie │ │ │ ├── trie.go │ │ │ └── trie_test.go │ ├── runtime │ │ └── runtime.go │ ├── shutdown │ │ ├── graceful_shutdown_signal_darwin.go │ │ ├── graceful_shutdown_signal_linux.go │ │ └── graceful_shutdown_signal_windows.go │ ├── util │ │ ├── response.go │ │ ├── response_test.go │ │ └── stringutil │ │ │ └── stringutil.go │ └── yaml │ │ ├── testdata │ │ └── config.yml │ │ ├── yaml.go │ │ └── yaml_test.go ├── config │ ├── api_config.go │ ├── api_config_test.go │ ├── conf_test.yaml │ ├── config_load.go │ ├── config_load_test.go │ ├── mock │ │ └── api_config.yml │ ├── version.go │ └── xds │ │ ├── README.md │ │ ├── apiclient │ │ ├── apiclient.go │ │ ├── grpc.go │ │ ├── grpc_envoy.go │ │ └── grpc_test.go │ │ ├── cds.go │ │ ├── cds_test.go │ │ ├── lds.go │ │ ├── lds_test.go │ │ ├── xds.go │ │ └── xds_test.go ├── context │ ├── base_context.go │ ├── dubbo │ │ └── context.go │ ├── http │ │ ├── context.go │ │ └── context_test.go │ └── mock │ │ └── context.go ├── filter │ ├── accesslog │ │ ├── access_log.go │ │ ├── access_log_test.go │ │ └── log.go │ ├── auth │ │ └── jwt │ │ │ ├── config.go │ │ │ └── jwt.go │ ├── authority │ │ ├── authority.go │ │ ├── authority_test.go │ │ └── config.go │ ├── cors │ │ └── cors.go │ ├── csrf │ │ └── csrf.go │ ├── event │ │ └── event.go │ ├── failinject │ │ ├── config.go │ │ └── filter.go │ ├── header │ │ ├── header.go │ │ └── header_test.go │ ├── host │ │ ├── host.go │ │ └── host_test.go │ ├── http │ │ ├── apiconfig │ │ │ ├── api │ │ │ │ ├── discovery_service.go │ │ │ │ └── discovery_service_test.go │ │ │ ├── api_config.go │ │ │ └── config.go │ │ ├── dubboproxy │ │ │ └── dubbo.go │ │ ├── grpcproxy │ │ │ ├── descriptor.go │ │ │ ├── descriptor_operation.go │ │ │ ├── descriptor_source.go │ │ │ ├── grpc.go │ │ │ └── invoke.go │ │ ├── httpproxy │ │ │ └── routerfilter.go │ │ ├── loadbalancer │ │ │ └── loadbalancer.go │ │ ├── proxyrewrite │ │ │ ├── rewrite.go │ │ │ └── rewrite_test.go │ │ ├── proxywasm │ │ │ ├── filter.go │ │ │ └── filter_windows.go │ │ └── remote │ │ │ └── call.go │ ├── llm │ │ └── tokenizer │ │ │ ├── tokenizer.go │ │ │ └── tokenizer_test.go │ ├── metric │ │ ├── metric.go │ │ └── metric_test.go │ ├── network │ │ ├── dubboproxy │ │ │ ├── dubbofiltermanager.go │ │ │ ├── filter │ │ │ │ ├── http │ │ │ │ │ └── httpfilter.go │ │ │ │ └── proxy │ │ │ │ │ └── proxyfilter.go │ │ │ ├── manager.go │ │ │ └── plugin.go │ │ ├── grpcconnectionmanager │ │ │ └── plugin.go │ │ └── httpconnectionmanager │ │ │ └── plugin.go │ ├── prometheus │ │ ├── config.go │ │ ├── metric.go │ │ └── metric_test.go │ ├── sentinel │ │ ├── circuitbreaker │ │ │ ├── circuit_breaker.go │ │ │ └── circuit_breaker_test.go │ │ ├── config.go │ │ ├── exact.go │ │ ├── logger_warpper.go │ │ ├── matcher.go │ │ ├── ratelimit │ │ │ ├── config.go │ │ │ ├── matcher_test.go │ │ │ ├── mock.go │ │ │ ├── rate_limit.go │ │ │ └── rate_limit_test.go │ │ └── regex.go │ ├── tracing │ │ └── tracing.go │ └── traffic │ │ ├── models.go │ │ └── traffic.go ├── filterchain │ └── network_filter_chain.go ├── hotreload │ ├── hotreload.go │ ├── logger.go │ └── route_reloader.go ├── listener │ ├── http │ │ └── http_listener.go │ ├── http2 │ │ └── http2_listener.go │ ├── listener.go │ ├── tcp │ │ ├── pkg_handler.go │ │ ├── server_handler.go │ │ └── tcp_listener.go │ └── triple │ │ └── triple_listener.go ├── logger │ ├── controller.go │ ├── log.yml │ ├── logger.go │ ├── logger_test.go │ ├── output.go │ └── triple.go ├── model │ ├── adapter.go │ ├── base.go │ ├── bootstrap.go │ ├── cluster.go │ ├── filter.go │ ├── health.go │ ├── http.go │ ├── lb.go │ ├── listener.go │ ├── llm.go │ ├── llmprovider.yaml │ ├── log.go │ ├── match.go │ ├── metric.go │ ├── pprof.go │ ├── remote.go │ ├── router.go │ ├── trace.go │ ├── tracing.go │ └── wasm.go ├── pluginregistry │ ├── proxywasm_register.go │ └── registry.go ├── pool │ └── pool.go ├── prometheus │ └── prometheus.go ├── remote │ ├── nacos │ │ └── client.go │ └── zookeeper │ │ └── client.go ├── router │ ├── api.go │ ├── api_test.go │ ├── route.go │ └── route_test.go ├── server │ ├── adapter_manager.go │ ├── adapter_manager_test.go │ ├── api_config_manager.go │ ├── cluster_manager.go │ ├── cluster_manager_test.go │ ├── controls │ │ ├── controls.go │ │ └── mocks │ │ │ └── mocks.go │ ├── dynamic_resource_manager.go │ ├── dynamic_resource_manager_test.go │ ├── http.go │ ├── listener_manager.go │ ├── otel.go │ ├── pixiu_start.go │ └── router_manager.go ├── tracing │ ├── api.go │ ├── driver.go │ ├── http.go │ ├── jaeger │ │ └── jaeger.go │ ├── otlp │ │ └── otlp.go │ └── trace_manager.go └── wasm │ ├── key.go │ ├── manager.go │ ├── service.go │ └── utils.go ├── quick_start_for_windows.md └── start_integrate_test.sh /.asf.yaml: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | github: 20 | protected_branches: ~ 21 | features: 22 | # Enable wiki for documentation 23 | wiki: true 24 | # Enable issue management 25 | issues: true 26 | # Enable projects for project management boards 27 | projects: true 28 | # Enable GitHub Discussions for community discussions 29 | discussions: true 30 | enabled_merge_buttons: 31 | # enable squash button: 32 | squash: true 33 | # enable merge button: 34 | merge: false 35 | # disable rebase button: 36 | rebase: false 37 | 38 | notifications: 39 | commits: commits@dubbo.apache.org 40 | issues: notifications@dubbo.apache.org 41 | pullrequests: notifications@dubbo.apache.org 42 | jira_options: link label link label 43 | discussions: notifications@dubbo.apache.org 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug 4 | labels: kind/bug 5 | 6 | --- 7 | 8 | 11 | 12 | 13 | **What happened**: 14 | 15 | **What you expected to happen**: 16 | 17 | **How to reproduce it (as minimally and precisely as possible)**: 18 | 19 | **Anything else we need to know?**: 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement Request 3 | about: Suggest an enhancement 4 | labels: kind/feature 5 | 6 | --- 7 | 8 | 9 | **What would you like to be added**: 10 | 11 | **Why is this needed**: -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 3 | 4 | **What this PR does**: 5 | 6 | **Which issue(s) this PR fixes**: 7 | 12 | Fixes # 13 | 14 | **Special notes for your reviewer**: 15 | 16 | **Does this PR introduce a user-facing change?**: 17 | 22 | ```release-note 23 | 24 | ``` -------------------------------------------------------------------------------- /.github/auto-comment.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | # Comment to a new issue. 20 | issueOpened: > 21 | Thank your for raising a issue. We will try and get back to you as soon as possible. 22 | Please make sure you have given us as much context as possible. 23 | pullRequestOpened: > 24 | Thank your for raising your pull request. 25 | Please make sure you have followed our contributing guidelines. We will review it as soon as possible 26 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | name: Release 20 | on: 21 | release: 22 | types: [created] 23 | 24 | jobs: 25 | releases-matrix: 26 | name: Release Go Binary 27 | runs-on: ubuntu-latest 28 | strategy: 29 | matrix: 30 | # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64 31 | goos: [linux, windows] 32 | goarch: ["386", amd64, arm] 33 | exclude: 34 | - goarch: "arm" 35 | goos: windows 36 | 37 | steps: 38 | - uses: actions/checkout@v4 39 | - uses: wangyoucao577/go-release-action@v1 40 | with: 41 | github_token: ${{ secrets.GITHUB_TOKEN }} 42 | goos: ${{ matrix.goos }} 43 | goarch: ${{ matrix.goarch }} 44 | goversion: "https://golang.org/dl/go1.23.4.linux-amd64.tar.gz" 45 | project_path: "./cmd/pixiu" 46 | binary_name: "dubbo-go-pixiu" 47 | -------------------------------------------------------------------------------- /.github/workflows/reviewdog.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | name: reviewdog 20 | on: [ pull_request ] 21 | jobs: 22 | golangci-lint: 23 | name: review 24 | runs-on: ubuntu-latest 25 | steps: 26 | - name: Check out code into the Go module directory 27 | uses: actions/checkout@v4 28 | with: 29 | persist-credentials: false 30 | submodules: true 31 | 32 | - name: golangci-lint 33 | uses: golangci/golangci-lint-action@v6 34 | with: 35 | args: --timeout=10m -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | .idea 3 | .vscode 4 | .mvn/ 5 | 6 | # app 7 | dubbo-go-pixiu 8 | dubbo-go-pixiu.exe 9 | dubbgo_server.out 10 | samples/dubbogo/simple/server/app/app 11 | .scannerwork 12 | /logs 13 | /.idea 14 | /.vscode 15 | .cache 16 | .log 17 | 18 | .DS_Store 19 | vendor/ 20 | 21 | coverage.txt 22 | 23 | *.iml 24 | 25 | *.exe 26 | !samples/springcloud/zookeeper/test 27 | !samples/springcloud/nacos/test 28 | 29 | target/ 30 | samples/**/dist 31 | 32 | out/ 33 | /test -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule ".github/actions/actions-ding"] 2 | path = .github/actions/actions-ding 3 | url = https://github.com/zcong1993/actions-ding 4 | [submodule ".github/actions/review-dog"] 5 | path = .github/actions/review-dog 6 | url = https://github.com/reviewdog/action-golangci-lint 7 | -------------------------------------------------------------------------------- /.golangci.yaml: -------------------------------------------------------------------------------- 1 | linters-settings: 2 | gocyclo: 3 | min-complexity: 10 4 | dupl: 5 | threshold: 100 6 | goconst: 7 | min-len: 2 8 | min-occurrences: 2 9 | depguard: 10 | rules: 11 | main: 12 | deny: 13 | - pkg: "github.com/sirupsen/logrus" 14 | desc: logging is allowed only by logutils.Log, logrus is allowed to use only in logutils package 15 | misspell: 16 | locale: US 17 | ignore-words: 18 | - nto 19 | lll: 20 | line-length: 140 21 | gofmt: 22 | # simplify code: gofmt with `-s` option, true by default 23 | simplify: true 24 | rewrite-rules: 25 | - pattern: interface{} 26 | replacement: any 27 | goimports: 28 | local-prefixes: github.com/golangci/golangci-lint 29 | gocritic: 30 | enabled-tags: 31 | - performance 32 | - style 33 | - experimental 34 | disabled-checks: 35 | - wrapperFunc 36 | 37 | linters: 38 | disable-all: true 39 | enable: 40 | - govet 41 | - staticcheck 42 | - ineffassign 43 | - gofmt 44 | - misspell 45 | 46 | issues: 47 | exclude-rules: 48 | - text: "weak cryptographic primitive" 49 | linters: 50 | - gosec 51 | - linters: 52 | - staticcheck 53 | text: "SA1019:" 54 | exclude-dirs: 55 | - test/testdata_etc 56 | - pkg/golinters/goanalysis/(checker|passes) 57 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | 21 | 22 | ### builder 23 | FROM amd64/ubuntu:latest as builder 24 | LABEL MAINTAINER="dev@dubbo.apache.org" 25 | 26 | RUN apt-get update && \ 27 | apt-get install -y --no-install-recommends gcc 28 | 29 | ADD https://golang.google.cn/dl/go1.23.4.linux-amd64.tar.gz . 30 | RUN tar -xf go1.23.4.linux-amd64.tar.gz -C /usr/local/ 31 | ENV PATH=$PATH:/usr/local/go/bin 32 | 33 | WORKDIR /app/ 34 | COPY . . 35 | 36 | ENV GO111MODULE=on \ 37 | CGO_ENABLED=1 \ 38 | GOOS=linux \ 39 | GOARCH=amd64 40 | 41 | RUN go build -ldflags '-r ./lib -s -w' -tags="wasm" -trimpath -o dubbo-go-pixiu ./cmd/pixiu/*.go 42 | 43 | ### alpine 44 | FROM amd64/pingcap/alpine-glibc:latest 45 | RUN addgroup -S nonroot \ 46 | && adduser -S nonroot -G nonroot 47 | USER nonroot 48 | COPY docker-entrypoint.sh / 49 | COPY configs/* /etc/pixiu/ 50 | COPY --from=builder /root/go/pkg/mod/github.com/wasmerio/wasmer-go@v1.0.4/wasmer/packaged/lib/linux-amd64/libwasmer.so /lib/ 51 | COPY --from=builder /app/dubbo-go-pixiu / 52 | RUN ["chmod", "+x", "/docker-entrypoint.sh"] 53 | ENTRYPOINT ["sh","./docker-entrypoint.sh"] 54 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Dubbo-go-pixiu 2 | Copyright 2020-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | This product contains modified code form the gRPC Project: 8 | 9 | The gRPC Project 10 | ================= 11 | Please visit the gRPC web site for more information: 12 | * https://grpc.io/ 13 | 14 | Copyright 2014 gRPC authors. 15 | -------------------------------------------------------------------------------- /before_ut.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | zkJarName="zookeeper-3.4.9-fatjar.jar" 18 | remoteJarUrl="https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/${zkJarName}" 19 | zkJarPath="pkg/registry/zookeeper-4unittest/contrib/fatjar" 20 | zkJar="${zkJarPath}/${zkJarName}" 21 | 22 | if [ ! -f "${zkJar}" ]; then 23 | mkdir -p ${zkJarPath} 24 | wget -P "${zkJarPath}" ${remoteJarUrl} 25 | fi -------------------------------------------------------------------------------- /before_validate_license.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | remoteLicenseCheckerPath="https://github.com/dubbogo/resources/raw/master/tools/license" 18 | remoteLicenseCheckerName="license-header-checker" 19 | remoteLicenseCheckerURL="${remoteLicenseCheckerPath}/${remoteLicenseCheckerName}" 20 | remoteLicenseName="license.txt" 21 | remoteLicenseURL="${remoteLicenseCheckerPath}/${remoteLicenseName}" 22 | 23 | licensePath="/tmp/tools/license" 24 | mkdir -p ${licensePath} 25 | wget -P "${licensePath}" ${remoteLicenseCheckerURL} 26 | wget -P "${licensePath}" ${remoteLicenseURL} 27 | -------------------------------------------------------------------------------- /cmd/pixiu/pixiu.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | _ "net/http/pprof" 22 | "strconv" 23 | "time" 24 | ) 25 | 26 | import ( 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | import ( 31 | "github.com/apache/dubbo-go-pixiu/pkg/cmd" 32 | _ "github.com/apache/dubbo-go-pixiu/pkg/pluginregistry" 33 | ) 34 | 35 | const ( 36 | // Version pixiu version 37 | Version = "1.0.0" 38 | ) 39 | 40 | // main pixiu run method 41 | func main() { 42 | app := getRootCmd() 43 | 44 | // ignore error so we don't exit non-zero and break gfmrun README example tests 45 | _ = app.Execute() 46 | } 47 | 48 | func getRootCmd() *cobra.Command { 49 | rootCmd := &cobra.Command{ 50 | Use: "dubbogo pixiu", 51 | Short: "Dubbogo pixiu is a lightweight gateway.", 52 | Long: "dubbo-go-pixiu is a gateway that mainly focuses on providing gateway solution to your Dubbo and RESTful \n" + 53 | "services. It supports HTTP-to-Dubbo and HTTP-to-HTTP proxy and more protocols will be supported in the near \n" + 54 | "future. \n" + 55 | "(c) " + strconv.Itoa(time.Now().Year()) + " Dubbogo", 56 | Version: Version, 57 | } 58 | 59 | rootCmd.AddCommand(cmd.GatewayCmd) 60 | rootCmd.AddCommand(cmd.SideCarCmd) 61 | 62 | return rootCmd 63 | } 64 | -------------------------------------------------------------------------------- /configcenter/configclient.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package configcenter 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | type ( 25 | ConfigClient interface { 26 | LoadConfig(properties map[string]any) (string, error) 27 | 28 | ListenConfig(properties map[string]any) (err error) 29 | 30 | // ViewConfig returns the current remote configuration. 31 | ViewConfig() *model.Bootstrap 32 | } 33 | ) 34 | -------------------------------------------------------------------------------- /configs/log.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | level: "debug" 21 | development: true 22 | disableCaller: false 23 | disableStacktrace: false 24 | sampling: 25 | encoding: "console" 26 | 27 | # encoder 28 | encoderConfig: 29 | messageKey: "message" 30 | levelKey: "level" 31 | timeKey: "time" 32 | nameKey: "logger" 33 | callerKey: "caller" 34 | stacktraceKey: "stacktrace" 35 | lineEnding: "" 36 | levelEncoder: "capitalColor" 37 | timeEncoder: "iso8601" 38 | durationEncoder: "seconds" 39 | callerEncoder: "short" 40 | nameEncoder: "" 41 | 42 | outputPaths: 43 | - "stderr" 44 | errorOutputPaths: 45 | - "stderr" 46 | initialFields: 47 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | 21 | CMD_PARAMS="" 22 | API_CONF="api_config.yaml" 23 | LOG="log.yml" 24 | CONF="conf.yaml" 25 | 26 | cd /etc/pixiu/ && ls -al /etc/pixiu/ 27 | echo "current path: $(pwd)" 28 | 29 | if [ ! -f "$CONF" ]; then 30 | echo "error: $CONF not exists!" 31 | exit 32 | fi 33 | CMD_PARAMS="-c /etc/pixiu/${CONF}" 34 | 35 | if [ -f "$API_CONF" ]; then 36 | CMD_PARAMS="$CMD_PARAMS -a /etc/pixiu/${API_CONF}" 37 | fi 38 | 39 | if [ -f "$LOG" ]; then 40 | CMD_PARAMS="$CMD_PARAMS -g /etc/pixiu/${LOG}" 41 | fi 42 | 43 | cd / ls -al . 44 | echo "current path: $(pwd)" 45 | echo "CMD_PARAMS: $CMD_PARAMS" 46 | ./dubbo-go-pixiu gateway start $CMD_PARAMS 47 | -------------------------------------------------------------------------------- /docs/common/README.md: -------------------------------------------------------------------------------- 1 | # Common 2 | 3 | * [FAQ](faq.md) 4 | * [Roadmap](roadmap.md) 5 | * [Proxy arguments](pixiu-arguments.md) 6 | -------------------------------------------------------------------------------- /docs/common/faq.md: -------------------------------------------------------------------------------- 1 | # FAQ 2 | 3 | If you can not get any help from this doc or [closed issues](https://github.com/apache/dubbo-go-pixiu/issues?q=is%3Aissue+is%3Aclosed), please [submit a new issue](https://github.com/apache/dubbo-go-pixiu/issues/new/choose). 4 | -------------------------------------------------------------------------------- /docs/developer/README.md: -------------------------------------------------------------------------------- 1 | # Developer Guide 2 | 3 | * [Concept](concept.md) 4 | * [Auto Registry](auto-registy.md) 5 | * [Filter](filter.md) 6 | * [Log](log.md) 7 | -------------------------------------------------------------------------------- /docs/developer/auto-registy.md: -------------------------------------------------------------------------------- 1 | # Auto Registry 2 | 3 | A feature easy for users to use dubbo-go-pixiu. 4 | 5 | ## Dubbo 6 | 7 | Find dubbo rpc interface from dubbo's register, use rules to significantly reduces the amount of manual registration. This feature is doing. 8 | -------------------------------------------------------------------------------- /docs/developer/concept.md: -------------------------------------------------------------------------------- 1 | # Concept 2 | 3 | ## Term 4 | 5 | The term in dubbo-go-pixiu 6 | -------------------------------------------------------------------------------- /docs/developer/log.md: -------------------------------------------------------------------------------- 1 | # Log 2 | 3 | How to view logs in dubbo-go-pixiu. 4 | 5 | ## DEBUG log 6 | 7 | ### Dubbo request log 8 | 9 | ```bash 10 | 2020-11-17T11:31:05.716+0800 DEBUG dubbo/dubbo.go:150 [dubbo-go-pixiu] dubbo invoke, method:GetUserByName, types:[java.lang.String], reqData:[tiecheng] 11 | ``` 12 | 13 | ### Dubbo response log 14 | 15 | ```bash 16 | 2020-11-17T11:31:05.718+0800 DEBUG dubbo/dubbo.go:160 [dubbo-go-pixiu] dubbo client resp:map[age:88 iD:3213 name:tiecheng time:] 17 | ``` 18 | 19 | -------------------------------------------------------------------------------- /docs/images/dubbgopixiu-infrastructure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/dubbgopixiu-infrastructure.png -------------------------------------------------------------------------------- /docs/images/dubbogopixiu-new-infrastructure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/dubbogopixiu-new-infrastructure.png -------------------------------------------------------------------------------- /docs/images/dubbogopixiu-procedure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/dubbogopixiu-procedure.png -------------------------------------------------------------------------------- /docs/images/group-pixiu-dingding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/group-pixiu-dingding.jpg -------------------------------------------------------------------------------- /docs/images/pixiu-logo-v4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/pixiu-logo-v4.png -------------------------------------------------------------------------------- /docs/images/pixiu-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/pixiu-logo.png -------------------------------------------------------------------------------- /docs/images/pixiu-old-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/dubbo-go-pixiu/81696fbc0fe325d540fa81dc4d52b1d7b023665f/docs/images/pixiu-old-logo.png -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # dubbo-go-pixiu Documentation 2 | 3 | ## [User Guide](user/README.md) 4 | 5 | * [Quick Start](user/start.md) 6 | * [Config](user/config.md) 7 | * [Metric](user/metric.md) 8 | 9 | ## [Samples](sample/README.md) 10 | 11 | * [dubbo](sample/dubbo/dubbo.md) 12 | * [http](sample/http/http.md) 13 | * [mock](sample/mock.md) 14 | * [plugins](../samples/plugins/index.md) 15 | * [Tracing](sample/others/jaeger.md) 16 | * [springcloud](sample/springcloud/README.md) 17 | 18 | ## [Developer Guide](developer/README.md) 19 | 20 | * [Concept](developer/concept.md) 21 | * [Auto Registry](developer/auto-registy.md) 22 | * [Filter](developer/filter.md) 23 | * [Log](developer/log.md) 24 | 25 | ## [Common](common/README.md) 26 | 27 | * [FAQ](common/faq.md) 28 | -------------------------------------------------------------------------------- /docs/sample/README.md: -------------------------------------------------------------------------------- 1 | # Document Catalog 2 | 3 | [中文文档](./zh-cn/README.md) 4 | * [dubbo](dubbo/dubbo.md) 5 | * [http](http/http.md) 6 | * [mock](mock.md) 7 | -------------------------------------------------------------------------------- /docs/sample/dubbo/dubbo-body(http).md: -------------------------------------------------------------------------------- 1 | # Get the parameter from the body 2 | 3 | > POST request 4 | 5 | ## Passthroughs 6 | 7 | ### Api Config 8 | 9 | ```yaml 10 | name: pixiu 11 | description: pixiu sample 12 | resources: 13 | - path: '/api/v1/test-dubbo/user' 14 | type: restful 15 | description: user 16 | methods: 17 | - httpVerb: POST 18 | enable: true 19 | timeout: 1000ms 20 | inboundRequest: 21 | requestType: http 22 | queryStrings: 23 | - name: name 24 | required: true 25 | integrationRequest: 26 | requestType: http 27 | host: 127.0.0.1:8889 28 | path: /UserProvider/CreateUser 29 | group: "test" 30 | version: 1.0.0 31 | ``` 32 | 33 | ### Request 34 | 35 | ```bash 36 | curl host:port/api/v1/test-dubbo/user -X POST -d '{"name": "tiecheng","id": "0002","code": 3,"age": 18}' --header "Content-Type: application/json" 37 | ``` 38 | 39 | ### Response 40 | 41 | - If first add, return like: 42 | 43 | ```json 44 | { 45 | "id": "0002", 46 | "code": 3, 47 | "name": "tiecheng", 48 | "age": 18, 49 | "time": "0001-01-01T00:00:00Z" 50 | } 51 | ``` 52 | 53 | - If you add user multi, return like: 54 | 55 | ```json 56 | { 57 | "message": "data is exist" 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /docs/sample/dubbo/dubbo-incomplete.md: -------------------------------------------------------------------------------- 1 | # Dubbo incomplete 2 | 3 | ## Args will nil 4 | 5 | > fix in dubbogo 1.5.4 6 | 7 | When the response is `User`, see below code: 8 | 9 | ```go 10 | type User struct { 11 | ID string 12 | Name string 13 | Age int32 14 | Time time.Time 15 | } 16 | ``` 17 | 18 | Although User struct has Time value, generic invoke will return nil. [the simple response](dubbo-query.md#simple) time field is disappear. 19 | 20 | So I suggest you can use string to time type for a short time. 21 | 22 | [Previous](dubbo.md) 23 | -------------------------------------------------------------------------------- /docs/sample/dubbo/dubbo-query(http).md: -------------------------------------------------------------------------------- 1 | # Get the parameter from the query 2 | 3 | > GET request 4 | 5 | ## Simple Demo 6 | 7 | ### Api Config 8 | 9 | ```yaml 10 | name: pixiu 11 | description: pixiu sample 12 | resources: 13 | - path: '/api/v1/test-dubbo/user' 14 | type: restful 15 | description: user 16 | methods: 17 | - httpVerb: GET 18 | enable: true 19 | timeout: 1000ms 20 | inboundRequest: 21 | requestType: http 22 | queryStrings: 23 | - name: name 24 | required: true 25 | integrationRequest: 26 | requestType: http 27 | host: 127.0.0.1:8889 28 | path: /UserProvider/GetUserByName 29 | mappingParams: 30 | - name: queryStrings.name 31 | mapTo: queryStrings.name 32 | group: "test" 33 | version: 1.0.0 34 | ``` 35 | 36 | ### Request 37 | 38 | ```bash 39 | curl http://localhost:8888/api/v1/test-dubbo/user?name=tc -X GET 40 | ``` 41 | 42 | ### Response 43 | 44 | - Successful result will return: 45 | 46 | ```bash 47 | { 48 | "id": "0001", 49 | "code": 1, 50 | "name": "tc", 51 | "age": 18, 52 | "time": "2020-12-24T16:46:31.8409857+08:00" 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /docs/sample/dubbo/dubbo-simple-run.md: -------------------------------------------------------------------------------- 1 | # How run dubbo simple test samples 2 | 3 | ## Start Pixiu 4 | 5 | - cd sample dir 6 | 7 | ```bash 8 | cd /dubbo-go-pixiu/samples/dubbogo/simple 9 | ``` 10 | 11 | - use start.sh to start pixiu and server quickly 12 | 13 | start.sh help for help info 14 | 15 | ``` 16 | ./start.sh help 17 | 18 | dubbo-go-pixiu start helper 19 | ./start.sh action project 20 | hint: 21 | ./start.sh prepare body for prepare config file and up docker in body project 22 | ./start.sh startPixiu body for start dubbo or http server in body project 23 | ./start.sh startServer body for start pixiu in body project 24 | ./start.sh startTest body for start unit test in body project 25 | ./start.sh clean body for clean 26 | 27 | ``` 28 | 29 | Use `./start.sh [action] [project]` to start sample,for exmaple: 30 | 31 | ```bash 32 | ./start.sh prepare body 33 | ./start.sh startPixiu body 34 | ./start.sh startServer body 35 | ./start.sh startTest body 36 | ./start.sh clean body 37 | ``` 38 | 39 | - interface access 40 | 41 | Go to the path of the specified test example,such as `/samples/dubbogo/simple/body` 42 | 43 | Executive Command: 44 | 45 | ```bash 46 | ./request.sh 47 | ``` 48 | 49 | -------------------------------------------------------------------------------- /docs/sample/dubbo/dubbo.md: -------------------------------------------------------------------------------- 1 | # Dubbo Catalog 2 | 3 | ### http to dubbo-protocol-base dubbo request 4 | 5 | * [dubbo-query](dubbo-query.md) 6 | * [dubbo-body](dubbo-body.md) 7 | * [dubbo-uri](dubbo-uri.md) 8 | * [dubbo-mix...params from uri,query,body](dubbo-mix.md) 9 | * [dubbo-universality...dubbo proxy model](dubbo-universality.md) 10 | * [dubbo-error](dubbo-error.md) 11 | * [dubbo-incomplete](dubbo-incomplete.md) 12 | * [dubbo-registry](dubbo-registry.md) 13 | 14 | ### http to http-protocl-base dubbo request 15 | 16 | * [http-body](http-body.md) 17 | * [http-query](http-query.md) 18 | * [http-uri](http-uri.md) 19 | 20 | > Based on [samples](https://github.com/apache/dubbo-go-pixiu-samples/tree/main/dubbogo/simple) 21 | 22 | How do I run a simple test example [document](dubbo-simple-run.md) 23 | 24 | [Previous](../README.md) 25 | -------------------------------------------------------------------------------- /docs/sample/dubbo/dubbo_sample_startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | if [ "$1" != "skip_zookeeper" ]; then 21 | zookeeper_container_id=$(docker ps | grep zookeeper | head -n 1 | awk '{print $1}') 22 | if [ -n "$zookeeper_container_id" ]; then 23 | echo "removing old zookeeper!" 24 | docker kill "$zookeeper_container_id" 25 | docker rm "$zookeeper_container_id" 26 | fi 27 | echo "starting zookeeper!" 28 | docker run -dit --name zookeeper -p 2181:2181 zookeeper:3.4.14 29 | echo "zookeeper stated!" 30 | fi 31 | 32 | 33 | APP_PATH=../../samples/dubbogo/simple 34 | 35 | go env -w GOPROXY=https://goproxy.cn,direct 36 | 37 | echo "starting dubbogo provider!" 38 | 39 | go build -o $APP_PATH/server/app/ $APP_PATH/server/app/ 40 | 41 | provider_pid=$(ps -ef | grep $APP_PATH/server/app/ | grep -v 'grep' | awk '{print $2}') 42 | 43 | if [ -n "$provider_pid" ]; then 44 | echo "pid of old dubbogo provider is $provider_pid, kill it" 45 | kill -9 "$provider_pid" 46 | fi 47 | nohup go run $APP_PATH/server/app/ >$APP_PATH/dubbgo_server.out & 48 | sleep 10 49 | echo "dubbogo provider started!" 50 | 51 | echo "starting proxy!" 52 | 53 | cd ../../ 54 | 55 | if [ -z "$CONF_PROVIDER_FILE_PATH" ]; then 56 | export CONF_PROVIDER_FILE_PATH=samples/dubbogo/simple/server/profiles/test/server.yml 57 | fi 58 | 59 | make run config-path=samples/dubbogo/simple/proxy/conf.yaml api-config-path=samples/dubbogo/simple/proxy/api_config.yaml 60 | -------------------------------------------------------------------------------- /docs/sample/dubbo/http-body.md: -------------------------------------------------------------------------------- 1 | # Get the parameter from the body 2 | 3 | > POST request 4 | 5 | ## Passthroughs 6 | 7 | ### Api Config 8 | 9 | ```yaml 10 | name: pixiu 11 | description: pixiu sample 12 | resources: 13 | - path: '/api/v1/test-http/user' 14 | type: restful 15 | description: user 16 | methods: 17 | - httpVerb: POST 18 | enable: true 19 | timeout: 10s 20 | inboundRequest: 21 | requestType: http 22 | integrationRequest: 23 | requestType: http 24 | host: "127.0.0.1:1314" 25 | path: "/user/" 26 | ``` 27 | 28 | ### Request 29 | 30 | ```bash 31 | curl host:port/api/v1/test-http/user -X POST -d '{"name": "tiecheng1","code": 4,"age": 18}' --header "Content-Type: application/json" 32 | ``` 33 | 34 | ### Response 35 | 36 | - If first add, return like: 37 | 38 | ```json 39 | { 40 | "id": "XVlBz", 41 | "name": "tiecheng1", 42 | "age": 18, 43 | "time": "0001-01-01T00:00:00Z" 44 | } 45 | ``` 46 | 47 | - If you add user multi, return like: 48 | 49 | ```json 50 | { 51 | "message": "data is exist" 52 | } 53 | ``` 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /docs/sample/dubbo/http-query.md: -------------------------------------------------------------------------------- 1 | # Get the parameter from the query 2 | 3 | > GET request 4 | 5 | ## Simple Demo 6 | 7 | ### Api Config 8 | 9 | ```yaml 10 | name: pixiu 11 | description: pixiu sample 12 | resources: 13 | - path: '/api/v1/test-http/user' 14 | type: restful 15 | description: user 16 | methods: 17 | - httpVerb: GET 18 | enable: true 19 | timeout: 1000ms 20 | inboundRequest: 21 | requestType: http 22 | queryStrings: 23 | - name: name 24 | required: true 25 | integrationRequest: 26 | requestType: http 27 | host: "127.0.0.1:1314" 28 | path: "/user" 29 | - httpVerb: POST 30 | enable: true 31 | timeout: 10s 32 | inboundRequest: 33 | requestType: http 34 | integrationRequest: 35 | requestType: http 36 | host: "127.0.0.1:1314" 37 | path: "/user/" 38 | ``` 39 | 40 | ### Request 41 | 42 | ```bash 43 | curl http://localhost:8888/api/v1/test-http/user?name=tc -X GET 44 | ``` 45 | 46 | ### Response 47 | 48 | - Successful result will return: 49 | 50 | ```bash 51 | { 52 | "id": "0001", 53 | "name": "tc", 54 | "age": 18, 55 | "time": "2020-12-30T14:07:07.9432117+08:00" 56 | } 57 | ``` 58 | -------------------------------------------------------------------------------- /docs/sample/http/http-http.md: -------------------------------------------------------------------------------- 1 | # Http to Http Proxy 2 | 3 | > Doc metions below fit the code in the `samples/http/simple` 4 | 5 | ## Define Apis in the pixiu/conf.yaml 6 | 7 | ```yaml 8 | --- 9 | static_resources: 10 | listeners: 11 | - name: "net/http" 12 | protocol_type: "HTTP" 13 | address: 14 | socket_address: 15 | address: "0.0.0.0" 16 | port: 8888 17 | filter_chains: 18 | filters: 19 | - name: dgp.filter.httpconnectionmanager 20 | config: 21 | route_config: 22 | routes: 23 | - match: 24 | prefix: "/user" 25 | route: 26 | cluster: "user" 27 | cluster_not_found_response_code: 505 28 | http_filters: 29 | - name: dgp.filter.http.httpproxy 30 | config: 31 | - name: dgp.filter.http.cors 32 | config: 33 | allow_origin: 34 | - api.dubbo.com 35 | allow_methods: "" 36 | allow_headers: "" 37 | expose_headers: "" 38 | max_age: "" 39 | allow_credentials: false 40 | - name: dgp.filter.http.response 41 | config: 42 | config: 43 | idle_timeout: 5s 44 | read_timeout: 5s 45 | write_timeout: 5s 46 | clusters: 47 | - name: "user" 48 | lb_policy: "lb" 49 | endpoints: 50 | - id: 1 51 | socket_address: 52 | address: 127.0.0.1 53 | port: 1314 54 | timeout_config: 55 | connect_timeout: "5s" 56 | request_timeout: "10s" 57 | shutdown_config: 58 | timeout: "60s" 59 | step_timeout: "10s" 60 | reject_policy: "immediacy" 61 | ``` 62 | 63 | for custom config , you can refer to [config](../../user/config.md) in user-guide 64 | -------------------------------------------------------------------------------- /docs/sample/http/http.md: -------------------------------------------------------------------------------- 1 | # HTTP 2 | 3 | Base on sample/http. 4 | 5 | * [http-http](http-http.md) 6 | * [http-gprc](http-grpc.md) 7 | 8 | 9 | [Previous](../README.md) 10 | -------------------------------------------------------------------------------- /docs/sample/mock.md: -------------------------------------------------------------------------------- 1 | # Mock request 2 | 3 | ## Simple Demo 4 | 5 | ### Api Config 6 | 7 | ```yaml 8 | name: pixiu 9 | description: pixiu sample 10 | resources: 11 | - path: '/api/v1/test-dubbo/mock' 12 | type: restful 13 | description: mock 14 | methods: 15 | - httpVerb: GET 16 | enable: true 17 | mock: true 18 | timeout: 1000ms 19 | inboundRequest: 20 | requestType: http 21 | ``` 22 | 23 | ### Request 24 | 25 | ```bash 26 | curl localhost:8888/api/v1/test-dubbo/mock -X GET 27 | ``` 28 | 29 | ### Response 30 | 31 | ```json 32 | { 33 | "message": "mock success" 34 | } 35 | ``` 36 | 37 | ## TODO 38 | 39 | We plan use can config custom result in the future. Not only api config way, but also create a match rule. 40 | 41 | [Previous](README.md) 42 | -------------------------------------------------------------------------------- /docs/sample/others/fail-inject.md: -------------------------------------------------------------------------------- 1 | # Fail Inject Filter Quick Start 2 | 3 | ## Start Pixiu: 4 | 5 | Examples of official references is in `https://github.com/dubbo-go-pixiu/samples` 6 | 7 | Add the following configuration file to the `samples/http/simple/pixiu/conf.yaml` 8 | 9 | ```yaml 10 | static_resources: 11 | listeners: 12 | - name: "net/http" 13 | protocol_type: "HTTP" 14 | address: 15 | socket_address: 16 | address: "0.0.0.0" 17 | port: 8888 18 | filter_chains: 19 | filters: 20 | - name: dgp.filter.httpconnectionmanager 21 | config: 22 | route_config: 23 | routes: 24 | - match: 25 | prefix: /user 26 | route: 27 | cluster: user 28 | cluster_not_found_response_code: 505 29 | http_filters: 30 | - name: dgp.filter.http.faultinjection 31 | config: 32 | fail_inject_rules: 33 | "/UserService/com.dubbogo.pixiu.UserService/GetUserByCode": 34 | type: delay 35 | trigger_type: random 36 | status_code: 500 37 | body: 'error' 38 | delay: 5s 39 | odds: 30 40 | config: 41 | idle_timeout: 5s 42 | read_timeout: 5s 43 | write_timeout: 5s 44 | clusters: 45 | - name: "user" 46 | lb_policy: "lb" 47 | endpoints: 48 | - id: 1 49 | socket_address: 50 | address: 127.0.0.1 51 | port: 1314 52 | health_checks: 53 | - protocol: "tcp" 54 | timeout: 1s 55 | interval: 2s 56 | healthy_threshold: 4 57 | unhealthy_threshold: 4 58 | shutdown_config: 59 | timeout: "60s" 60 | step_timeout: "10s" 61 | reject_policy: "immediacy" 62 | ``` 63 | 64 | Then execute the following command . 65 | 66 | ```shell 67 | go run cmd/pixiu/*.go gateway start -c samples/http/simplep/pixiu/conf.yaml 68 | ``` 69 | -------------------------------------------------------------------------------- /docs/sample/others/jaeger.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | #### Tracing with Jaeger 4 | 5 | 6 | There is a tracing filter, by which we can add tracing function for pixiu 7 | 8 | 9 | ```go 10 | http_filters: 11 | - name: dgp.filters.tracing 12 | config: 13 | url: http://127.0.0.1:14268/api/traces 14 | type: jaeger 15 | ``` 16 | 17 | you can quick start the demo in samples/dubbogo/simple/jaeger for experience 18 | -------------------------------------------------------------------------------- /docs/sample/springcloud/README.md: -------------------------------------------------------------------------------- 1 | # Quick Start 2 | 3 | Start Nacos [Docker environment]: 4 | 5 | ```bash 6 | cd samples/springcloud/docker 7 | run docker-compose.yml/services 8 | ``` 9 | 10 | Start SpringCloud [Java environment]: 11 | 12 | ```bash 13 | cd samples/springcloud/server 14 | 15 | # the port is 8074 16 | run auth-service 17 | 18 | # the port is 8071 19 | run user-service 20 | ``` 21 | 22 | Start Pixiu: 23 | 24 | ```bash 25 | go run cmd/pixiu/*.go gateway start -c samples/springcloud/pixiu/conf.yaml 26 | ``` 27 | 28 | Call the server of SpringCloud by Pixiu : 29 | 30 | ```bash 31 | # the serviceId is `user-provider` 32 | curl http://localhost:8888/user-service/echo/Pixiu 33 | 34 | # the serviceId is `auth-provider` 35 | curl http://localhost:8888/auth-service/echo/Pixiu 36 | ``` 37 | result on console : 38 | ```log 39 | Hello Nacos Discovery Pixiu 40 | ``` 41 | -------------------------------------------------------------------------------- /docs/sample/zh-cn/README.md: -------------------------------------------------------------------------------- 1 | # 示例 2 | 3 | [English](../README.md) 4 | * [dubbo](dubbo.md) 5 | -------------------------------------------------------------------------------- /docs/sample/zh-cn/dubbo/dubbo-simple-run.md: -------------------------------------------------------------------------------- 1 | # 如何运行 dubbo 简单的测试例子 2 | 3 | ## 启动 Pixiu 4 | 5 | - 打开 samples 路径 6 | 7 | ```bash 8 | cd /dubbo-go-pixiu/samples/dubbogo/simple 9 | ``` 10 | 11 | - 使用 start.sh 启动案例 12 | 13 | 使用 start.sh help 来获取帮助信息 14 | 15 | ``` 16 | ./start.sh help 17 | 18 | dubbo-go-pixiu start helper 19 | ./start.sh action project 20 | hint: 21 | ./start.sh prepare body for prepare config file and up docker in body project 22 | ./start.sh startPixiu body for start dubbo or http server in body project 23 | ./start.sh startServer body for start pixiu in body project 24 | ./start.sh startTest body for start unit test in body project 25 | ./start.sh clean body for clean 26 | 27 | ``` 28 | 29 | 使用 `./start.sh [action] [project]` 来启动案例,比如说: 30 | 31 | ```bash 32 | ./start.sh prepare body 33 | ./start.sh startPixiu body 34 | ./start.sh startServer body 35 | ./start.sh startTest body 36 | ./start.sh clean body 37 | ``` 38 | 39 | - 接口访问 40 | 41 | 先到指定测试例子的路径下,比如 `/samples/dubbogo/simple/body` 42 | 43 | 执行命令: 44 | 45 | ```bash 46 | ./request.sh 47 | ``` 48 | 49 | -------------------------------------------------------------------------------- /docs/sample/zh-cn/dubbo/dubbo.md: -------------------------------------------------------------------------------- 1 | # Dubbo 2 | 3 | * [dubbo-query](dubbo-query.md) 4 | * [dubbo-body](dubbo-body.md) 5 | * [dubbo-uri](dubbo-uri.md) 6 | * [dubbo-mix...params from uri,query,body](dubbo-mix.md) 7 | * [dubbo-universality...dubbo proxy model](dubbo-universality.md) 8 | * [dubbo-error](../dubbo-error.md) 9 | * [dubbo-incomplete](../dubbo-incomplete.md) 10 | 11 | > 基于的例子 [samples](https://github.com/apache/dubbo-go-pixiu-samples/tree/main/dubbogo/simple) 12 | 13 | 如何运行简单的测试例子[文档](dubbo-simple-run.md) 14 | 15 | [上一页](../README.md) 16 | 17 | -------------------------------------------------------------------------------- /docs/user/README.md: -------------------------------------------------------------------------------- 1 | # User Guide 2 | 3 | * [Quick Start](start.md) 4 | * [Api Model](api.md) 5 | * [Response](response.md) 6 | * [Installation](installation.md) 7 | -------------------------------------------------------------------------------- /docs/user/metric.md: -------------------------------------------------------------------------------- 1 | # Metric 2 | 3 | ## Enable 4 | 5 | You can enable the metric in config.yaml as follows. 6 | Config pixiu's ip and prometheus_port below in your prometheus config file 7 | will allow prometheus to scrape the metric generated by pixiu. 8 | 9 | ```yaml 10 | metric: 11 | enable: true 12 | prometheus_port: 2222 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/user/start.md: -------------------------------------------------------------------------------- 1 | # Start 2 | 3 | How to start the dubbo-go-pixiu 4 | 5 | #### 1 cd samples dir 6 | 7 | ``` 8 | cd samples/dubbo/simple 9 | ``` 10 | 11 | we can use start.sh to run samples quickly. for more info, execute command as below for more help 12 | 13 | ``` 14 | ./start.sh [action] [project] 15 | ./start.sh help 16 | ``` 17 | 18 | we run body samples below step 19 | 20 | #### 2 prepare config file and docker 21 | 22 | prepare command will prepare dubbo-server and pixiu config file and start docker container needed 23 | 24 | ``` 25 | ./start.sh prepare body 26 | ``` 27 | 28 | if prepare config file manually, notice: 29 | 30 | - modify $PROJECT_DIR in conf.yaml to absolute path in your compute 31 | 32 | #### 3 start dubbo or http server 33 | 34 | ``` 35 | ./start.sh startServer body 36 | ``` 37 | 38 | #### 4 start pixiu 39 | 40 | ``` 41 | ./start.sh startPixiu body 42 | ``` 43 | 44 | if run pixiu manually, use command as below 45 | 46 | ``` 47 | go run cmd/pixiu/*.go gateway start -c /[absolute-path]/dubbo-go-pixiu/samples/dubbo/simple/body/pixiu/conf.yaml 48 | ``` 49 | 50 | #### 5. Try a request 51 | 52 | use curl to try or use unit test 53 | 54 | ```bash 55 | curl -X POST 'localhost:8881/api/v1/test-dubbo/user' -d '{"id":"0003","code":3,"name":"dubbogo","age":99}' --header 'Content-Type: application/json' 56 | ./start.sh startTest body 57 | ``` 58 | 59 | #### 6. Clean 60 | 61 | ``` 62 | ./start.sh clean body 63 | ``` 64 | -------------------------------------------------------------------------------- /integrate_test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | if [ -z "$1" ]; then 18 | echo 'Provide test directory please, like : ./integrate_test.sh $(pwd)/samples/simple/server .' 19 | exit 20 | fi 21 | 22 | P_DIR=$(pwd)/$1 23 | PIXIU_DIR=$(pwd) 24 | 25 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile docker-up 26 | sleep 2 27 | # test 28 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile docker-health-check 29 | 30 | # start server 31 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile start 32 | sleep 2 33 | # start server 34 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile buildPixiu 35 | sleep 2 36 | # start integration 37 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile integration 38 | result=$? 39 | # stop server 40 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile clean 41 | 42 | make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f igt/Makefile docker-down 43 | 44 | sleep 1 45 | 46 | exit $((result)) 47 | -------------------------------------------------------------------------------- /pkg/adapter/dubboregistry/common/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package common 19 | 20 | import ( 21 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/api/config" 22 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/router" 23 | ) 24 | 25 | type RegistryEventListener interface { 26 | OnAddAPI(r router.API) error 27 | OnRemoveAPI(r router.API) error 28 | OnDeleteRouter(r config.Resource) error 29 | } 30 | -------------------------------------------------------------------------------- /pkg/adapter/dubboregistry/registry/base/baseregistry_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package baseregistry 19 | 20 | import ( 21 | "math/rand" 22 | "time" 23 | ) 24 | 25 | import ( 26 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/router" 27 | ) 28 | 29 | import ( 30 | "github.com/apache/dubbo-go-pixiu/pkg/adapter/dubboregistry/registry" 31 | ) 32 | 33 | var _ registry.Registry = new(mockRegFacade) 34 | 35 | type mockRegFacade struct { 36 | BaseRegistry 37 | } 38 | 39 | func (m *mockRegFacade) DoSubscribe() error { 40 | return nil 41 | } 42 | func (m *mockRegFacade) DoUnsubscribe() error { 43 | return nil 44 | } 45 | 46 | func CreateMockRegisteredAPI(urlPattern string) router.API { 47 | var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 48 | randStringRunes := func(n int) string { 49 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) 50 | b := make([]rune, n) 51 | for i := range b { 52 | b[i] = letterRunes[rng.Intn(len(letterRunes))] 53 | } 54 | return string(b) 55 | } 56 | if len(urlPattern) == 0 { 57 | urlPattern = randStringRunes(4) + "/" + randStringRunes(4) + "/" + randStringRunes(4) 58 | } 59 | return router.API{ 60 | URLPattern: urlPattern, 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pkg/adapter/dubboregistry/registry/listener.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package registry 19 | 20 | // Listener this interface defined for load services from different kinds registry, such as nacos,consul,zookeeper. 21 | type Listener interface { 22 | // Close closes this listener 23 | Close() 24 | // WatchAndHandle watch the target path and handle the event 25 | WatchAndHandle() 26 | } 27 | -------------------------------------------------------------------------------- /pkg/adapter/dubboregistry/registry/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package registry 19 | 20 | import ( 21 | "dubbo.apache.org/dubbo-go/v3/common" 22 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/api/config" 23 | ) 24 | 25 | import ( 26 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 27 | ) 28 | 29 | // TransferURL2Api transfer url and clusterName to IntegrationRequest 30 | func TransferURL2Api(url *common.URL, clusterName string) []config.IntegrationRequest { 31 | var irs []config.IntegrationRequest 32 | for _, method := range url.Methods { 33 | irs = append(irs, config.IntegrationRequest{ 34 | RequestType: config.RequestType(url.Protocol), 35 | DubboBackendConfig: config.DubboBackendConfig{ 36 | ApplicationName: url.GetParam(constant.NameKey, ""), 37 | Group: url.GetParam(constant.GroupKey, ""), 38 | Version: url.GetParam(constant.VersionKey, ""), 39 | Interface: url.GetParam(constant.InterfaceKey, ""), 40 | Method: method, 41 | Retries: url.GetParam(constant.RetriesKey, ""), 42 | ClusterName: clusterName, 43 | }, 44 | }) 45 | } 46 | return irs 47 | } 48 | -------------------------------------------------------------------------------- /pkg/adapter/springcloud/common/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package common 19 | 20 | const ( 21 | ZKLogDiscovery = "[ZKDiscover]" 22 | ) 23 | -------------------------------------------------------------------------------- /pkg/client/client.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package client 19 | 20 | // Client represents the interface of http/dubbo clients 21 | type Client interface { 22 | // Apply to init client 23 | Apply() error 24 | 25 | // Close close the client 26 | Close() error 27 | 28 | // Call invoke the downstream service. 29 | Call(req *Request) (res any, err error) 30 | 31 | // MapParams mapping param, uri, query, body ... 32 | MapParams(req *Request) (reqData any, err error) 33 | } 34 | 35 | /** 36 | * the following option is designed to support dubbo pixiu model. you can see 37 | * https://github.com/apache/dubbo-go-pixiu/pixiu/tree/master. 38 | */ 39 | 40 | // MapOption option map, key : name, value : option 41 | type MapOption map[string]RequestOption 42 | 43 | // RequestOption option interface. 44 | type RequestOption interface { 45 | Action(target, val any) error 46 | } 47 | -------------------------------------------------------------------------------- /pkg/client/dubbo/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package dubbo 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | // DubboProxyConfig the config for dubbo proxy 25 | type DubboProxyConfig struct { 26 | // Registries such as zk,nacos or etcd 27 | Registries map[string]model.Registry `yaml:"registries" json:"registries"` 28 | // Timeout 29 | Timeout *model.TimeoutConfig `yaml:"timeout_config" json:"timeout_config"` 30 | // IsDefaultMap whether to use DefaultMap role 31 | IsDefaultMap bool 32 | // AutoResolve whether to resolve api config from request 33 | AutoResolve bool `yaml:"auto_resolve" json:"auto_resolve,omitempty"` 34 | // Protoset path to load protoset files 35 | Protoset []string `yaml:"protoset" json:"protoset,omitempty"` 36 | // Load balance 37 | LoadBalance string `yaml:"load_balance" json:"load_balance,omitempty"` 38 | // Retries number of retries 39 | Retries string `yaml:"retries" json:"retries,omitempty"` 40 | } 41 | -------------------------------------------------------------------------------- /pkg/client/dubbo/default.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package dubbo 19 | 20 | import ( 21 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/api/config" 22 | ) 23 | 24 | // defaultMappingParams default http to dubbo config 25 | var defaultMappingParams = []config.MappingParam{ 26 | { 27 | Name: "requestBody.values", 28 | MapTo: "opt.values", 29 | }, { 30 | Name: "requestBody.types", 31 | MapTo: "opt.types", 32 | }, { 33 | Name: "uri.application", 34 | MapTo: "opt.application", 35 | }, { 36 | Name: "uri.interface", 37 | MapTo: "opt.interface", 38 | }, { 39 | Name: "queryStrings.method", 40 | MapTo: "opt.method", 41 | }, { 42 | Name: "queryStrings.group", 43 | MapTo: "opt.group", 44 | }, { 45 | Name: "queryStrings.version", 46 | MapTo: "opt.version", 47 | }, 48 | } 49 | -------------------------------------------------------------------------------- /pkg/client/metadata.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package client 19 | 20 | // DubboMetadata dubbo metadata, api config 21 | type DubboMetadata struct { 22 | ApplicationName string `yaml:"application_name" json:"application_name" mapstructure:"application_name"` 23 | Group string `yaml:"group" json:"group" mapstructure:"group"` 24 | Version string `yaml:"version" json:"version" mapstructure:"version"` 25 | Interface string `yaml:"interface" json:"interface" mapstructure:"interface"` 26 | Method string `yaml:"method" json:"method" mapstructure:"method"` 27 | Types []string `yaml:"types" json:"types" mapstructure:"types"` 28 | Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"` 29 | ClusterName string `yaml:"cluster_name" json:"cluster_name,omitempty" property:"cluster_name"` 30 | ProtocolTypeStr string `yaml:"protocol_type" json:"protocol_type,omitempty" property:"protocol_type"` 31 | SerializationTypeStr string `yaml:"serialization_type" json:"serialization_type,omitempty" property:"serialization_type"` 32 | } 33 | -------------------------------------------------------------------------------- /pkg/client/mq/msg.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package mq 19 | 20 | // Msq Request Action Type Enum 21 | 22 | type MQType string 23 | 24 | type MQAction int 25 | 26 | const ( 27 | MQActionPublish = 1 + iota 28 | MQActionSubscribe 29 | MQActionUnSubscribe 30 | ) 31 | 32 | var MQActionIntToStr = map[MQAction]string{ 33 | MQActionPublish: "publish", 34 | MQActionSubscribe: "subscribe", 35 | MQActionUnSubscribe: "unsubscribe", 36 | } 37 | 38 | var MQActionStrToInt = map[string]MQAction{ 39 | "publish": MQActionPublish, 40 | "subscribe": MQActionSubscribe, 41 | "unsubscribe": MQActionUnSubscribe, 42 | } 43 | 44 | // MQSubscribeRequest url format http://domain/publish/broker/topic 45 | type MQSubscribeRequest struct { 46 | TopicList []string `json:"topic_list"` 47 | ConsumerGroup string `json:"consumer_group"` 48 | ConsumeUrl string `json:"consume_url"` // not empty when subscribe msg, eg: http://10.0.0.1:11451/consume 49 | CheckUrl string `json:"check_url"` // not empty when subscribe msg, eg: http://10.0.0.1:11451/health 50 | } 51 | 52 | // MQUnSubscribeRequest url format http://domain/publish/broker/topic 53 | type MQUnSubscribeRequest struct { 54 | ConsumerGroup string `json:"consumer_group"` 55 | } 56 | 57 | type MQProduceRequest struct { 58 | Topic string `json:"topic"` 59 | Msg []string `json:"msg"` 60 | } 61 | 62 | type MQMsgPush struct { 63 | Msg []string `json:"msg"` 64 | } 65 | -------------------------------------------------------------------------------- /pkg/client/request.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package client 19 | 20 | import ( 21 | "context" 22 | "net/http" 23 | "time" 24 | ) 25 | 26 | import ( 27 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/api/config" 28 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/router" 29 | ) 30 | 31 | // Request request for endpoint 32 | type Request struct { 33 | Context context.Context 34 | IngressRequest *http.Request 35 | API router.API 36 | Timeout time.Duration 37 | } 38 | 39 | // NewReq create a request 40 | func NewReq(ctx context.Context, request *http.Request, api router.API) *Request { 41 | return &Request{ 42 | Context: ctx, 43 | IngressRequest: request, 44 | API: api, 45 | } 46 | } 47 | 48 | // GetURL new url 49 | func (r *Request) GetURL() string { 50 | ir := r.API.IntegrationRequest 51 | if ir.RequestType == config.HTTPRequest { 52 | if len(ir.HTTPBackendConfig.URL) != 0 { 53 | return ir.HTTPBackendConfig.URL 54 | } 55 | 56 | // now only support http. 57 | scheme := "http" 58 | 59 | return scheme + "://" + r.IngressRequest.Host + r.IngressRequest.URL.Path 60 | } 61 | 62 | return "" 63 | } 64 | -------------------------------------------------------------------------------- /pkg/client/response.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package client 19 | 20 | import ( 21 | "io" 22 | ) 23 | 24 | // UnaryResponse response from endpoint 25 | type UnaryResponse struct { 26 | Data []byte 27 | } 28 | 29 | // NewUnaryResponse create response contains a []byte 30 | func NewUnaryResponse(data []byte) *UnaryResponse { 31 | return &UnaryResponse{Data: data} 32 | } 33 | 34 | // StreamResponse response from endpoint 35 | type StreamResponse struct { 36 | Stream io.ReadCloser 37 | IsSSEStream bool 38 | } 39 | 40 | func (r *StreamResponse) IsSSE() bool { 41 | return r.IsSSEStream 42 | } 43 | 44 | // NewStreamResponse create response contains a stream 45 | func NewStreamResponse(stream io.ReadCloser, isSSE bool) *StreamResponse { 46 | return &StreamResponse{Stream: stream, IsSSEStream: isSSE} 47 | } 48 | -------------------------------------------------------------------------------- /pkg/cluster/cluster.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package cluster 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/cluster/healthcheck" 22 | "github.com/apache/dubbo-go-pixiu/pkg/model" 23 | ) 24 | 25 | type Cluster struct { 26 | HealthCheck *healthcheck.HealthChecker 27 | Config *model.ClusterConfig 28 | } 29 | 30 | func NewCluster(clusterConfig *model.ClusterConfig) *Cluster { 31 | c := &Cluster{ 32 | Config: clusterConfig, 33 | } 34 | 35 | // only handle one health checker 36 | if len(c.Config.HealthChecks) != 0 { 37 | c.HealthCheck = healthcheck.CreateHealthCheck(clusterConfig, c.Config.HealthChecks[0]) 38 | c.HealthCheck.Start() 39 | } 40 | return c 41 | } 42 | 43 | func (c *Cluster) Stop() { 44 | if c.HealthCheck != nil { 45 | c.HealthCheck.Stop() 46 | } 47 | } 48 | 49 | func (c *Cluster) RemoveEndpoint(endpoint *model.Endpoint) { 50 | if c.HealthCheck != nil { 51 | c.HealthCheck.StopOne(endpoint) 52 | } 53 | } 54 | 55 | func (c *Cluster) AddEndpoint(endpoint *model.Endpoint) { 56 | if c.HealthCheck != nil { 57 | c.HealthCheck.StartOne(endpoint) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pkg/cluster/healthcheck/http.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package healthcheck 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | type HTTPChecker struct { 25 | address string 26 | timeout time.Duration 27 | } 28 | 29 | func (s *HTTPChecker) CheckHealth() bool { 30 | tarAddr := s.address 31 | return CheckTcpConn(tarAddr, "80", s.timeout) 32 | } 33 | 34 | func (s *HTTPChecker) OnTimeout() {} 35 | -------------------------------------------------------------------------------- /pkg/cluster/healthcheck/https.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package healthcheck 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | type HTTPSChecker struct { 25 | address string 26 | timeout time.Duration 27 | } 28 | 29 | func (s *HTTPSChecker) CheckHealth() bool { 30 | tarAddr := s.address 31 | return CheckTcpConn(tarAddr, "443", s.timeout) 32 | 33 | } 34 | 35 | func (s *HTTPSChecker) OnTimeout() {} 36 | -------------------------------------------------------------------------------- /pkg/cluster/healthcheck/tcp.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package healthcheck 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | type TCPChecker struct { 25 | address string 26 | timeout time.Duration 27 | } 28 | 29 | func (s *TCPChecker) CheckHealth() bool { 30 | return CheckTcpConn(s.address, "", s.timeout) 31 | } 32 | 33 | func (s *TCPChecker) OnTimeout() {} 34 | -------------------------------------------------------------------------------- /pkg/cluster/loadbalancer/load_balancer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package loadbalancer 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | type LoadBalancer interface { 25 | Handler(c *model.ClusterConfig, policy model.LbPolicy) *model.Endpoint 26 | } 27 | 28 | // LoadBalancerStrategy load balancer strategy mode 29 | var LoadBalancerStrategy = map[model.LbPolicyType]LoadBalancer{} 30 | 31 | func RegisterLoadBalancer(name model.LbPolicyType, balancer LoadBalancer) { 32 | if _, ok := LoadBalancerStrategy[name]; ok { 33 | panic("load balancer register fail " + name) 34 | } 35 | LoadBalancerStrategy[name] = balancer 36 | } 37 | 38 | func RegisterConsistentHashInit(name model.LbPolicyType, function model.ConsistentHashInitFunc) { 39 | if _, ok := model.ConsistentHashInitMap[name]; ok { 40 | panic("consistent hash load balancer register fail " + name) 41 | } 42 | model.ConsistentHashInitMap[name] = function 43 | } 44 | -------------------------------------------------------------------------------- /pkg/cluster/loadbalancer/maglev/maglev_hash_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package maglev 19 | 20 | import ( 21 | "fmt" 22 | stdHttp "net/http" 23 | "strconv" 24 | "testing" 25 | ) 26 | 27 | import ( 28 | "github.com/apache/dubbo-go-pixiu/pkg/context/http" 29 | "github.com/apache/dubbo-go-pixiu/pkg/model" 30 | ) 31 | 32 | func TestMaglevHash(t *testing.T) { 33 | 34 | nodeCount := 5 35 | 36 | nodes := make([]*model.Endpoint, 0, nodeCount) 37 | 38 | for i := 1; i <= nodeCount; i++ { 39 | name := strconv.Itoa(i) 40 | nodes = append(nodes, &model.Endpoint{ID: name, Name: name, 41 | Address: model.SocketAddress{Address: "192.168.1." + name, Port: 1000 + i}}) 42 | } 43 | 44 | cluster := &model.ClusterConfig{ 45 | Name: "test-cluster", 46 | Endpoints: nodes, 47 | LbStr: model.LoadBalancerMaglevHashing, 48 | ConsistentHash: model.ConsistentHash{MaglevTableSize: 521}, 49 | } 50 | cluster.CreateConsistentHash() 51 | 52 | var ( 53 | hashing = MaglevHash{} 54 | path string 55 | ) 56 | 57 | for i := 1; i <= 20; i++ { 58 | path = fmt.Sprintf("/pixiu?total=%d", i) 59 | t.Log(hashing.Handler(cluster, &http.HttpContext{Request: &stdHttp.Request{Method: stdHttp.MethodGet, RequestURI: path}})) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pkg/cluster/loadbalancer/rand/load_balancer_rand.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package rand 19 | 20 | import ( 21 | "math/rand" 22 | ) 23 | 24 | import ( 25 | "github.com/apache/dubbo-go-pixiu/pkg/cluster/loadbalancer" 26 | "github.com/apache/dubbo-go-pixiu/pkg/model" 27 | ) 28 | 29 | func init() { 30 | loadbalancer.RegisterLoadBalancer(model.LoadBalancerRand, Rand{}) 31 | } 32 | 33 | type Rand struct{} 34 | 35 | func (Rand) Handler(c *model.ClusterConfig, _ model.LbPolicy) *model.Endpoint { 36 | return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints)-1)] 37 | } 38 | -------------------------------------------------------------------------------- /pkg/cluster/loadbalancer/ringhash/ring_hash_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ringhash 19 | 20 | import ( 21 | "fmt" 22 | stdHttp "net/http" 23 | "strconv" 24 | "testing" 25 | ) 26 | 27 | import ( 28 | "github.com/apache/dubbo-go-pixiu/pkg/context/http" 29 | "github.com/apache/dubbo-go-pixiu/pkg/model" 30 | ) 31 | 32 | func TestHashRing(t *testing.T) { 33 | 34 | nodeCount := 5 35 | 36 | nodes := make([]*model.Endpoint, 0, nodeCount) 37 | 38 | for i := 1; i <= nodeCount; i++ { 39 | name := strconv.Itoa(i) 40 | nodes = append(nodes, &model.Endpoint{ID: name, Name: name, 41 | Address: model.SocketAddress{Address: "192.168.1." + name, Port: 1000 + i}}) 42 | } 43 | 44 | cluster := &model.ClusterConfig{ 45 | Name: "cluster1", 46 | Endpoints: nodes, 47 | LbStr: model.LoadBalancerRingHashing, 48 | ConsistentHash: model.ConsistentHash{ReplicaNum: 10, MaxVnodeNum: 1023}, 49 | } 50 | cluster.CreateConsistentHash() 51 | 52 | var ( 53 | hashing = RingHashing{} 54 | path string 55 | ) 56 | 57 | for i := 1; i <= 20; i++ { 58 | path = fmt.Sprintf("/pixiu?total=%d", i) 59 | t.Log(hashing.Handler(cluster, &http.HttpContext{Request: &stdHttp.Request{Method: stdHttp.MethodGet, RequestURI: path}})) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pkg/cluster/loadbalancer/roundrobin/round_robin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package roundrobin 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/cluster/loadbalancer" 22 | "github.com/apache/dubbo-go-pixiu/pkg/model" 23 | ) 24 | 25 | func init() { 26 | loadbalancer.RegisterLoadBalancer(model.LoadBalancerRoundRobin, RoundRobin{}) 27 | } 28 | 29 | type RoundRobin struct{} 30 | 31 | func (RoundRobin) Handler(c *model.ClusterConfig, _ model.LbPolicy) *model.Endpoint { 32 | endpoints := c.GetEndpoint(true) 33 | lens := len(endpoints) 34 | if c.PrePickEndpointIndex >= lens { 35 | c.PrePickEndpointIndex = 0 36 | } 37 | e := endpoints[c.PrePickEndpointIndex] 38 | c.PrePickEndpointIndex = (c.PrePickEndpointIndex + 1) % lens 39 | return e 40 | } 41 | -------------------------------------------------------------------------------- /pkg/cmd/deployer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package cmd 19 | 20 | type Deployer interface { 21 | initialize() error 22 | 23 | start() error 24 | 25 | stop() error 26 | } 27 | -------------------------------------------------------------------------------- /pkg/cmd/sidecar.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package cmd 19 | 20 | import ( 21 | "fmt" 22 | ) 23 | 24 | import ( 25 | "github.com/spf13/cobra" 26 | ) 27 | 28 | func init() { 29 | SideCarCmd.AddCommand(startSideCarCmd) 30 | } 31 | 32 | var ( 33 | SideCarCmd = &cobra.Command{ 34 | Use: "sidecar", 35 | Short: "Run dubbo go pixiu in sidecar mode (implement in the future)", 36 | } 37 | 38 | startSideCarCmd = &cobra.Command{ 39 | Use: "start", 40 | Short: "Start sidecar (implement in the future)", 41 | Run: func(cmd *cobra.Command, args []string) { 42 | fmt.Println("Meet you in the Future!") 43 | }, 44 | } 45 | ) 46 | -------------------------------------------------------------------------------- /pkg/common/constant/env.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package constant 19 | 20 | // env key 21 | const ( 22 | EnvResponseStrategy = "dgp-response-strategy" 23 | EnvMock = "dgp-mock" 24 | ) 25 | 26 | const ( 27 | EnvDubbogoPixiuConfig = "DUBBOGO_PIXIU_CONFIG" 28 | EnvDubbogoPixiuApiConfig = "DUBBOGO_PIXIU_API_CONFIG" 29 | EnvDubbogoPixiuLogConfig = "DUBBOGO_PIXIU_LOG_CONFIG" 30 | EnvDubbogoPixiuLogLevel = "DUBBOGO_PIXIU_LOG_LEVEL" 31 | EnvDubbogoPixiuLogFormat = "DUBBOGO_PIXIU_LOG_FORMAT" 32 | EnvDubbogoPixiuLimitCpus = "DUBBOGO_PIXIU_LIMIT_CPUS" 33 | ) 34 | 35 | // registry configuration 36 | const ( 37 | EnvDubbogoPixiuNacosRegistryAddress = "NACOS_ADDRESS" 38 | ) 39 | -------------------------------------------------------------------------------- /pkg/common/constant/filter.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package constant 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | var ( 25 | Default403Body = []byte("403 for bidden") 26 | Default404Body = []byte("404 page not found") 27 | Default405Body = []byte("405 method not allowed") 28 | Default406Body = []byte("406 api not up") 29 | Default503Body = []byte("503 service unavailable") 30 | ) 31 | 32 | const ( 33 | // nolint 34 | // FileDateFormat 35 | FileDateFormat = "2006-01-02" 36 | // nolint 37 | // MessageDateLayout 38 | MessageDateLayout = "2006-01-02 15:04:05" 39 | // nolint 40 | // LogFileMode 41 | LogFileMode = 0o600 42 | // nolint 43 | // buffer 44 | LogDataBuffer = 5000 45 | // console 46 | Console = "console" 47 | 48 | DefaultReqTimeout = 10 * time.Second 49 | ) 50 | -------------------------------------------------------------------------------- /pkg/common/constant/hotreload.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package constant 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | const ( 25 | CheckConfigInterval = 1 * time.Second 26 | ) 27 | -------------------------------------------------------------------------------- /pkg/common/constant/jtypes.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package constant 19 | 20 | import ( 21 | "reflect" 22 | "time" 23 | ) 24 | 25 | // Object represents the java.lang.Object type 26 | type Object any 27 | 28 | // JTypeMapper maps the java basic types to golang types 29 | var JTypeMapper = map[string]reflect.Type{ 30 | "string": reflect.TypeOf(""), 31 | "java.lang.String": reflect.TypeOf(""), 32 | "char": reflect.TypeOf(""), 33 | "short": reflect.TypeOf(int16(0)), 34 | "int": reflect.TypeOf(int(0)), 35 | "long": reflect.TypeOf(int64(0)), 36 | "float": reflect.TypeOf(float32(0)), 37 | "double": reflect.TypeOf(float64(0)), 38 | "boolean": reflect.TypeOf(true), 39 | "java.util.Date": reflect.TypeOf(time.Time{}), 40 | "date": reflect.TypeOf(time.Time{}), 41 | "object": reflect.TypeOf([]Object{}).Elem(), 42 | "java.lang.Object": reflect.TypeOf([]Object{}).Elem(), 43 | } 44 | -------------------------------------------------------------------------------- /pkg/common/constant/pixiu.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package constant 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | // default timeout 1s. 25 | const ( 26 | DefaultTimeoutStr = "1s" 27 | DefaultTimeout = time.Second 28 | ) 29 | 30 | const ( 31 | // DefaultBodyAll body passthrough. 32 | DefaultBodyAll = "_all" 33 | ) 34 | 35 | // strategy for response. 36 | const ( 37 | ResponseStrategyNormal = "normal" 38 | ResponseStrategyHump = "hump" 39 | ) 40 | 41 | const ( 42 | // DefaultDiscoveryType Set up default discovery type. 43 | DefaultDiscoveryType = "EDS" 44 | // DefaultLoadBalanceType Set up default load balance type. 45 | DefaultLoadBalanceType = "RoundRobin" 46 | // DefaultFilterType Set up default filter type. 47 | DefaultFilterType = "dgp.filter.httpconnectionmanager" 48 | // DefaultHTTPType Set up default HTTP Type. 49 | DefaultHTTPType = "net/http" 50 | // DefaultProtocolType Set up default protocol type. 51 | DefaultProtocolType = "HTTP" 52 | ) 53 | 54 | const ( 55 | // YAML .yaml 56 | YAML = ".yaml" 57 | //YML .yml 58 | YML = ".yml" 59 | ) 60 | 61 | const ( 62 | StringSeparator = "," 63 | DefaultConfigPath = "configs/conf.yaml" 64 | DefaultApiConfigPath = "configs/api_config.yaml" 65 | DefaultLogConfigPath = "configs/log.yml" 66 | DefaultLogLevel = "info" 67 | DefaultLimitCpus = "0" 68 | DefaultLogFormat = "" 69 | ) 70 | -------------------------------------------------------------------------------- /pkg/common/constant/remote.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package constant 19 | 20 | // env key 21 | const ( 22 | Zookeeper string = "zookeeper" 23 | Nacos string = "nacos" 24 | Consul string = "consul" 25 | ) 26 | -------------------------------------------------------------------------------- /pkg/common/constant/url.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package constant 18 | 19 | const ( 20 | // RequestBody name of api config mapping from/to 21 | RequestBody = "requestBody" 22 | // QueryStrings name of api config mapping from/to 23 | QueryStrings = "queryStrings" 24 | // Headers name of api config mapping from/to 25 | Headers = "headers" 26 | // RequestURI name of api config mapping from/to, retrieve parameters from uri 27 | // for instance, https://test.com/:id uri.id will retrieve the :id parameter 28 | RequestURI = "uri" 29 | // Dot defines the . which will be used to present the path to specific field in the body 30 | Dot = "." 31 | AnyValue = "*" 32 | ) 33 | -------------------------------------------------------------------------------- /pkg/common/extension/adapter/adapter.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package adapter 19 | 20 | import ( 21 | "fmt" 22 | ) 23 | 24 | import ( 25 | "github.com/pkg/errors" 26 | ) 27 | 28 | import ( 29 | "github.com/apache/dubbo-go-pixiu/pkg/model" 30 | ) 31 | 32 | type ( 33 | // AdapterPlugin plugin for adapter 34 | AdapterPlugin interface { 35 | // Kind returns the unique kind name to represent itself. 36 | Kind() string 37 | 38 | // CreateAdapter return the Adapter callback 39 | CreateAdapter(ad *model.Adapter) (Adapter, error) 40 | } 41 | 42 | // Adapter adapter interface 43 | Adapter interface { 44 | // Start start adapter lifetime 45 | Start() 46 | // Stop stop adapter lifetime 47 | Stop() 48 | // Apply init 49 | Apply() error 50 | // Config get config for Adapter 51 | Config() any 52 | } 53 | ) 54 | 55 | var ( 56 | adapterPlugins = map[string]AdapterPlugin{} 57 | ) 58 | 59 | // RegisterAdapterPlugin registers adapter plugin 60 | func RegisterAdapterPlugin(p AdapterPlugin) { 61 | if p.Kind() == "" { 62 | panic(fmt.Errorf("%T: empty kind", p)) 63 | } 64 | 65 | existedPlugin, existed := adapterPlugins[p.Kind()] 66 | if existed { 67 | panic(fmt.Errorf("%T and %T got same kind: %s", p, existedPlugin, p.Kind())) 68 | } 69 | 70 | adapterPlugins[p.Kind()] = p 71 | } 72 | 73 | // GetAdapterPlugin get plugin by kind 74 | func GetAdapterPlugin(kind string) (AdapterPlugin, error) { 75 | existedAdapter, existed := adapterPlugins[kind] 76 | if existed { 77 | return existedAdapter, nil 78 | } 79 | return nil, errors.Errorf("plugin not found %s", kind) 80 | } 81 | -------------------------------------------------------------------------------- /pkg/common/extension/adapter/adapter_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package adapter 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | import ( 25 | "github.com/stretchr/testify/assert" 26 | ) 27 | 28 | import ( 29 | "github.com/apache/dubbo-go-pixiu/pkg/model" 30 | ) 31 | 32 | type ( 33 | DemoAdapterPlugin struct{} 34 | 35 | DemoAdapter struct { 36 | cfg *Config 37 | } 38 | 39 | Config struct{} 40 | ) 41 | 42 | func (d *DemoAdapterPlugin) Kind() string { 43 | return "test" 44 | } 45 | 46 | func (p *DemoAdapterPlugin) CreateAdapter(ad *model.Adapter) (Adapter, error) { 47 | return &DemoAdapter{cfg: &Config{}}, nil 48 | } 49 | 50 | // Apply init 51 | func (a *DemoAdapter) Apply() error { 52 | return nil 53 | } 54 | 55 | // Config get config for Adapter 56 | func (a *DemoAdapter) Config() any { 57 | return a.cfg 58 | } 59 | 60 | func (a *DemoAdapter) Start() { 61 | 62 | } 63 | 64 | func (a *DemoAdapter) Stop() { 65 | 66 | } 67 | 68 | func TestRegisterAdapterPlugin(t *testing.T) { 69 | RegisterAdapterPlugin(&DemoAdapterPlugin{}) 70 | _, err := GetAdapterPlugin("test") 71 | assert.NoError(t, err) 72 | } 73 | -------------------------------------------------------------------------------- /pkg/common/extension/filter/filter_status.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package filter 19 | 20 | type FilterStatus int 21 | 22 | const ( 23 | Continue FilterStatus = iota 24 | Stop 25 | ) 26 | -------------------------------------------------------------------------------- /pkg/common/grpc/RoundTripper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package grpc 19 | 20 | import ( 21 | "net/http" 22 | ) 23 | 24 | import ( 25 | "golang.org/x/net/http2" 26 | ) 27 | 28 | type HttpForwarder struct { 29 | transport *http2.Transport 30 | } 31 | 32 | func (hf *HttpForwarder) Forward(r *http.Request) (*http.Response, error) { 33 | return hf.transport.RoundTrip(r) 34 | } 35 | -------------------------------------------------------------------------------- /pkg/common/mock/router.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package mock 19 | 20 | import ( 21 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/api/config" 22 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/router" 23 | ) 24 | 25 | // GetMockAPI a mock util to create router.API 26 | func GetMockAPI(verb config.HTTPVerb, urlPattern string, filters ...string) router.API { 27 | inbound := config.InboundRequest{} 28 | integration := config.IntegrationRequest{RequestType: config.DubboRequest} 29 | method := config.Method{ 30 | Enable: true, 31 | HTTPVerb: verb, 32 | InboundRequest: inbound, 33 | IntegrationRequest: integration, 34 | } 35 | return router.API{ 36 | URLPattern: urlPattern, 37 | Method: method, 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pkg/common/shutdown/graceful_shutdown_signal_darwin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package shutdown 19 | 20 | import ( 21 | "os" 22 | "syscall" 23 | ) 24 | 25 | var ( 26 | // ShutdownSignals receives shutdown signals to process 27 | ShutdownSignals = []os.Signal{ 28 | os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP, 29 | syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, 30 | syscall.SIGABRT, syscall.SIGSYS, syscall.SIGTERM, 31 | } 32 | 33 | // DumpHeapShutdownSignals receives shutdown signals to process 34 | DumpHeapShutdownSignals = []os.Signal{ 35 | syscall.SIGQUIT, syscall.SIGILL, 36 | syscall.SIGTRAP, syscall.SIGABRT, syscall.SIGSYS, 37 | } 38 | ) 39 | -------------------------------------------------------------------------------- /pkg/common/shutdown/graceful_shutdown_signal_linux.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package shutdown 19 | 20 | import ( 21 | "os" 22 | "syscall" 23 | ) 24 | 25 | var ( 26 | // ShutdownSignals receives shutdown signals to process 27 | ShutdownSignals = []os.Signal{ 28 | os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP, 29 | syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, 30 | syscall.SIGABRT, syscall.SIGSYS, syscall.SIGTERM, 31 | } 32 | 33 | // DumpHeapShutdownSignals receives shutdown signals to process 34 | DumpHeapShutdownSignals = []os.Signal{ 35 | syscall.SIGQUIT, syscall.SIGILL, 36 | syscall.SIGTRAP, syscall.SIGABRT, syscall.SIGSYS, 37 | } 38 | ) 39 | -------------------------------------------------------------------------------- /pkg/common/shutdown/graceful_shutdown_signal_windows.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package shutdown 19 | 20 | import ( 21 | "os" 22 | "syscall" 23 | ) 24 | 25 | var ( 26 | // ShutdownSignals receives shutdown signals to process 27 | ShutdownSignals = []os.Signal{ 28 | os.Interrupt, os.Kill, syscall.SIGKILL, 29 | syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, 30 | syscall.SIGABRT, syscall.SIGTERM, 31 | } 32 | 33 | // DumpHeapShutdownSignals receives shutdown signals to process 34 | DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, syscall.SIGABRT} 35 | ) 36 | -------------------------------------------------------------------------------- /pkg/common/yaml/testdata/config.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | intTest: 11 20 | booleanTest: false 21 | strTest: "strTest" 22 | 23 | child: 24 | strTest: "childStrTest" -------------------------------------------------------------------------------- /pkg/config/api_config_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package config_test 19 | 20 | import ( 21 | "log" 22 | "testing" 23 | ) 24 | 25 | import ( 26 | "github.com/stretchr/testify/assert" 27 | ) 28 | 29 | import ( 30 | "github.com/apache/dubbo-go-pixiu/pkg/common/yaml" 31 | "github.com/apache/dubbo-go-pixiu/pkg/config" 32 | ) 33 | 34 | func TestLoadAPIConfigFromFile(t *testing.T) { 35 | apiC, err := config.LoadAPIConfigFromFile("") 36 | assert.Empty(t, apiC) 37 | assert.EqualError(t, err, "Config file not specified") 38 | 39 | apiC, err = config.LoadAPIConfigFromFile("./mock/api_config.yml") 40 | assert.Empty(t, err) 41 | assert.Equal(t, apiC.Name, "api name") 42 | bytes, _ := yaml.MarshalYML(apiC) 43 | log.Printf("%s", bytes) 44 | } 45 | -------------------------------------------------------------------------------- /pkg/config/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package config 19 | 20 | const ( 21 | Version = "0.4.0" 22 | ) 23 | -------------------------------------------------------------------------------- /pkg/config/xds/apiclient/apiclient.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package apiclient 19 | 20 | import ( 21 | "reflect" 22 | ) 23 | 24 | import ( 25 | v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" 26 | anypb "github.com/golang/protobuf/ptypes/any" 27 | "github.com/pkg/errors" 28 | "google.golang.org/protobuf/proto" 29 | ) 30 | 31 | type ( 32 | ResourceTypeName = string 33 | PixiuDynamicConfigModel proto.Message 34 | 35 | ProtoAny struct { 36 | typeConfig *v3.TypedExtensionConfig 37 | any *anypb.Any 38 | } 39 | 40 | DeltaResources struct { 41 | NewResources []*ProtoAny 42 | RemovedResource []string 43 | } 44 | ) 45 | 46 | func (p *ProtoAny) GetName() string { 47 | return p.typeConfig.Name 48 | } 49 | 50 | func (p *ProtoAny) To(configModel PixiuDynamicConfigModel) error { 51 | if p.any != nil { 52 | return p.any.UnmarshalTo(configModel) 53 | } 54 | 55 | err := p.typeConfig.TypedConfig.UnmarshalTo(configModel) 56 | if err != nil { 57 | panic(err) 58 | } 59 | return errors.Wrapf(err, "can not covert to %v", reflect.TypeOf(configModel)) 60 | } 61 | 62 | func NewProtoAny(typeConfig *v3.TypedExtensionConfig) *ProtoAny { 63 | return &ProtoAny{typeConfig: typeConfig} 64 | } 65 | -------------------------------------------------------------------------------- /pkg/context/base_context.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package context 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | type ( 25 | ContextKey string 26 | 27 | // Context run context 28 | Context interface { 29 | Next() 30 | Abort() 31 | AbortWithError(string, error) 32 | 33 | Status(code int) 34 | StatusCode() int 35 | WriteWithStatus(int, []byte) (int, error) 36 | Write([]byte) (int, error) 37 | AddHeader(k, v string) 38 | GetHeader(k string) string 39 | GetUrl() string 40 | GetMethod() string 41 | 42 | BuildFilters() 43 | 44 | GetRouteEntry() *model.RouteAction 45 | SetRouteEntry(ra *model.RouteAction) 46 | GetClientIP() string 47 | GetApplicationName() string 48 | 49 | WriteErr(p any) 50 | 51 | Request() 52 | Response() 53 | } 54 | ) 55 | 56 | func (c ContextKey) String() string { 57 | return string(c) 58 | } 59 | -------------------------------------------------------------------------------- /pkg/context/dubbo/context.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package dubbo 19 | 20 | import ( 21 | "context" 22 | ) 23 | 24 | import ( 25 | "dubbo.apache.org/dubbo-go/v3/protocol" 26 | "dubbo.apache.org/dubbo-go/v3/protocol/invocation" 27 | ) 28 | 29 | import ( 30 | "github.com/apache/dubbo-go-pixiu/pkg/model" 31 | ) 32 | 33 | // RpcContext the rpc invocation context 34 | type RpcContext struct { 35 | RpcInvocation *invocation.RPCInvocation 36 | RpcResult protocol.Result 37 | Route *model.RouteAction 38 | Ctx context.Context 39 | } 40 | 41 | // SetError set error in RpcResult 42 | func (c *RpcContext) SetError(err error) { 43 | if c.RpcResult == nil { 44 | c.RpcResult = &protocol.RPCResult{} 45 | } 46 | c.RpcResult.SetError(err) 47 | } 48 | 49 | // SetResult set successful result in RpcResult 50 | func (c *RpcContext) SetResult(result protocol.Result) { 51 | c.RpcResult = result 52 | } 53 | 54 | // SetInvocation set invocation 55 | func (c *RpcContext) SetInvocation(invocation *invocation.RPCInvocation) { 56 | c.RpcInvocation = invocation 57 | } 58 | 59 | // SetRoute set route 60 | func (c *RpcContext) SetRoute(route *model.RouteAction) { 61 | c.Route = route 62 | } 63 | 64 | func (c *RpcContext) GenerateHash() string { 65 | req := c.RpcInvocation 66 | return req.MethodName() + "." + req.Invoker().GetURL().String() 67 | } 68 | -------------------------------------------------------------------------------- /pkg/context/http/context_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package http 19 | -------------------------------------------------------------------------------- /pkg/context/mock/context.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package mock 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | "net/http" 24 | ) 25 | 26 | import ( 27 | contexthttp "github.com/apache/dubbo-go-pixiu/pkg/context/http" 28 | ) 29 | 30 | // GetMockHTTPContext mock context for test. 31 | func GetMockHTTPContext(r *http.Request) *contexthttp.HttpContext { 32 | result := &contexthttp.HttpContext{ 33 | Index: -1, 34 | Request: r, 35 | } 36 | 37 | w := mockWriter{header: map[string][]string{}} 38 | result.Writer = &w 39 | result.Reset() 40 | result.Ctx = context.Background() 41 | return result 42 | } 43 | 44 | type mockWriter struct { 45 | header http.Header 46 | } 47 | 48 | func (w *mockWriter) Header() http.Header { 49 | return w.header 50 | } 51 | 52 | func (w *mockWriter) Write(b []byte) (int, error) { 53 | fmt.Println(string(b)) 54 | return -1, nil 55 | } 56 | 57 | func (w *mockWriter) WriteHeader(statusCode int) { 58 | fmt.Println(statusCode) 59 | } 60 | -------------------------------------------------------------------------------- /pkg/filter/authority/authority_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package authority 19 | 20 | import ( 21 | "net/http" 22 | "testing" 23 | ) 24 | 25 | import ( 26 | "github.com/stretchr/testify/assert" 27 | ) 28 | 29 | import ( 30 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 31 | "github.com/apache/dubbo-go-pixiu/pkg/common/yaml" 32 | "github.com/apache/dubbo-go-pixiu/pkg/context/mock" 33 | ) 34 | 35 | func TestAuth(t *testing.T) { 36 | 37 | rules := AuthorityConfiguration{ 38 | []AuthorityRule{{Strategy: Blacklist, Items: append([]string{}, "127.0.0.1")}}, 39 | } 40 | //rules = []AuthorityRule{{Strategy: Whitelist, Items: append([]string{}, "127.0.0.1")}} 41 | p := Plugin{} 42 | authFilter, _ := p.CreateFilterFactory() 43 | config := authFilter.Config() 44 | mockYaml, err := yaml.MarshalYML(rules) 45 | assert.Nil(t, err) 46 | err = yaml.UnmarshalYML(mockYaml, config) 47 | assert.Nil(t, err) 48 | 49 | err = authFilter.Apply() 50 | assert.Nil(t, err) 51 | f := &Filter{cfg: &rules} 52 | 53 | request, _ := http.NewRequest("GET", "/", nil) 54 | ctx := mock.GetMockHTTPContext(request) 55 | filterStatus := f.Decode(ctx) 56 | assert.Equal(t, filterStatus, filter.Continue) 57 | } 58 | -------------------------------------------------------------------------------- /pkg/filter/failinject/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package failinject 19 | 20 | import ( 21 | "time" 22 | ) 23 | 24 | type URI string 25 | 26 | const ( 27 | TypeAbort = "abort" 28 | TypeDelay = "delay" 29 | 30 | TriggerTypeRandom = "random" 31 | TriggerTypeAlways = "always" 32 | TriggerTypePercentage = "percentage" 33 | ) 34 | 35 | type ( 36 | Config struct { 37 | Rules map[URI]*Rule `yaml:"fail_inject_rules" json:"fail_inject_rules"` 38 | } 39 | Rule struct { 40 | StatusCode int `yaml:"status_code" json:"status_code"` 41 | Body string `yaml:"body" json:"body"` 42 | Type string `yaml:"type" json:"type"` // abort, delay 43 | TriggerType string `yaml:"trigger_type" json:"trigger_type"` // random, always, percentage 44 | Odds int `yaml:"odds" json:"odds"` // 0-100 45 | Delay time.Duration `yaml:"delay" json:"delay"` 46 | } 47 | ) 48 | -------------------------------------------------------------------------------- /pkg/filter/header/header_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package header 19 | 20 | import ( 21 | "bytes" 22 | "net/http" 23 | "testing" 24 | ) 25 | 26 | import ( 27 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/api/config" 28 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/router" 29 | "github.com/stretchr/testify/assert" 30 | ) 31 | 32 | import ( 33 | "github.com/apache/dubbo-go-pixiu/pkg/context/mock" 34 | ) 35 | 36 | func TestHeader(t *testing.T) { 37 | p := Plugin{} 38 | 39 | filter, _ := p.CreateFilterFactory() 40 | err := filter.Apply() 41 | assert.Nil(t, err) 42 | 43 | api := router.API{ 44 | URLPattern: "/mock/:id/:name", 45 | Method: getMockMethod(config.MethodGet), 46 | Headers: map[string]string{}, 47 | } 48 | request, err := http.NewRequest("POST", "http://www.dubbogopixiu.com/mock/test?name=tc", bytes.NewReader([]byte("{\"id\":\"12345\"}"))) 49 | assert.NoError(t, err) 50 | c := mock.GetMockHTTPContext(request) 51 | c.API(api) 52 | 53 | request.Header.Set("filter", "test") 54 | api.Headers["filter"] = "test" 55 | c1 := mock.GetMockHTTPContext(request) 56 | c1.API(api) 57 | 58 | request.Header.Set("filter", "test1") 59 | c2 := mock.GetMockHTTPContext(request) 60 | c2.API(api) 61 | } 62 | 63 | func getMockMethod(verb config.HTTPVerb) config.Method { 64 | inbound := config.InboundRequest{} 65 | integration := config.IntegrationRequest{} 66 | return config.Method{ 67 | Enable: true, 68 | HTTPVerb: verb, 69 | InboundRequest: inbound, 70 | IntegrationRequest: integration, 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /pkg/filter/host/host.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package host 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 22 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 23 | contexthttp "github.com/apache/dubbo-go-pixiu/pkg/context/http" 24 | ) 25 | 26 | const ( 27 | // Kind is the kind of plugin. 28 | Kind = constant.HTTPHostFilter 29 | ) 30 | 31 | func init() { 32 | filter.RegisterHttpFilter(&Plugin{}) 33 | } 34 | 35 | type ( 36 | // Plugin is http filter plugin. 37 | Plugin struct { 38 | } 39 | // FilterFactory is http filter instance 40 | FilterFactory struct { 41 | cfg *Config 42 | } 43 | // Filter is http filter instance 44 | Filter struct { 45 | cfg *Config 46 | } 47 | // Config describe the config of FilterFactory 48 | Config struct { 49 | Host string `yaml:"host" json:"host"` 50 | } 51 | ) 52 | 53 | func (p *Plugin) Kind() string { 54 | return Kind 55 | } 56 | 57 | func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) { 58 | return &FilterFactory{}, nil 59 | } 60 | 61 | func (factory *FilterFactory) PrepareFilterChain(ctx *contexthttp.HttpContext, chain filter.FilterChain) error { 62 | f := &Filter{cfg: factory.cfg} 63 | chain.AppendDecodeFilters(f) 64 | return nil 65 | } 66 | 67 | func (f *Filter) Decode(c *contexthttp.HttpContext) filter.FilterStatus { 68 | c.Request.Host = f.cfg.Host 69 | return filter.Continue 70 | } 71 | func (factory *FilterFactory) Config() any { 72 | return factory.cfg 73 | } 74 | 75 | func (factory *FilterFactory) Apply() error { 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /pkg/filter/host/host_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package host 19 | 20 | import ( 21 | "bytes" 22 | "net/http" 23 | "testing" 24 | ) 25 | 26 | import ( 27 | "github.com/stretchr/testify/assert" 28 | ) 29 | 30 | import ( 31 | "github.com/apache/dubbo-go-pixiu/pkg/context/mock" 32 | ) 33 | 34 | func TestHost(t *testing.T) { 35 | targetHost := "www.dubbogo.com" 36 | cfg := &Config{ 37 | Host: targetHost, 38 | } 39 | request, err := http.NewRequest("POST", "http://www.dubbogopixiu.com/mock/test?name=tc", bytes.NewReader([]byte("{\"id\":\"12345\"}"))) 40 | assert.NoError(t, err) 41 | host := &Filter{cfg: cfg} 42 | assert.Nil(t, err) 43 | c := mock.GetMockHTTPContext(request) 44 | host.Decode(c) 45 | assert.Equal(t, targetHost, c.Request.Host) 46 | } 47 | -------------------------------------------------------------------------------- /pkg/filter/http/apiconfig/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package apiconfig 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | // ApiConfigConfig the config for api_config filter 25 | type ApiConfigConfig struct { 26 | APIMetaConfig *model.APIMetaConfig `yaml:"api_meta_config" json:"api_meta_config,omitempty"` 27 | Path string `yaml:"path" json:"path,omitempty"` 28 | Dynamic bool `yaml:"dynamic" json:"dynamic,omitempty"` 29 | DynamicAdapter string `yaml:"dynamic_adapter" json:"dynamic_adapter,omitempty"` 30 | } 31 | -------------------------------------------------------------------------------- /pkg/filter/http/grpcproxy/descriptor_operation.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package grpcproxy 19 | 20 | import ( 21 | "fmt" 22 | ) 23 | 24 | import ( 25 | "github.com/jhump/protoreflect/desc" 26 | ) 27 | 28 | func DescriptorSourceFromFileDescriptors(files ...*desc.FileDescriptor) (*fileSource, error) { 29 | fds := map[string]*desc.FileDescriptor{} 30 | for _, fd := range files { 31 | if err := addFile(fd, fds); err != nil { 32 | return nil, err 33 | } 34 | } 35 | return &fileSource{files: fds}, nil 36 | } 37 | 38 | func addFile(fd *desc.FileDescriptor, fds map[string]*desc.FileDescriptor) error { 39 | name := fd.GetName() 40 | if existing, ok := fds[name]; ok { 41 | // already added this file 42 | if existing != fd { 43 | // doh! duplicate files provided 44 | return fmt.Errorf("given files include multiple copies of %q", name) 45 | } 46 | return nil 47 | } 48 | fds[name] = fd 49 | for _, dep := range fd.GetDependencies() { 50 | if err := addFile(dep, fds); err != nil { 51 | return err 52 | } 53 | } 54 | return nil 55 | } 56 | 57 | func (fs *fileSource) GetAllFiles() ([]*desc.FileDescriptor, error) { 58 | files := make([]*desc.FileDescriptor, len(fs.files)) 59 | i := 0 60 | for _, fd := range fs.files { 61 | files[i] = fd 62 | i++ 63 | } 64 | return files, nil 65 | } 66 | -------------------------------------------------------------------------------- /pkg/filter/http/grpcproxy/invoke.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package grpcproxy 19 | 20 | import ( 21 | "context" 22 | ) 23 | 24 | import ( 25 | "github.com/golang/protobuf/proto" //nolint 26 | "github.com/jhump/protoreflect/desc" 27 | "github.com/jhump/protoreflect/dynamic/grpcdynamic" 28 | perrors "github.com/pkg/errors" 29 | "google.golang.org/grpc" 30 | ) 31 | 32 | func Invoke(ctx context.Context, stub grpcdynamic.Stub, mthDesc *desc.MethodDescriptor, grpcReq proto.Message, opts ...grpc.CallOption) (proto.Message, error) { 33 | var resp proto.Message 34 | var err error 35 | // Bi-direction Stream 36 | if mthDesc.IsServerStreaming() && mthDesc.IsClientStreaming() { 37 | err = perrors.New("currently not support bi-direction stream") 38 | } else if mthDesc.IsClientStreaming() { 39 | err = perrors.New("currently not support client side stream") 40 | } else if mthDesc.IsServerStreaming() { 41 | err = perrors.New("currently not support server side stream") 42 | } else { 43 | resp, err = invokeUnary(ctx, stub, mthDesc, grpcReq, opts...) 44 | } 45 | 46 | return resp, err 47 | } 48 | 49 | func invokeUnary(ctx context.Context, stub grpcdynamic.Stub, mthDesc *desc.MethodDescriptor, grpcReq proto.Message, opts ...grpc.CallOption) (proto.Message, error) { 50 | return stub.InvokeRpc(ctx, mthDesc, grpcReq, opts...) 51 | } 52 | -------------------------------------------------------------------------------- /pkg/filter/http/proxyrewrite/rewrite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package proxyrewrite 19 | 20 | import ( 21 | "net/http" 22 | "testing" 23 | ) 24 | 25 | import ( 26 | "github.com/go-playground/assert/v2" 27 | ) 28 | 29 | import ( 30 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 31 | "github.com/apache/dubbo-go-pixiu/pkg/context/mock" 32 | ) 33 | 34 | func TestDecode(t *testing.T) { 35 | url := "/user-service/query" 36 | 37 | request, _ := http.NewRequest("Get", url, nil) 38 | ctx := mock.GetMockHTTPContext(request) 39 | 40 | factory := &FilterFactory{cfg: &Config{UriRegex: []string{"^/([^/]*)/(.*)$", "/$2"}}} 41 | chain := filter.NewDefaultFilterChain() 42 | _ = factory.PrepareFilterChain(ctx, chain) 43 | chain.OnDecode(ctx) 44 | 45 | assert.Equal(t, ctx.GetUrl(), "/query") 46 | } 47 | 48 | func TestConfigUpdate(t *testing.T) { 49 | url := "/user-service/query" 50 | 51 | request, _ := http.NewRequest("Get", url, nil) 52 | ctx := mock.GetMockHTTPContext(request) 53 | 54 | cfg := &Config{UriRegex: []string{"^/([^/]*)/(.*)$", "/$2"}} 55 | 56 | factory := &FilterFactory{cfg: cfg} 57 | chain := filter.NewDefaultFilterChain() 58 | _ = factory.PrepareFilterChain(ctx, chain) 59 | 60 | cfg.UriRegex = []string{} 61 | 62 | chain.OnDecode(ctx) 63 | 64 | assert.Equal(t, ctx.GetUrl(), "/query") 65 | } 66 | -------------------------------------------------------------------------------- /pkg/filter/http/proxywasm/filter_windows.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package proxywasm 21 | 22 | import ( 23 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 24 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 25 | "github.com/apache/dubbo-go-pixiu/pkg/context/http" 26 | "github.com/apache/dubbo-go-pixiu/pkg/logger" 27 | ) 28 | 29 | func init() { 30 | filter.RegisterHttpFilter(&Plugin{}) 31 | } 32 | 33 | type ( 34 | Plugin struct { 35 | } 36 | 37 | WasmFilterFactory struct { 38 | cfg *Config 39 | } 40 | 41 | WasmFilter struct { 42 | } 43 | 44 | Config struct { 45 | } 46 | ) 47 | 48 | func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus { 49 | return filter.Continue 50 | } 51 | 52 | func (w *WasmFilter) Encode(ctx *http.HttpContext) filter.FilterStatus { 53 | return filter.Continue 54 | } 55 | 56 | func (factory *WasmFilterFactory) Config() any { 57 | return factory.cfg 58 | } 59 | 60 | func (factory *WasmFilterFactory) Apply() error { 61 | return nil 62 | } 63 | 64 | func (factory *WasmFilterFactory) PrepareFilterChain(ctx *http.HttpContext, chain filter.FilterChain) error { 65 | logger.Warnf("Wasm not support on windows now") 66 | return nil 67 | } 68 | 69 | func (p *Plugin) Kind() string { 70 | return constant.HTTPWasmFilter 71 | } 72 | 73 | func (p *Plugin) CreateFilterFactory() (filter.HttpFilterFactory, error) { 74 | return &WasmFilterFactory{ 75 | cfg: &Config{}, 76 | }, nil 77 | } 78 | -------------------------------------------------------------------------------- /pkg/filter/metric/metric_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package metric 19 | 20 | import ( 21 | "bytes" 22 | "net/http" 23 | "testing" 24 | ) 25 | 26 | import ( 27 | "github.com/stretchr/testify/assert" 28 | ) 29 | 30 | import ( 31 | "github.com/apache/dubbo-go-pixiu/pkg/context/mock" 32 | ) 33 | 34 | func TestMetric(t *testing.T) { 35 | filter := &Filter{} 36 | err := registerOtelMetric() 37 | if err != nil { 38 | t.Fatal(err) 39 | return 40 | } 41 | 42 | request, err := http.NewRequest("POST", "http://www.dubbogopixiu.com/mock/test?name=tc", bytes.NewReader([]byte("{\"id\":\"12345\"}"))) 43 | assert.NoError(t, err) 44 | c := mock.GetMockHTTPContext(request) 45 | filter.Decode(c) 46 | filter.Encode(c) 47 | t.Log("log filter test is finished") 48 | } 49 | -------------------------------------------------------------------------------- /pkg/filter/network/dubboproxy/dubbofiltermanager.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package dubboproxy 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 22 | "github.com/apache/dubbo-go-pixiu/pkg/common/yaml" 23 | "github.com/apache/dubbo-go-pixiu/pkg/logger" 24 | "github.com/apache/dubbo-go-pixiu/pkg/model" 25 | ) 26 | 27 | // DubboFilterManager manage filters 28 | type DubboFilterManager struct { 29 | filterConfigs []*model.DubboFilter 30 | filters []filter.DubboFilter 31 | } 32 | 33 | // NewDubboFilterManager create filter manager 34 | func NewDubboFilterManager(fs []*model.DubboFilter) *DubboFilterManager { 35 | filters := createDubboFilter(fs) 36 | fm := &DubboFilterManager{filterConfigs: fs, filters: filters} 37 | return fm 38 | } 39 | 40 | func createDubboFilter(fs []*model.DubboFilter) []filter.DubboFilter { 41 | var filters []filter.DubboFilter 42 | 43 | for _, f := range fs { 44 | p, err := filter.GetDubboFilterPlugin(f.Name) 45 | if err != nil { 46 | logger.Error("createDubboFilter %s getNetworkFilterPlugin error %s", f.Name, err) 47 | continue 48 | } 49 | 50 | config := p.Config() 51 | if err := yaml.ParseConfig(config, f.Config); err != nil { 52 | logger.Error("createDubboFilter %s parse config error %s", f.Name, err) 53 | continue 54 | } 55 | 56 | filter, err := p.CreateFilter(config) 57 | if err != nil { 58 | logger.Error("createDubboFilter %s createFilter error %s", f.Name, err) 59 | continue 60 | } 61 | filters = append(filters, filter) 62 | } 63 | return filters 64 | } 65 | -------------------------------------------------------------------------------- /pkg/filter/network/dubboproxy/plugin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package dubboproxy 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 22 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 23 | "github.com/apache/dubbo-go-pixiu/pkg/common/util/stringutil" 24 | "github.com/apache/dubbo-go-pixiu/pkg/model" 25 | ) 26 | 27 | const ( 28 | Kind = constant.DubboConnectManagerFilter 29 | ) 30 | 31 | func init() { 32 | filter.RegisterNetworkFilterPlugin(&Plugin{}) 33 | } 34 | 35 | type ( 36 | // Plugin the dubbo networkfilter plugin 37 | Plugin struct{} 38 | ) 39 | 40 | // Kind kind 41 | func (p *Plugin) Kind() string { 42 | return Kind 43 | } 44 | 45 | // CreateFilter create dubbo networkfilter 46 | func (p *Plugin) CreateFilter(config any) (filter.NetworkFilter, error) { 47 | hcmc, ok := config.(*model.DubboProxyConnectionManagerConfig) 48 | hcmc.Timeout = stringutil.ResolveTimeStr2Time(hcmc.TimeoutStr, constant.DefaultReqTimeout) 49 | if !ok { 50 | panic("CreateFilter occur some exception for the type is not suitable one.") 51 | } 52 | return CreateDubboProxyConnectionManager(hcmc), nil 53 | } 54 | 55 | // Config return DubboProxyConnectionManagerConfig 56 | func (p *Plugin) Config() any { 57 | return &model.DubboProxyConnectionManagerConfig{} 58 | } 59 | -------------------------------------------------------------------------------- /pkg/filter/network/grpcconnectionmanager/plugin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package grpcconnectionmanager 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 22 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 23 | "github.com/apache/dubbo-go-pixiu/pkg/common/grpc" 24 | "github.com/apache/dubbo-go-pixiu/pkg/common/util/stringutil" 25 | "github.com/apache/dubbo-go-pixiu/pkg/model" 26 | ) 27 | 28 | const ( 29 | Kind = constant.GRPCConnectManagerFilter 30 | ) 31 | 32 | func init() { 33 | filter.RegisterNetworkFilterPlugin(&Plugin{}) 34 | } 35 | 36 | type ( 37 | Plugin struct{} 38 | ) 39 | 40 | // Kind kind 41 | func (p *Plugin) Kind() string { 42 | return Kind 43 | } 44 | 45 | // CreateFilter create grpc network filter 46 | func (p *Plugin) CreateFilter(config any) (filter.NetworkFilter, error) { 47 | hcmc := config.(*model.GRPCConnectionManagerConfig) 48 | hcmc.Timeout = stringutil.ResolveTimeStr2Time(hcmc.TimeoutStr, constant.DefaultReqTimeout) 49 | return grpc.CreateGrpcConnectionManager(hcmc), nil 50 | } 51 | 52 | // Config return GRPCConnectionManagerConfig 53 | func (p *Plugin) Config() any { 54 | return &model.GRPCConnectionManagerConfig{} 55 | } 56 | -------------------------------------------------------------------------------- /pkg/filter/network/httpconnectionmanager/plugin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package httpconnectionmanager 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 22 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 23 | "github.com/apache/dubbo-go-pixiu/pkg/common/http" 24 | "github.com/apache/dubbo-go-pixiu/pkg/common/util/stringutil" 25 | "github.com/apache/dubbo-go-pixiu/pkg/model" 26 | ) 27 | 28 | const ( 29 | Kind = constant.HTTPConnectManagerFilter 30 | ) 31 | 32 | func init() { 33 | filter.RegisterNetworkFilterPlugin(&Plugin{}) 34 | } 35 | 36 | type ( 37 | Plugin struct{} 38 | ) 39 | 40 | // Kind 41 | func (p *Plugin) Kind() string { 42 | return Kind 43 | } 44 | 45 | // CreateFilter create http network filter 46 | func (p *Plugin) CreateFilter(config any) (filter.NetworkFilter, error) { 47 | hcmc := config.(*model.HttpConnectionManagerConfig) 48 | hcmc.Timeout = stringutil.ResolveTimeStr2Time(hcmc.TimeoutStr, constant.DefaultReqTimeout) 49 | return http.CreateHttpConnectionManager(hcmc), nil 50 | } 51 | 52 | // Config return HttpConnectionManagerConfig 53 | func (p *Plugin) Config() any { 54 | return &model.HttpConnectionManagerConfig{} 55 | } 56 | -------------------------------------------------------------------------------- /pkg/filter/prometheus/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package prometheus 19 | 20 | type ( 21 | MetricCollectConfiguration struct { 22 | Rules MetricCollectRule `yaml:"metric_collect_rules" json:"metric_collect_rules"` 23 | } 24 | 25 | MetricCollectRule struct { 26 | MetricPath string `json:"metric_path,omitempty" yaml:"metric_path,omitempty"` 27 | // Push Gateway URL in format http://domain:port 28 | // where JOBNAME can be any string of your choice 29 | PushGatewayURL string `default:"http://127.0.0.1:9091" json:"push_gateway_url,omitempty" yaml:"push_gateway_url,omitempty"` 30 | CounterPush bool `json:"counter_push,omitempty" yaml:"counter_push,omitempty"` 31 | PushIntervalThreshold int `json:"push_interval_threshold" yaml:"push_interval_threshold,omitempty"` 32 | PushJobName string `json:"push_job_name,omitempty" yaml:"push_job_name,omitempty"` 33 | } 34 | ) 35 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package sentinel 19 | 20 | const ( 21 | EXACT MatchStrategy = iota 22 | REGEX 23 | AntPath 24 | ) 25 | 26 | type ( 27 | // Resource API group for rate sentinel, all API in group is considered to be the same resource 28 | Resource struct { 29 | ID int64 `json:"id,omitempty" yaml:"id,omitempty"` 30 | Name string `json:"name,omitempty" yaml:"name,omitempty"` 31 | Items []*Item `json:"items" yaml:"items"` 32 | } 33 | 34 | // Item API item for group 35 | Item struct { 36 | MatchStrategy MatchStrategy `json:"matchStrategy,omitempty" yaml:"matchStrategy,omitempty"` 37 | Pattern string `json:"pattern,omitempty" yaml:"pattern"` 38 | } 39 | 40 | // MatchStrategy API match strategy 41 | MatchStrategy int32 42 | ) 43 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/exact.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package sentinel 19 | 20 | import ( 21 | "sync" 22 | ) 23 | 24 | type Exact struct { 25 | apiNames map[string]string 26 | 27 | mu sync.RWMutex 28 | } 29 | 30 | func (p *Exact) load(apis []*Resource) { 31 | m := make(map[string]string, len(apis)) 32 | 33 | for _, api := range apis { 34 | apiName := api.Name 35 | for _, item := range api.Items { 36 | if item.MatchStrategy == EXACT { 37 | m[item.Pattern] = apiName 38 | } 39 | } 40 | } 41 | 42 | p.mu.Lock() 43 | defer p.mu.Unlock() 44 | p.apiNames = m 45 | } 46 | 47 | func (p *Exact) match(path string) (string, bool) { 48 | p.mu.RLock() 49 | defer p.mu.RUnlock() 50 | 51 | resourceName, ok := p.apiNames[path] 52 | return resourceName, ok 53 | } 54 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/logger_warpper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package sentinel 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/logger" 22 | ) 23 | 24 | // loggerWrapper 25 | type loggerWrapper struct { 26 | } 27 | 28 | // GetWrappedLogger 29 | func GetWrappedLogger() loggerWrapper { 30 | return loggerWrapper{} 31 | } 32 | 33 | func (l loggerWrapper) Debug(msg string, keysAndValues ...any) { 34 | logger.Debugf(msg, keysAndValues...) 35 | } 36 | 37 | func (l loggerWrapper) Info(msg string, keysAndValues ...any) { 38 | logger.Infof(msg, keysAndValues...) 39 | } 40 | 41 | func (l loggerWrapper) Warn(msg string, keysAndValues ...any) { 42 | logger.Warnf(msg, keysAndValues...) 43 | } 44 | 45 | func (l loggerWrapper) Error(err error, msg string, keysAndValues ...any) { 46 | logger.Warnf(msg, err, keysAndValues) 47 | } 48 | 49 | // InfoEnabled todo logger should implements this method 50 | func (l loggerWrapper) InfoEnabled() bool { 51 | return true 52 | } 53 | 54 | func (l loggerWrapper) ErrorEnabled() bool { 55 | return true 56 | } 57 | 58 | func (l loggerWrapper) DebugEnabled() bool { 59 | return true 60 | } 61 | 62 | func (l loggerWrapper) WarnEnabled() bool { 63 | return true 64 | } 65 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/matcher.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package sentinel 19 | 20 | type ( 21 | //PathMatcher according the url path find APIResource name 22 | PathMatcher interface { 23 | load(apis []*Resource) 24 | 25 | match(path string) (string, bool) 26 | } 27 | 28 | Matcher struct { 29 | matchers []PathMatcher 30 | } 31 | ) 32 | 33 | func NewMatcher() *Matcher { 34 | return &Matcher{ 35 | matchers: []PathMatcher{ 36 | &Exact{}, 37 | &Regex{}, 38 | }, 39 | } 40 | } 41 | 42 | // Load load api resource for matchers 43 | func (m *Matcher) Load(apis []*Resource) { 44 | for _, v := range m.matchers { 45 | v.load(apis) 46 | } 47 | } 48 | 49 | // Match match resource via url path 50 | func (m *Matcher) Match(path string) (string, bool) { 51 | for _, matchers := range m.matchers { 52 | if res, ok := matchers.match(path); ok { 53 | return res, ok 54 | } 55 | } 56 | return "", false 57 | } 58 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/ratelimit/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ratelimit 19 | 20 | import ( 21 | "github.com/alibaba/sentinel-golang/core/flow" 22 | ) 23 | 24 | import ( 25 | pkgs "github.com/apache/dubbo-go-pixiu/pkg/filter/sentinel" 26 | ) 27 | 28 | type ( 29 | // Config rate limit config 30 | Config struct { 31 | Resources []*pkgs.Resource `json:"resources,omitempty" yaml:"resources,omitempty"` 32 | Rules []*Rule `json:"rules,omitempty" yaml:"rules,omitempty"` 33 | LogPath string `json:"logPath,omitempty" yaml:"logPath,omitempty"` 34 | } 35 | 36 | // Rule api group 's rate-limit rule 37 | Rule struct { 38 | ID int64 `json:"id,omitempty" yaml:"id,omitempty"` 39 | FlowRule flow.Rule `json:"flowRule,omitempty" yaml:"flowRule,omitempty"` 40 | Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"` 41 | } 42 | ) 43 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/ratelimit/mock.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ratelimit 19 | 20 | import ( 21 | "github.com/alibaba/sentinel-golang/core/flow" 22 | ) 23 | 24 | import ( 25 | pkgs "github.com/apache/dubbo-go-pixiu/pkg/filter/sentinel" 26 | ) 27 | 28 | func GetMockedRateLimitConfig() *Config { 29 | c := Config{ 30 | Resources: []*pkgs.Resource{ 31 | { 32 | Name: "test-dubbo", 33 | Items: []*pkgs.Item{ 34 | {MatchStrategy: pkgs.EXACT, Pattern: "/api/v1/test-dubbo/user"}, 35 | {MatchStrategy: pkgs.REGEX, Pattern: "/api/v1/test-dubbo/user/*"}, 36 | }, 37 | }, 38 | { 39 | Name: "test-http", 40 | Items: []*pkgs.Item{ 41 | {MatchStrategy: pkgs.EXACT, Pattern: "/api/v1/http/foo"}, 42 | {MatchStrategy: pkgs.EXACT, Pattern: "/api/v1/http/bar"}, 43 | 44 | {MatchStrategy: pkgs.REGEX, Pattern: "/api/v1/http/foo/*"}, 45 | {MatchStrategy: pkgs.REGEX, Pattern: "/api/v1/http/bar/*"}, 46 | }, 47 | }, 48 | }, 49 | Rules: []*Rule{ 50 | { 51 | Enable: true, 52 | FlowRule: flow.Rule{ 53 | Threshold: 100, 54 | StatIntervalInMs: 1000, 55 | }, 56 | }, 57 | }, 58 | } 59 | return &c 60 | } 61 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/ratelimit/rate_limit_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ratelimit 19 | 20 | import ( 21 | "bytes" 22 | stdHttp "net/http" 23 | "testing" 24 | ) 25 | 26 | import ( 27 | "github.com/stretchr/testify/assert" 28 | ) 29 | 30 | import ( 31 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter" 32 | "github.com/apache/dubbo-go-pixiu/pkg/common/yaml" 33 | "github.com/apache/dubbo-go-pixiu/pkg/context/mock" 34 | ) 35 | 36 | func TestFilter(t *testing.T) { 37 | f := &FilterFactory{conf: &Config{}} 38 | 39 | mockYaml, err := yaml.MarshalYML(mockConfig()) 40 | assert.Nil(t, err) 41 | 42 | assert.Nil(t, yaml.UnmarshalYML(mockYaml, f.Config())) 43 | 44 | assert.Nil(t, f.Apply()) 45 | 46 | decoder := &Filter{conf: f.conf, matcher: f.matcher} 47 | 48 | request, _ := stdHttp.NewRequest("POST", "http://www.dubbogopixiu.com/mock/test?name=tc", bytes.NewReader([]byte("{\"id\":\"12345\"}"))) 49 | c := mock.GetMockHTTPContext(request) 50 | status := decoder.Decode(c) 51 | assert.Equal(t, status, filter.Continue) 52 | } 53 | -------------------------------------------------------------------------------- /pkg/filter/sentinel/regex.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package sentinel 19 | 20 | import ( 21 | "regexp" 22 | "sync" 23 | ) 24 | 25 | type Regex struct { 26 | apiNames map[string]string 27 | 28 | mu sync.RWMutex 29 | } 30 | 31 | func (p *Regex) load(apis []*Resource) { 32 | m := make(map[string]string, len(apis)) 33 | 34 | for _, api := range apis { 35 | apiName := api.Name 36 | for _, item := range api.Items { 37 | if item.MatchStrategy == REGEX { 38 | m[item.Pattern] = apiName 39 | } 40 | } 41 | } 42 | 43 | p.mu.Lock() 44 | defer p.mu.Unlock() 45 | p.apiNames = m 46 | } 47 | 48 | func (p *Regex) match(path string) (string, bool) { 49 | p.mu.RLock() 50 | defer p.mu.RUnlock() 51 | 52 | for k, v := range p.apiNames { 53 | matched, _ := regexp.MatchString(k, path) 54 | if matched { 55 | return v, true 56 | } 57 | } 58 | return "", false 59 | } 60 | -------------------------------------------------------------------------------- /pkg/filter/traffic/models.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package traffic 19 | 20 | import ( 21 | "net/http" 22 | ) 23 | 24 | func spiltHeader(req *http.Request, value string) bool { 25 | return req.Header.Get(string(canaryByHeader)) == value 26 | } 27 | 28 | func spiltWeight(weight, floor, ceil int) bool { 29 | return weight > floor && weight <= ceil 30 | } 31 | -------------------------------------------------------------------------------- /pkg/listener/tcp/pkg_handler.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package tcp 19 | 20 | import ( 21 | "github.com/apache/dubbo-getty" 22 | ) 23 | 24 | type PackageHandler struct { 25 | ls *TcpListenerService 26 | } 27 | 28 | func NewPackageHandler(ls *TcpListenerService) *PackageHandler { 29 | return &PackageHandler{ls} 30 | } 31 | 32 | func (h *PackageHandler) Read(ss getty.Session, data []byte) (any, int, error) { 33 | return h.ls.FilterChain.OnDecode(data) 34 | } 35 | 36 | func (h *PackageHandler) Write(ss getty.Session, p any) ([]byte, error) { 37 | return h.ls.FilterChain.OnEncode(p) 38 | } 39 | -------------------------------------------------------------------------------- /pkg/logger/log.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | level: "debug" 20 | development: true 21 | disableCaller: false 22 | disableStacktrace: false 23 | sampling: 24 | encoding: "console" 25 | 26 | # encoder 27 | encoderConfig: 28 | messageKey: "message" 29 | levelKey: "level" 30 | timeKey: "time" 31 | nameKey: "logger" 32 | callerKey: "caller" 33 | stacktraceKey: "stacktrace" 34 | lineEnding: "" 35 | levelEncoder: "capitalColor" 36 | timeEncoder: "iso8601" 37 | durationEncoder: "seconds" 38 | callerEncoder: "short" 39 | nameEncoder: "" 40 | 41 | outputPaths: 42 | - "stderr" 43 | errorOutputPaths: 44 | - "stderr" 45 | initialFields: 46 | -------------------------------------------------------------------------------- /pkg/logger/output.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package logger 19 | 20 | func Info(args ...any) { 21 | control.info(args...) 22 | } 23 | 24 | func Warn(args ...any) { 25 | control.warn(args...) 26 | } 27 | 28 | func Error(args ...any) { 29 | control.error(args...) 30 | } 31 | 32 | func Debug(args ...any) { 33 | control.debug(args...) 34 | } 35 | 36 | func Infof(fmt string, args ...any) { 37 | control.infof(fmt, args...) 38 | } 39 | 40 | func Warnf(fmt string, args ...any) { 41 | control.warnf(fmt, args...) 42 | } 43 | 44 | func Errorf(fmt string, args ...any) { 45 | control.errorf(fmt, args...) 46 | } 47 | 48 | func Debugf(fmt string, args ...any) { 49 | control.debugf(fmt, args...) 50 | } 51 | -------------------------------------------------------------------------------- /pkg/logger/triple.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package logger 19 | 20 | // TripleLogger does not add user-defined log fields, so there will be no pointer 21 | // reference issues after updates, ensuring that all references are under control. 22 | type TripleLogger struct { 23 | } 24 | 25 | func GetTripleLogger() *TripleLogger { 26 | return &TripleLogger{} 27 | } 28 | 29 | func (l *TripleLogger) Info(args ...any) { 30 | control.info(args...) 31 | } 32 | 33 | func (l *TripleLogger) Warn(args ...any) { 34 | control.warn(args...) 35 | } 36 | 37 | func (l *TripleLogger) Error(args ...any) { 38 | control.error(args...) 39 | } 40 | 41 | func (l *TripleLogger) Debug(args ...any) { 42 | control.debug(args...) 43 | } 44 | 45 | func (l *TripleLogger) Infof(fmt string, args ...any) { 46 | control.infof(fmt, args...) 47 | } 48 | 49 | func (l *TripleLogger) Warnf(fmt string, args ...any) { 50 | control.warnf(fmt, args...) 51 | } 52 | 53 | func (l *TripleLogger) Errorf(fmt string, args ...any) { 54 | control.errorf(fmt, args...) 55 | } 56 | 57 | func (l *TripleLogger) Debugf(fmt string, args ...any) { 58 | control.debugf(fmt, args...) 59 | } 60 | -------------------------------------------------------------------------------- /pkg/model/adapter.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // Adapter the adapter plugin for manage cluster or router 21 | type Adapter struct { 22 | ID string `yaml:"id" json:"id"` 23 | Name string `yaml:"name" json:"name"` // Name the adapter unique name 24 | Enabled string `yaml:"enabled" json:"enabled" default:"true"` 25 | Config map[string]any `yaml:"config" json:"config" mapstructure:"config"` // Config adapter config 26 | } 27 | -------------------------------------------------------------------------------- /pkg/model/filter.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // FilterChain filter chain 21 | type FilterChain struct { 22 | Filters []NetworkFilter `yaml:"filters" json:"filters" mapstructure:"filters"` 23 | } 24 | 25 | // NetworkFilter core struct, filter is extend by user 26 | type NetworkFilter struct { 27 | Name string `yaml:"name" json:"name" mapstructure:"name"` // Name filter name unique 28 | Config map[string]any `yaml:"config" json:"config" mapstructure:"config"` // Config filter config 29 | } 30 | 31 | // FilterChainMatch 32 | type FilterChainMatch struct { 33 | Domains []string `yaml:"domains" json:"domains" mapstructure:"domains"` 34 | } 35 | -------------------------------------------------------------------------------- /pkg/model/lb.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // LbPolicyType the load balance policy enum 21 | type LbPolicyType string 22 | 23 | const ( 24 | LoadBalancerRand LbPolicyType = "Rand" 25 | LoadBalancerRoundRobin LbPolicyType = "RoundRobin" 26 | LoadBalancerRingHashing LbPolicyType = "RingHashing" 27 | LoadBalancerMaglevHashing LbPolicyType = "MaglevHashing" 28 | LoadBalancerWeightRandom LbPolicyType = "WeightRandom" 29 | ) 30 | 31 | var LbPolicyTypeValue = map[string]LbPolicyType{ 32 | "Rand": LoadBalancerRand, 33 | "RoundRobin": LoadBalancerRoundRobin, 34 | "RingHashing": LoadBalancerRingHashing, 35 | "MaglevHashing": LoadBalancerMaglevHashing, 36 | "WeightRandom": LoadBalancerWeightRandom, 37 | } 38 | 39 | type LbPolicy interface { 40 | GenerateHash() string 41 | } 42 | 43 | // LbConsistentHash supports consistent hash load balancing 44 | type LbConsistentHash interface { 45 | Hash(key string) uint32 46 | Add(host string) 47 | Get(key string) (string, error) 48 | GetHash(key uint32) (string, error) 49 | Remove(host string) bool 50 | } 51 | 52 | type ConsistentHashInitFunc = func(ConsistentHash, []*Endpoint) LbConsistentHash 53 | 54 | // ConsistentHashInitMap stores the Init functions for consistent hash load balancing 55 | var ConsistentHashInitMap = map[LbPolicyType]ConsistentHashInitFunc{} 56 | -------------------------------------------------------------------------------- /pkg/model/listener.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | const ( 21 | ProtocolTypeHTTP ProtocolType = 0 + iota // support for 1.0 22 | ProtocolTypeTCP 23 | ProtocolTypeUDP 24 | ProtocolTypeHTTPS 25 | ProtocolTypeGRPC 26 | ProtocolTypeHTTP2 27 | ProtocolTypeTriple 28 | ) 29 | 30 | const ( 31 | REST_VALUE = "REST" 32 | GRPC_VALUE = "GRPC" 33 | DUBBO_VALUE = "DUBBO" 34 | ISTIOGRPC_VALUE = "ISTIO" 35 | ) 36 | 37 | var ( 38 | // ProtocolTypeName enum seq to protocol type name 39 | ProtocolTypeName = map[int32]string{ 40 | 0: "HTTP", 41 | 1: "TCP", 42 | 2: "UDP", 43 | 3: "HTTPS", 44 | 4: "GRPC", 45 | 5: "HTTP2", 46 | 6: "TRIPLE", 47 | } 48 | 49 | // ProtocolTypeValue protocol type name to enum seq 50 | ProtocolTypeValue = map[string]int32{ 51 | "HTTP": 0, 52 | "TCP": 1, 53 | "UDP": 2, 54 | "HTTPS": 3, 55 | "GRPC": 4, 56 | "HTTP2": 5, 57 | "TRIPLE": 6, 58 | } 59 | ) 60 | 61 | type ( 62 | // ProtocolType protocol type enum 63 | ProtocolType int32 64 | 65 | // Listener is a server, listener a port 66 | Listener struct { 67 | Name string `yaml:"name" json:"name" mapstructure:"name"` 68 | Address Address `yaml:"address" json:"address" mapstructure:"address"` 69 | ProtocolStr string `default:"http" yaml:"protocol_type" json:"protocol_type" mapstructure:"protocol_type"` 70 | Protocol ProtocolType `default:"http" yaml:"omitempty" json:"omitempty"` 71 | FilterChain FilterChain `yaml:"filter_chains" json:"filter_chains" mapstructure:"filter_chains"` 72 | Config any `yaml:"config" json:"config" mapstructure:"config"` 73 | } 74 | ) 75 | -------------------------------------------------------------------------------- /pkg/model/llmprovider.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | providers: 21 | deepseek: 22 | name: DeepSeek 23 | description: DeepSeek uses advanced llms to improve search accuracy and relevance, seamlessly integrating AI into existing search systems for smarter information retrieval across various fields. 24 | base_url: api.deepseek.com 25 | endpoints: 26 | chatComplete: /chat/completions 27 | openai: 28 | name: OpenAI 29 | description: OpenAI is an AI research and deployment company. Their mission is to ensure that artificial general intelligence benefits all of humanity. 30 | base_url: api.openai.com/v1 31 | endpoints: 32 | chatComplete: /chat/completions 33 | dashscope: 34 | name: Dashscope 35 | description: Alibaba Cloud's Tongyi Generative AI Platform (BaiLian) offers official APIs for the Tongyi series of large models. This high-performance, cost-effective model service helps you focus on business innovation, freeing you from the burden of technical operations and maintenance. 36 | base_url: dashscope.aliyuncs.com/compatible-mode/v1 37 | endpoints: 38 | chatComplete: /chat/completions -------------------------------------------------------------------------------- /pkg/model/match.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | const ( 21 | Exact MatcherType = 0 + iota 22 | Prefix 23 | Suffix 24 | Regex 25 | ) 26 | 27 | var ( 28 | MatcherTypeName = map[int32]string{ 29 | 0: "Exact", 30 | 1: "Prefix", 31 | 2: "Suffix", 32 | 3: "Regex", 33 | } 34 | 35 | MatcherTypeValue = map[string]int32{ 36 | "Exact": 0, 37 | "Prefix": 1, 38 | "Suffix": 2, 39 | "Regex": 3, 40 | } 41 | ) 42 | 43 | type ( 44 | // StringMatcher matcher string 45 | StringMatcher struct { 46 | Matcher MatcherType 47 | } 48 | 49 | // MatcherType matcher type 50 | MatcherType int32 51 | ) 52 | 53 | // Match 54 | func (sm *StringMatcher) Match() (bool, error) { 55 | return true, nil 56 | } 57 | -------------------------------------------------------------------------------- /pkg/model/metric.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // Metirc config for otel metric. 21 | type Metric struct { 22 | Enable bool `yaml:"enable" json:"enable"` 23 | PrometheusPort int `yaml:"prometheus_port" json:"prometheus_port"` 24 | } 25 | -------------------------------------------------------------------------------- /pkg/model/pprof.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | type PprofConf struct { 21 | Enable bool `yaml:"enable" json:"enable" mapstructure:"enable" default:"false"` 22 | Address Address `yaml:"address" json:"address" mapstructure:"address"` 23 | } 24 | -------------------------------------------------------------------------------- /pkg/model/remote.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // RemoteConfig remote server info which offer server discovery or k/v or distribution function 21 | type RemoteConfig struct { 22 | Protocol string `yaml:"protocol" json:"protocol" default:"zookeeper"` 23 | Timeout string `yaml:"timeout" json:"timeout" default:"10s"` 24 | Address string `yaml:"address" json:"address"` 25 | Username string `yaml:"username" json:"username"` 26 | Password string `yaml:"password" json:"password"` 27 | Group string `yaml:"group" json:"group"` 28 | Root string `yaml:"root" json:"root" default:"/services"` 29 | } 30 | -------------------------------------------------------------------------------- /pkg/model/trace.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // TracerConfig inclueds detail information about the exporter 21 | type TracerConfig struct { 22 | Name string `yaml:"name" json:"name" mapstructure:"name"` 23 | ServiceName string `yaml:"serviceName" json:"serviceName" mapstructure:"serviceName"` 24 | Sampler Sampler `yaml:"sampler" json:"sampler" mapstructure:"sampler"` 25 | Config map[string]any `yaml:"config" json:"config" mapstructure:"config"` 26 | } 27 | 28 | // Sampler policy 29 | type Sampler struct { 30 | Type string `yaml:"type" json:"type" mapstructure:"type"` 31 | Param float64 `yaml:"param" json:"param" mapstructure:"param"` 32 | } 33 | -------------------------------------------------------------------------------- /pkg/model/tracing.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // Tracing 21 | type Tracing struct { 22 | Http Http `yaml:"http" json:"http,omitempty"` 23 | URL string `yaml:"url" json:"url,omitempty"` 24 | Type string `yaml:"type" json:"type,omitempty"` 25 | } 26 | 27 | // Tracing 28 | type Http struct { 29 | Name string `yaml:"name"` 30 | Config any `yaml:"config"` 31 | } 32 | -------------------------------------------------------------------------------- /pkg/model/wasm.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package model 19 | 20 | // WasmConfig contains all services' config. 21 | type WasmConfig struct { 22 | Services []WasmService `yaml:"services" json:"services" mapstructure:"services"` 23 | } 24 | 25 | // WasmService includes all information about the specific application. 26 | type WasmService struct { 27 | Name string `yaml:"name" json:"name" mapstructure:"name"` 28 | Config map[string]any `yaml:"config" json:"config" mapstructure:"config"` 29 | } 30 | -------------------------------------------------------------------------------- /pkg/pluginregistry/proxywasm_register.go: -------------------------------------------------------------------------------- 1 | //go:build wasm 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package pluginregistry 21 | 22 | import ( 23 | _ "github.com/apache/dubbo-go-pixiu/pkg/filter/http/proxywasm" 24 | ) 25 | -------------------------------------------------------------------------------- /pkg/router/api.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package router 19 | 20 | import ( 21 | "net/url" 22 | "strings" 23 | ) 24 | 25 | import ( 26 | "github.com/dubbo-go-pixiu/pixiu-api/pkg/router" 27 | ) 28 | 29 | import ( 30 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 31 | ) 32 | 33 | // GetURIParams returns the values retrieved from the rawURL 34 | func GetURIParams(api *router.API, rawURL url.URL) url.Values { 35 | return wildcardMatch(api.URLPattern, rawURL.Path) 36 | } 37 | 38 | // IsWildCardBackendPath checks whether the configured path of 39 | // the upstream restful service contains parameters 40 | func IsWildCardBackendPath(api *router.API) bool { 41 | if len(api.IntegrationRequest.Path) == 0 { 42 | return false 43 | } 44 | return strings.Contains(api.IntegrationRequest.Path, constant.PathParamIdentifier) 45 | } 46 | -------------------------------------------------------------------------------- /pkg/server/adapter_manager_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package server 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | import ( 25 | "github.com/stretchr/testify/assert" 26 | ) 27 | 28 | import ( 29 | "github.com/apache/dubbo-go-pixiu/pkg/common/extension/adapter" 30 | "github.com/apache/dubbo-go-pixiu/pkg/model" 31 | ) 32 | 33 | type ( 34 | DemoAdapterPlugin struct{} 35 | 36 | DemoAdapter struct { 37 | cfg *Config 38 | } 39 | 40 | Config struct { 41 | Name string `yaml:"name" json:"name,omitempty"` 42 | } 43 | ) 44 | 45 | func (d *DemoAdapterPlugin) Kind() string { 46 | return "test" 47 | } 48 | 49 | func (d *DemoAdapterPlugin) CreateAdapter(ad *model.Adapter) (adapter.Adapter, error) { 50 | return &DemoAdapter{cfg: &Config{}}, nil 51 | } 52 | 53 | func (a *DemoAdapter) Start() { 54 | 55 | } 56 | 57 | // Apply init 58 | func (a *DemoAdapter) Apply() error { 59 | return nil 60 | } 61 | 62 | // Config get config for Adapter 63 | func (a *DemoAdapter) Config() any { 64 | return a.cfg 65 | } 66 | 67 | func (a *DemoAdapter) Stop() { 68 | 69 | } 70 | 71 | func TestAdapterManager(t *testing.T) { 72 | adapter.RegisterAdapterPlugin(&DemoAdapterPlugin{}) 73 | 74 | bs := &model.Bootstrap{ 75 | StaticResources: model.StaticResources{ 76 | Adapters: []*model.Adapter{ 77 | { 78 | Name: "test", 79 | Config: make(map[string]any), 80 | }, 81 | }, 82 | }, 83 | } 84 | 85 | am := CreateDefaultAdapterManager(nil, bs) 86 | 87 | assert.Equal(t, len(am.adapters), 1) 88 | 89 | am.Start() 90 | 91 | am.Stop() 92 | 93 | } 94 | -------------------------------------------------------------------------------- /pkg/server/cluster_manager_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package server 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | import ( 25 | "github.com/stretchr/testify/assert" 26 | ) 27 | 28 | import ( 29 | "github.com/apache/dubbo-go-pixiu/pkg/model" 30 | ) 31 | 32 | func TestClusterManager(t *testing.T) { 33 | bs := &model.Bootstrap{ 34 | StaticResources: model.StaticResources{ 35 | Clusters: []*model.ClusterConfig{ 36 | { 37 | Name: "test", 38 | Endpoints: []*model.Endpoint{ 39 | { 40 | Address: model.SocketAddress{}, 41 | ID: "1", 42 | }, 43 | }, 44 | }, 45 | }, 46 | }, 47 | } 48 | 49 | cm := CreateDefaultClusterManager(bs) 50 | assert.Equal(t, len(cm.store.Config), 1) 51 | 52 | cm.AddCluster(&model.ClusterConfig{ 53 | Name: "test2", 54 | Endpoints: []*model.Endpoint{ 55 | { 56 | Address: model.SocketAddress{}, 57 | ID: "1", 58 | }, 59 | }, 60 | }) 61 | 62 | assert.Equal(t, len(cm.store.Config), 2) 63 | 64 | cm.SetEndpoint("test2", &model.Endpoint{ 65 | Address: model.SocketAddress{}, 66 | ID: "2", 67 | }) 68 | assert.Equal(t, cm.PickEndpoint("test", nil).ID, "1") 69 | cm.DeleteEndpoint("test2", "1") 70 | } 71 | -------------------------------------------------------------------------------- /pkg/server/controls/controls.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package controls 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | type ( 25 | ClusterManager interface { 26 | RemoveCluster(names []string) 27 | HasCluster(name string) bool 28 | UpdateCluster(cluster *model.ClusterConfig) 29 | AddCluster(cluster *model.ClusterConfig) 30 | CloneXdsControlStore() (ClusterStore, error) 31 | } 32 | 33 | ListenerManager interface { 34 | AddListener(m *model.Listener) error 35 | UpdateListener(m *model.Listener) error 36 | RemoveListener(names []string) 37 | HasListener(name string) bool 38 | CloneXdsControlListener() ([]*model.Listener, error) 39 | } 40 | 41 | DynamicResourceManager interface { 42 | GetLds() *model.ApiConfigSource 43 | GetCds() *model.ApiConfigSource 44 | GetNode() *model.Node 45 | } 46 | 47 | ClusterStore interface { 48 | Config() []*model.ClusterConfig 49 | HasCluster(name string) bool 50 | } 51 | ) 52 | -------------------------------------------------------------------------------- /pkg/server/http.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package server 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/common/constant" 22 | "github.com/apache/dubbo-go-pixiu/pkg/common/router/trie" 23 | "github.com/apache/dubbo-go-pixiu/pkg/model" 24 | ) 25 | 26 | // DefaultHttpConnectionManager 27 | func DefaultHttpConnectionManager() *model.HttpConnectionManagerConfig { 28 | return &model.HttpConnectionManagerConfig{ 29 | RouteConfig: model.RouteConfiguration{ 30 | RouteTrie: trie.NewTrieWithDefault("/api/v1/**", model.RouteAction{ 31 | Cluster: constant.HeaderValueAll, 32 | }), 33 | }, 34 | HTTPFilters: []*model.HTTPFilter{ 35 | { 36 | Name: constant.HTTPProxyFilter, 37 | }, 38 | }, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pkg/server/otel.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package server 19 | 20 | import ( 21 | "net/http" 22 | "strconv" 23 | ) 24 | 25 | import ( 26 | sdkprometheus "github.com/prometheus/client_golang/prometheus" 27 | "github.com/prometheus/client_golang/prometheus/promhttp" 28 | "go.opentelemetry.io/otel/exporters/prometheus" 29 | "go.opentelemetry.io/otel/metric/global" 30 | "go.opentelemetry.io/otel/sdk/metric" 31 | ) 32 | 33 | import ( 34 | "github.com/apache/dubbo-go-pixiu/pkg/logger" 35 | "github.com/apache/dubbo-go-pixiu/pkg/model" 36 | ) 37 | 38 | func registerOtelMetricMeter(conf model.Metric) { 39 | if conf.Enable { 40 | exporter := prometheus.New() 41 | provider := metric.NewMeterProvider(metric.WithReader(exporter)) 42 | 43 | registry := sdkprometheus.NewRegistry() 44 | err := registry.Register(exporter.Collector) 45 | if err != nil { 46 | logger.Errorf("register otel metric meter failed, err: %v", err) 47 | return 48 | } 49 | 50 | global.SetMeterProvider(provider) 51 | 52 | http.Handle("/", promhttp.HandlerFor(registry, promhttp.HandlerOpts{})) 53 | addr := ":" + strconv.Itoa(conf.PrometheusPort) 54 | go func() { 55 | logger.Info("Prometheus server running on " + addr) 56 | _ = http.ListenAndServe(addr, nil) 57 | }() 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pkg/tracing/api.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package tracing 19 | 20 | import ( 21 | "go.opentelemetry.io/otel/trace" 22 | ) 23 | 24 | // Trace interface need to be implemented to construct your Tracer. 25 | type Trace interface { 26 | trace.Tracer 27 | } 28 | -------------------------------------------------------------------------------- /pkg/tracing/http.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package tracing 19 | 20 | import ( 21 | "go.opentelemetry.io/otel/trace" 22 | ) 23 | 24 | // Wrap the tracer provided by otel and be asked to implement the Trace interface 25 | // to customize the Span implementation. 26 | type Tracer struct { 27 | Trace trace.Tracer 28 | } 29 | -------------------------------------------------------------------------------- /pkg/tracing/jaeger/jaeger.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package jaeger 19 | 20 | import ( 21 | "github.com/mitchellh/mapstructure" 22 | "github.com/pkg/errors" 23 | "go.opentelemetry.io/otel/exporters/jaeger" 24 | sdktrace "go.opentelemetry.io/otel/sdk/trace" 25 | ) 26 | 27 | import ( 28 | "github.com/apache/dubbo-go-pixiu/pkg/model" 29 | ) 30 | 31 | type jaegerConfig struct { 32 | Url string `yaml:"url" json:"url" mapstructure:"url"` 33 | } 34 | 35 | func NewJaegerExporter(cfg *model.TracerConfig) (sdktrace.SpanExporter, error) { 36 | var config jaegerConfig 37 | if err := mapstructure.Decode(cfg.Config, &config); err != nil { 38 | return nil, errors.Wrap(err, "config error") 39 | } 40 | exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(config.Url))) 41 | return exp, err 42 | } 43 | -------------------------------------------------------------------------------- /pkg/tracing/otlp/otlp.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package otlp 19 | 20 | import ( 21 | "context" 22 | ) 23 | 24 | import ( 25 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace" 26 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" 27 | sdktrace "go.opentelemetry.io/otel/sdk/trace" 28 | ) 29 | 30 | import ( 31 | "github.com/apache/dubbo-go-pixiu/pkg/model" 32 | ) 33 | 34 | func NewOTLPExporter(ctx context.Context, cfg *model.TracerConfig) (sdktrace.SpanExporter, error) { 35 | client := otlptracehttp.NewClient() 36 | return otlptrace.New(ctx, client) 37 | } 38 | -------------------------------------------------------------------------------- /pkg/tracing/trace_manager.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package tracing 19 | 20 | import ( 21 | "github.com/apache/dubbo-go-pixiu/pkg/model" 22 | ) 23 | 24 | // TraceDriverManager Driver maintains all tracers and the provider. 25 | type TraceDriverManager struct { 26 | driver *TraceDriver 27 | bootstrap *model.Bootstrap 28 | } 29 | 30 | func CreateDefaultTraceDriverManager(bs *model.Bootstrap) *TraceDriverManager { 31 | manager := &TraceDriverManager{ 32 | bootstrap: bs, 33 | } 34 | manager.driver = InitDriver(bs) 35 | return manager 36 | } 37 | 38 | func (manager *TraceDriverManager) GetDriver() *TraceDriver { 39 | return manager.driver 40 | } 41 | -------------------------------------------------------------------------------- /pkg/wasm/key.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package wasm 19 | 20 | const ( 21 | LogLevel = "wasm.log" 22 | HeaderLevel = "wasm.header" 23 | ) 24 | 25 | var keys = []string{LogLevel, HeaderLevel} 26 | 27 | func contains(key string) bool { 28 | for i := range keys { 29 | if key == keys[i] { 30 | return true 31 | } 32 | } 33 | return false 34 | } 35 | -------------------------------------------------------------------------------- /start_integrate_test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | #!/bin/bash 18 | 19 | set -e 20 | set -x 21 | 22 | echo 'start integrate-test' 23 | 24 | # set root workspace 25 | ROOT_DIR=$(pwd) 26 | echo "integrate-test root work-space -> ${ROOT_DIR}" 27 | 28 | # show all github-env 29 | echo "github current commit id -> $2" 30 | echo "github pull request branch -> ${GITHUB_REF}" 31 | echo "github pull request slug -> ${GITHUB_REPOSITORY}" 32 | echo "github pull request repo slug -> ${GITHUB_REPOSITORY}" 33 | echo "github pull request actor -> ${GITHUB_ACTOR}" 34 | echo "github pull request repo param -> $1" 35 | echo "github pull request base branch -> $3" 36 | echo "github pull request head branch -> ${GITHUB_HEAD_REF}" 37 | 38 | echo "use dubbo-go-samples $3 branch for integration testing" 39 | git clone -b main https://github.com/apache/dubbo-go-pixiu-samples.git integrate_samples && cd integrate_samples 40 | 41 | # update dubbo-go to current commit id 42 | go mod edit -replace=github.com/apache/dubbo-go-pixiu=github.com/"$1"@"$2" 43 | 44 | #grep -rl "github.com/apache/dubbo-go-pixiu/pkg" | xargs sed -i 's/github.com\/apache\/dubbo-go-pixiu\/pkg\//github.com\/apache\/dubbo-go-pixiu\/pixiu\/pkg\//g' 45 | 46 | # prepare dependency 47 | go mod tidy 48 | 49 | # start integrate test 50 | ./start_integrate_test.sh 51 | --------------------------------------------------------------------------------