Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter spec suggest #1590

Closed
XiaoWeiKIN opened this issue Nov 16, 2021 · 1 comment
Closed

filter spec suggest #1590

XiaoWeiKIN opened this issue Nov 16, 2021 · 1 comment

Comments

@XiaoWeiKIN
Copy link
Contributor

Filter 编写规范

注意:

  1. extension.get(xxx),为 lazy 初始化。
  2. extension.get(xxx),要保证单例。

模板:

var (
	once   sync.Once 
	// 变量尽量简短有含义
	active *activeFilter 
)

func init() {
    // extension.SetFilter() 必须 set 保证单例的私有化构造函数
    // 禁止直接 set 一个 func
	extension.SetFilter(constant.ActiveFilterKey, newActiveFilter)
}

// filter struct 应该为私有化,所有filter获取必须通过 extension.get(),禁止外部实例化
// filter 名称应当为: 他的作用 + Filter
// 对于同时作用于 provider 和 consumser的应该命名为:他的作用 + side + Filter
// 禁止直接命名为 Filter 这种毫无含义的结构体
type activeFilter struct{}

func newActiveFilter() filter.Filter {
	if active == nil {
	   // 虽然 extension.get(xx) 为 only read 但是建议增加once保护.
		once.Do(func() {
			active = &activeFilter{}
		})
	}
	return active
}
  1. extension.SetFilter() 必须 set 保证单例的私有化构造函数, 禁止直接 set 一个 func().

    反例:没有保证单例

    extension.SetFilter(constant.ActiveFilterKey, func() filter.Filter {
    		return &Filter{}
    	}))
  2. 不推荐直接命名为 Filter 这种毫无含义的结构体,Filter 名称应当为: 他的作用 + Filter。对于同时作用于 provider 和 consumser的应该命名为:他的作用 + side + Filter。

  3. Filter struct 应该为私有化,所有 Filter 获取必须通过 extension.get(),禁止外部直接实例化 Filter。

  4. 虽然 extension.get(xx) 为 only read 但是实例化时建议增加 once 保护.

@XiaoWeiKIN
Copy link
Contributor Author

