变更记录
- 20-01-2020:初稿
状态
提案中背景
遥测对于调试以及理解应用程序正在做什么、其运行表现如何至关重要。我们的目标是从模块以及 Cosmos SDK 的其他核心部分暴露指标。 此外,我们还应支持多种可配置的 sink,供运维人员自行选择。默认情况下,当启用遥测时,应用程序应跟踪并暴露存储在内存中的指标。运维人员还可以选择启用额外的 sink,目前我们只支持 Prometheus,因为它经过充分验证、易于设置、开源,并且拥有丰富的生态工具。 我们还必须以尽可能无缝的方式将指标集成到 Cosmos SDK 中,从而可以按需添加或移除指标,而不会带来太多阻力。为此,我们将使用 go-metrics 库。 最后,运维人员可以结合特定配置选项启用遥测。启用后,指标将通过 API 服务器的/metrics?format={text|prometheus} 对外暴露。
决策
我们将在app.toml 中新增一个配置块,用于定义遥测设置:
Metrics 类型,为运维人员完成所有初始化工作,从而使指标采集过程变得无缝。
Metrics 还允许我们在任意时刻收集当前这组指标。运维人员也可以选择发送 SIGUSR1 信号,将格式化后的指标转储并打印到 STDERR。
在应用程序的引导和构建阶段,如果 Telemetry.Enabled 为 true,API 服务器将创建一个 Metrics 对象引用的实例,并据此注册指标处理器。
影响
正面
- 提升对应用程序性能和行为的可观测性
负面
中性
参考资料
Changelog
- 20-01-2020: Initial Draft
Status
ProposedContext
Telemetry is paramount into debugging and understanding what the application is doing and how it is performing. We aim to expose metrics from modules and other core parts of the Cosmos SDK. In addition, we should aim to support multiple configurable sinks that an operator may choose from. By default, when telemetry is enabled, the application should track and expose metrics that are stored in-memory. The operator may choose to enable additional sinks, where we support only Prometheus for now, as it’s battle-tested, simple to setup, open source, and is rich with ecosystem tooling. We must also aim to integrate metrics into the Cosmos SDK in the most seamless way possible such that metrics may be added or removed at will and without much friction. To do this, we will use the go-metrics library. Finally, operators may enable telemetry along with specific configuration options. If enabled, metrics will be exposed via/metrics?format={text|prometheus} via the API server.
Decision
We will add an additional configuration block toapp.toml that defines telemetry settings:
Metrics
type that performs all the bootstrapping for the operator, so capturing metrics becomes seamless.
Metrics allows us to gather the current set of metrics at any given point in time. An
operator may also choose to send a signal, SIGUSR1, to dump and print formatted metrics to STDERR.
During an application’s bootstrapping and construction phase, if Telemetry.Enabled is true, the
API server will create an instance of a reference to Metrics object and will register a metrics
handler accordingly.
Consequences
Positive
- Exposure into the performance and behavior of an application