写点什么

What's new in dubbo-go-pixiu v0.6.0

作者:apache/dubbo-go
  • 2023-03-04
    北京
  • 本文字数:4902 字

    阅读完需:约 16 分钟

pixiu 0.6.0 虽然艰辛,但在社区小伙伴的努力下发布了。这个版本不止有常规社区功能,还有很多功能特性是来源于 ASoC-2022 Alibaba Summer of Code,OSPP(中科院软件所[开源软件供应链点亮计划]) , GSoC(Google Summer of Code) 提案内容。

New Features In v0.6.0

nacos config

背景:pixiu 的配置,启动配置项(conf.yaml),日志配置(log.yml)均是从本地文件加载,没有接入动态配置中心的能力,而日常生产环境中,配置通过配置中心集中下发管理是更为灵活和安全的方式之一。


动态配置下发的场景还有很多扩展,接入的组件也因公司的选型有所不同,当前我们主要考虑接入 nacos 配置中心。


注:在设计上可以考虑,如何在二次开发场景下更为“标准、安全、简单”的接入其他配置中心。


Pixiu 启动时从配置中心 Nacos 拉取配置 conf.yaml 数据





pixiu.conf 的配置不用配置 static_resources,需要配置 config-center 和 nacos:


config-center:  type: nacos  enable: truenacos:  server-configs:    - ip_addr: "127.0.0.1"      port: 8848  client-config:    username: nacos    password: nacos
复制代码


原来我们熟悉 pixiu.conf 配置内容放到了 nacos 中:


static_resources:  listeners:    - name: "net/http"      protocol_type: "HTTP"      address:        socket_address:          address: "0.0.0.0"          port: 8881      filter_chains:          filters:            - name: dgp.filter.httpconnectionmanager              config:                route_config:                  routes:                    - match:                        prefix: "*"                http_filters:                  - name: dgp.filter.http.dubboproxy                    config:                      dubboProxyConfig:                        auto_resolve: true                        registries:                          "zookeeper":                            protocol: "zookeeper"                            timeout: "3s"                            address: "127.0.0.1:2181"                            username: ""                            password: ""                        timeout_config:                          connect_timeout: 5s                          request_timeout: 5s
server_name: "test_http_dubbo" generate_request_id: false config: idle_timeout: 5s read_timeout: 5s write_timeout: 5s shutdown_config: timeout: "60s" step_timeout: "10s" reject_policy: "immediacy"
复制代码


更详细的配置参考 samples: https://github.com/apache/dubbo-go-pixiu-samples/tree/main/dubbogo/simple/farconfnacos


nacos 配置支持还需要进一步完善的功能:


  • 动态托管/下发用户自定义配置

  • 动态下发 Pixiu 配置

OSPP: Traffic Distribution

流量分发提供两种策略,基于 Request Header 和服务权重的流量切分。

canary-by-header

canary-by-header 是要匹配的 Request Header 的值,当 Request Header 设置此值时,它将被路由到相应的 cluster(cluster 中绑定 canary-by-header 键值)。当请求不包含这一 Request Header 或 Header 值不匹配时,请求不会被发送到 Canary 版本,该策略适用于蓝绿发布以及 A/B 测试


canary-weight

这种策略适用于金丝雀部署,权重范围 0 - 100 按百分比将请求路由到指定的服务。权重为 0 意味着该金丝雀规则不会向 Canary 服务发送任何请求;权重为 100 意味着所有请求都将被发送到 Canary。


Add Graceful Shutdown

通过 graceful shutdown 能力,在进程获得系统型号:SIGINT, SIGKILL, SIGTERM 信号时执行 graceful shutdown 过程:拒绝新的请求;等待处理中请求完成直到 timeout.


static_resources:  .......  .......  shutdown_config:    timeout: "60s"    step_timeout: "10s"    reject_policy: "immediacy"
复制代码


配置方式参考: https://github.com/apache/dubbo-go-pixiu-samples/tree/main/shutdown

WASM Plugin for Pixiu

Pixiu 支持 WASM 插件机制,实现 http fitler。



PIxiu 与 WASM 扩展代码交互采取 Proxy-Wasm 规范,该规范是开源社区针对「网络代理场景」设计的一套 ABI 规范,采用该规范能让 PIxiu 复用社区既有的 WASM 扩展。


WASM 原则上应该支持多种语言,这里以 Go 语言为例,最终通过 tinygo 编译成 wasm 文件。如果要实现我们的扩展 WASM 程序,需要按以下模版进行编码实现:


package main
import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types")
func main() { proxywasm.SetNewHttpContext(newHttpContext)}
type myHttpContext struct { // you must embed the default context so that you need not to re-implement all the methods by yourself proxywasm.DefaultHttpContext contextID uint32}
func newHttpContext(rootContextID, contextID uint32) proxywasm.HttpContext { return &myHttpContext{contextID: contextID}}
// overridefunc (ctx *myHttpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
return types.ActionContinue}
复制代码

deploy pixiu as dubbo service ingress gateway in k8s istio

当 dubbo 部署 istio + k8s 环境中,pixiu 可以作为 dubbo provider 的 ingress gateway,接收 dubbo/triple/http 的流量,并将请求转发到 dubbo provider 中。



samples: https://github.com/apache/dubbo-go-pixiu-samples/tree/main/xds/dubbo-go-istio

ASoC 2022: Pixiu Metrics Implementation

Pixiu Metrics 提供四个 prometheus 运行指标:


var reqCnt = &Metric{  ID:          "reqCnt",  Name:        "requests_total",  Description: "How many HTTP requests processed, partitioned by status code and HTTP method.",  Type:        "counter_vec",  Args:        []string{"code", "method", "host", "url"},}
var reqDur = &Metric{ ID: "reqDur", Name: "request_duration_seconds", Description: "The HTTP request latencies in seconds.", Args: []string{"code", "method", "url"}, Type: "histogram_vec", Buckets: reqDurBuckets,}
var resSz = &Metric{ ID: "resSz", Name: "response_size_bytes", Description: "The HTTP response sizes in bytes.", Args: []string{"code", "method", "url"}, Type: "histogram_vec", Buckets: resSzBuckets,}
var reqSz = &Metric{ ID: "reqSz", Name: "request_size_bytes", Description: "The HTTP request sizes in bytes.", Args: []string{"code", "method", "url"}, Type: "histogram_vec", Buckets: reqSzBuckets,}
var standardMetrics = []*Metric{ reqCnt, reqDur, resSz, reqSz,}
复制代码


config 配置 http_filters: dgp.filter.http.prometheusmetric:


static_resources:  listeners:    - name: "net/http"      protocol_type: "HTTP"      address:        socket_address:          address: "0.0.0.0"          port: 8888      filter_chains:        filters:          - name: dgp.filter.httpconnectionmanager            config:              route_config:                routes:                  - match:                      prefix: /health                    route:                      cluster: user                      cluster_not_found_response_code: 505                  - match:                      prefix: /user                    route:                      cluster: user                      cluster_not_found_response_code: 505                  - match:                      prefix: /prefix                    route:                      cluster: user                      cluster_not_found_response_code: 505              http_filters:                - name: dgp.filter.http.prometheusmetric                  metric_collect_rules:                    metric_path: "/metrics"                    push_gateway_url: "http://127.0.0.1:9091"                    counter_push: true                    push_interval_threshold: 3                    push_job_name: "prometheus"                - name: dgp.filter.http.httpproxy                          config:        idle_timeout: 5s        read_timeout: 5s        write_timeout: 5s  clusters:    - name: "user"      lb_policy: "lb"      endpoints:        - id: 1          socket_address:            address: 127.0.0.1            port: 1314      health_checks:        - protocol: "tcp"          timeout: 1s          interval: 2s          healthy_threshold: 4          unhealthy_threshold: 4  shutdown_config:    timeout: "60s"    step_timeout: "10s"    reject_policy: "immediacy"
复制代码


sample 参考: https://github.com/apache/dubbo-go-pixiu-samples/tree/main/dubbogo/simple/prometheus

feat:consistent hashing

为 cluster 提供基于一致性 hash 的请求负载算法;


clusters:  - name: "test_dubbo"    lb_policy: "ConsistentHashing"    registries:      "zookeeper":        timeout: "3s"        address: "127.0.0.1:2181"        username: ""        password: ""
复制代码

Enhancement in v0.6.0

Remove "Types" on Http to dubbo proxy

在通过 http 调用 dubbo 服务的场景中,v0.6.0 以前版本需要再请求中包含"types": ...., 来描述 dubbo parameters 的结构描述,示例 :{"types":"string"....


func TestPost1(t *testing.T) {    url := "http://localhost:8883/UserService/com.dubbogo.pixiu.UserService/GetUserByName"    data := "{"types":"string","values":"tc"}"    client := &http.Client{Timeout: 5 * time.Second}    req, err := http.NewRequest("POST", url, strings.NewReader(data))    req.Header.Set("x-dubbo-http1.1-dubbo-version", "1.0.0")    req.Header.Set("x-dubbo-service-protocol", "dubbo")    req.Header.Set("x-dubbo-service-version", "1.0.0")    req.Header.Set("x-dubbo-service-group", "test")    assert.NoError(t, err)    req.Header.Add("Content-Type", "application/json")    resp, err := client.Do(req)    assert.NoError(t, err)    assert.NotNil(t, resp)    assert.Equal(t, 200, resp.StatusCode)    s, _ := ioutil.ReadAll(resp.Body)    assert.True(t, strings.Contains(string(s), "0001"))}
复制代码


改进之后 data 中不需要 types 数据。



sample 代码: https://github.com/apache/dubbo-go-pixiu-samples/blob/main/dubbogo/simple/direct/test/pixiu_test.go

ASoC 2002: Optimization of Pixiu timeout feature

dgp.filter.http.dubboproxy 支持超时配置:


...................- name: dgp.filter.http.dubboproxy  config:    dubboProxyConfig:      registries:        "zookeeper":          protocol: "zookeeper"          timeout: "3s"          address: "127.0.0.1:2181"          username: ""          password: ""      timeout_config:        connect_timeout: 5s        request_timeout: 5s
复制代码


欢迎钉钉扫码加入 dubbogo 社区钉钉群【钉钉群号 23331795】进行交流。



发布于: 刚刚阅读数: 4
用户头像

dubbogo社区 2019-08-25 加入

dubbogo社区官方账号,发布 github.com/apache/dubbo-go 各种最新技术趋势、项目实战和最新版本特性等技术干货。

评论

发布
暂无评论
What's new in dubbo-go-pixiu v0.6.0_dubbo_apache/dubbo-go_InfoQ写作社区