func (paf *ProviderAuthFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
	logger.Infof("invoking providerAuth filter.")
	url := invoker.GetURL()

禁止在 filter.invoke 方法内,打印毫无意义的日志。如果要打印,建议设置为 debug。

@XiaoWeiKIN XiaoWeiKIN changed the title filter specifications suggest filter spec suggest Nov 16, 2021
LaurenceLiZhixin pushed a commit that referenced this issue Nov 19, 2021
* filter single instance

* filter single instance

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
AlexStocks added a commit that referenced this issue Dec 1, 2021
* feat: try to support dubbo

* Merge 3.0 to master (#1606)

* build(deps): bump github.com/hashicorp/vault/sdk from 0.2.1 to 0.3.0 (#1552)

Bumps [github.com/hashicorp/vault/sdk](https://github.com/hashicorp/vault) from 0.2.1 to 0.3.0.
- [Release notes](https://github.com/hashicorp/vault/releases)
- [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md)
- [Commits](hashicorp/vault@sdk/v0.2.1...v0.3.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/vault/sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* delete useless codes (#1551)

* Update CHANGELOG.md

* [#1559]: adjust the startup process of the configuration center (#1560)

* [#1559]:
1. fix the startup process of the configuration center(remove error log)
2. refactor zk registry listener

* delete redundant dynamic configuration center cache

Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>

* [#1276]modify the name of the receiver to a single character (#1561)

Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>

* style(common): rename constants in camel-case style (#1563)

* style(common): rename constants in camel-case style

* style(common): rename Ttl to TTL

* fix: #1558: Set root config to global ptr in Init() function. (#1564)

* fix: #1558

* fix: change the api to start the app by config-api

* fix: in the Consumer service, the Reference config property ‘check’ use the Consumer config when omitted

* Triple upgrade to grpc (#1566)

* fix: init triple grpc

* fix: delete replace

* Fix: upgrade triple grpc

* Fix: remove unused file

* Fix decrease grpc go version to 1.14

* Fix: add server side serialization

* register not use metadata configuration.

* build(deps): bump github.com/go-resty/resty/v2 from 2.3.0 to 2.7.0 (#1579)

Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.3.0 to 2.7.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](go-resty/resty@v2.3.0...v2.7.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump google.golang.org/grpc from 1.41.0 to 1.42.0 (#1578)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.41.0 to 1.42.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.41.0...v1.42.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/knadh/koanf from 1.3.0 to 1.3.2 (#1577)

Bumps [github.com/knadh/koanf](https://github.com/knadh/koanf) from 1.3.0 to 1.3.2.
- [Release notes](https://github.com/knadh/koanf/releases)
- [Commits](knadh/koanf@v1.3.0...v1.3.2)

---
updated-dependencies:
- dependency-name: github.com/knadh/koanf
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: registry param

* fix: fix ns and group

* fix: integrate test

* Fix: integrate test

* fix: url fmt

* fix: nacos servicediscovery group

* Fix: enhance zk

* start application (#1571)

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: LaurenceLiZhixin <382673304@qq.com>

* graceful shutdwon filter (#1585)

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>

* Fix: some bugs and features for 3.0 (#1586)

* fix: some bugs

* Fix: remove file\k8s registry, k8s remote

* refactor listenDirEvent
1. remove CLEAR label;
2. remove register/unregister logic for watch children;
3. reorder the zk dynamic configuration code
4. adapt the gost

* hessian encode attachments return error (#1588)

* upgrade gost dependency version

* upgrade hessian to v1.9.5 (#1595)

* build(deps): bump k8s.io/apimachinery from 0.16.9 to 0.22.4 (#1600)

Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.16.9 to 0.22.4.
- [Release notes](https://github.com/kubernetes/apimachinery/releases)
- [Commits](kubernetes/apimachinery@v0.16.9...v0.22.4)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ftr: triple tracing (#1596)

* ftr: triple tracing

* fix: if-else to switch

* [fix #1590] filter single instance (#1591)

* filter single instance

* filter single instance

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>

* Ftr/triple reflect support (#1603)

* ftr: triple-reflection

* fix: comment and var name

* Fix: comment typo

* Fix: official website

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: Mulavar <978007503@qq.com>
Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>
Co-authored-by: Xuewei Niu <a@nxw.name>
Co-authored-by: PhilYue <phil.yue@foxmail.com>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: sanxun0325 <bbz17640380550@163.com>
Co-authored-by: Xuewei Niu <justxuewei@apache.org>
Co-authored-by: zhaoyunxing <zhaoyunxing@apache.org>
Co-authored-by: wangxw <2484713618@qq.com>
Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: 望哥 <gelnyang@163.com>

* feat: support polaris

* feat: support polarismesh registry

* fix: fix cr issue

* chore: run go mod tidy to fix ci-error

* refactor: change polaris::ConsumerAPI.GetInstances => GetAllInstances

* fix github action scan error

* fix: fix go fmt error

* fix: import formatter

* fix: fix cr issue

* fix: fix code-style check error

* fix: fix cr issue

* fix: fix maybe nil error

* fix: fix lose event bug

* style: fix code style

Co-authored-by: springliao <springliao@tencent.com>
Co-authored-by: Laurence <45508533+LaurenceLiZhixin@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: Mulavar <978007503@qq.com>
Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>
Co-authored-by: Xuewei Niu <a@nxw.name>
Co-authored-by: PhilYue <phil.yue@foxmail.com>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: sanxun0325 <bbz17640380550@163.com>
Co-authored-by: Xuewei Niu <justxuewei@apache.org>
Co-authored-by: zhaoyunxing <zhaoyunxing@apache.org>
Co-authored-by: wangxw <2484713618@qq.com>
Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: 望哥 <gelnyang@163.com>
Co-authored-by: LaurenceLiZhixin <382673304@qq.com>
AlexStocks added a commit that referenced this issue Dec 21, 2021
* Merge 3.0 to master (#1606)

* build(deps): bump github.com/hashicorp/vault/sdk from 0.2.1 to 0.3.0 (#1552)

Bumps [github.com/hashicorp/vault/sdk](https://github.com/hashicorp/vault) from 0.2.1 to 0.3.0.
- [Release notes](https://github.com/hashicorp/vault/releases)
- [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md)
- [Commits](hashicorp/vault@sdk/v0.2.1...v0.3.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/vault/sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* delete useless codes (#1551)

* Update CHANGELOG.md

* [#1559]: adjust the startup process of the configuration center (#1560)

* [#1559]:
1. fix the startup process of the configuration center(remove error log)
2. refactor zk registry listener

* delete redundant dynamic configuration center cache

Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>

* [#1276]modify the name of the receiver to a single character (#1561)

Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>

* style(common): rename constants in camel-case style (#1563)

* style(common): rename constants in camel-case style

* style(common): rename Ttl to TTL

* fix: #1558: Set root config to global ptr in Init() function. (#1564)

* fix: #1558

* fix: change the api to start the app by config-api

* fix: in the Consumer service, the Reference config property ‘check’ use the Consumer config when omitted

* Triple upgrade to grpc (#1566)

* fix: init triple grpc

* fix: delete replace

* Fix: upgrade triple grpc

* Fix: remove unused file

* Fix decrease grpc go version to 1.14

* Fix: add server side serialization

* register not use metadata configuration.

* build(deps): bump github.com/go-resty/resty/v2 from 2.3.0 to 2.7.0 (#1579)

Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.3.0 to 2.7.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](go-resty/resty@v2.3.0...v2.7.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump google.golang.org/grpc from 1.41.0 to 1.42.0 (#1578)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.41.0 to 1.42.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.41.0...v1.42.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/knadh/koanf from 1.3.0 to 1.3.2 (#1577)

Bumps [github.com/knadh/koanf](https://github.com/knadh/koanf) from 1.3.0 to 1.3.2.
- [Release notes](https://github.com/knadh/koanf/releases)
- [Commits](knadh/koanf@v1.3.0...v1.3.2)

---
updated-dependencies:
- dependency-name: github.com/knadh/koanf
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: registry param

* fix: fix ns and group

* fix: integrate test

* Fix: integrate test

* fix: url fmt

* fix: nacos servicediscovery group

* Fix: enhance zk

* start application (#1571)

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: LaurenceLiZhixin <382673304@qq.com>

* graceful shutdwon filter (#1585)

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>

* Fix: some bugs and features for 3.0 (#1586)

* fix: some bugs

* Fix: remove file\k8s registry, k8s remote

* refactor listenDirEvent
1. remove CLEAR label;
2. remove register/unregister logic for watch children;
3. reorder the zk dynamic configuration code
4. adapt the gost

* hessian encode attachments return error (#1588)

* upgrade gost dependency version

* upgrade hessian to v1.9.5 (#1595)

* build(deps): bump k8s.io/apimachinery from 0.16.9 to 0.22.4 (#1600)

Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.16.9 to 0.22.4.
- [Release notes](https://github.com/kubernetes/apimachinery/releases)
- [Commits](kubernetes/apimachinery@v0.16.9...v0.22.4)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ftr: triple tracing (#1596)

* ftr: triple tracing

* fix: if-else to switch

* [fix #1590] filter single instance (#1591)

* filter single instance

* filter single instance

Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>

* Ftr/triple reflect support (#1603)

* ftr: triple-reflection

* fix: comment and var name

* Fix: comment typo

* Fix: official website

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: Mulavar <978007503@qq.com>
Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>
Co-authored-by: Xuewei Niu <a@nxw.name>
Co-authored-by: PhilYue <phil.yue@foxmail.com>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: sanxun0325 <bbz17640380550@163.com>
Co-authored-by: Xuewei Niu <justxuewei@apache.org>
Co-authored-by: zhaoyunxing <zhaoyunxing@apache.org>
Co-authored-by: wangxw <2484713618@qq.com>
Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: 望哥 <gelnyang@163.com>

* fix unexported bug (#1634)

* Revert "fix unexported bug (#1634)" (#1635)

This reverts commit 5604ba5.

* add OPay logo to user list

Co-authored-by: Laurence <45508533+LaurenceLiZhixin@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Co-authored-by: Mulavar <978007503@qq.com>
Co-authored-by: dongjianhui03 <dongjianhui03@meituan.com>
Co-authored-by: Xuewei Niu <a@nxw.name>
Co-authored-by: PhilYue <phil.yue@foxmail.com>
Co-authored-by: lizhixin.lzx <lizhixin.lzx@alibaba-inc.com>
Co-authored-by: sanxun0325 <bbz17640380550@163.com>
Co-authored-by: Xuewei Niu <justxuewei@apache.org>
Co-authored-by: zhaoyunxing <zhaoyunxing@apache.org>
Co-authored-by: wangxw <2484713618@qq.com>
Co-authored-by: wangxiaowei14227 <wangxiaowei14227@autohome.com.cn>
Co-authored-by: 望哥 <gelnyang@163.com>
Co-authored-by: 刘月财 <38887641+luky116@users.noreply.github.com>
Co-authored-by: AlexStocks <alexstocks@foxmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant