feat(otel): Metrics basic components and metrics collection for TCP - #89
Open
guowei-gong wants to merge 1 commit into
Open
feat(otel): Metrics basic components and metrics collection for TCP#89guowei-gong wants to merge 1 commit into
guowei-gong wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @dobyte ,我这次 PR 的主旨是为 due 提供可插拔、遵守 otel 规范的 metrics 指标监控能力,默认不开启,开启方式是在配置文件中新增。
使用示例
开启指标采集需要配置两处 enable 开关,这样做的目的如下。
效果图
设计思路
目前可观测性的官方最佳实践流程是:
业务应用打点 Otel SDK -> 通过 OTLP 推送到 Collector -> Prometheus 定时拉取 Collector 暴露的 /metrics在 due 中,我选择的集成方式是,定义应用打点指标并采集,通过 OTLP 推送到 Collector,我们可以把这个能力看作 Exporter。框架不关心:
为了遵守项目风格,我选择在 component 包下,新增 otel/metrics 包来组织代码。otel 是可观测性的简写,为未来扩展 trace 和 log 留下口子。
otel/metrics 包,主要负责把管道建好并持续导出数据,也就是:
本次集成 metrics 的组件只有 network/tcp,采集了 7 个指标:
这些公共指标定义和网络通用的上报函数放在在 network 包的 metrics.go 中,特有的采集方法放在 network/tcp 包中,比如 TCP 才有的错误。
cluster 的 id(实例ID) 和 name(实例名词)目前是在 otel 中独立去设置,没有去读取 cluster 的相关配置,这是为了解耦,默认为空,它们是用于构建 resource,非必填。
性能测试
使用了现有的 benchmark 代码作为客户端,在 gate 引入指标组件,CPU pprof 文件,结果如下。
指标组件打开后,对网关吞吐的影响已经接近可以忽略,只占约 0.13% CPU。
其他