Skip to content

feat: selfmonitor metrics support dynamic labels and gc#2496

Open
shunjiazhu wants to merge 8 commits intoalibaba:mainfrom
shunjiazhu:feat/self-monitor-dynamic-labels
Open

feat: selfmonitor metrics support dynamic labels and gc#2496
shunjiazhu wants to merge 8 commits intoalibaba:mainfrom
shunjiazhu:feat/self-monitor-dynamic-labels

Conversation

@shunjiazhu
Copy link
Copy Markdown
Contributor

@shunjiazhu shunjiazhu commented Dec 21, 2025

Change-Id: I74af3156bbc37e047cfc7f7b6c26a807973aceb5

  1. 自监控API,支持在打点时动态的传入TagValue,用于观测在插件初始化时无法确定label value的场景,比如http code等。
// ExportMetricRecords exports all metrics bound to this metric record.
// The results may be a list of map[string]string, each map[string]string is a set of measurements has the same labels.
// for example:
// []{
// {"counters":"{\"http_flusher_dropped_events\":\"3.0000\",\"http_flusher_flush_failure_count\":\"6.0000\",\"http_flusher_matched_events\":\"1.0000\",\"http_flusher_retry_count\":\"5.0000\",\"http_flusher_unmatched_events\":\"2.0000\"}","gauges":"{\"http_flusher_flush_latency_ns\":\"7.0000\"}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\"}"}
// {"counters":"{\"http_flusher_status_code_count\":\"8.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"status_code\":\"200\"}"}
// {"counters":"{\"http_flusher_status_code_count\":\"9.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"status_code\":\"400\"}"}
// {"counters":"{\"http_flusher_error_count\":\"10.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"level\":\"error\",\"reason\":\"timeout\"}"}
// {"counters":"{\"http_flusher_error_count\":\"11.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"level\":\"warn\",\"reason\":\"retry\"}"}
// {"counters":"{\"http_flusher_error_count\":\"12.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"level\":\"error\",\"reason\":\"dropped\"}"}
// }
// Note:
// A metric may have three levels of labels
// 1. MetricsRecord Level Const Labels, like PluginType=flusher_http, PluginId=1
// 2. Metric Level Const Labels, for example, flusher_http may have a const label: RemoteURL=http://aliyun.com/write
// 3. Metric Level Dynamic Labels, like status_code=200, status_code=204
  1. 自监控支持序列过期,当一个指标的一个特定的Tags组合长期没有打点时,允许其gc掉,防止因为内存中常驻维度过高而产生的内存开销。
	cumulativeCounter := NewCumulativeCounterMetricVector("test", constLabels, getTagNames(allTags),
		WithExpiration(time.Hour),
		WithCardinalityLimit(1000),
	)

Change-Id: I74af3156bbc37e047cfc7f7b6c26a807973aceb5
…mic-labels

Change-Id: Ic6dc62cf5675332857d79385be33f522c9f8c97c
Change-Id: I68d30400a1c319ed3a79235c4931825c907b20b8
Change-Id: If2681139c5acec1ea11b317558cf92b63b3fa48e
Change-Id: Id1d9a4eafd958bee780a617db5874d587f0148cb
Change-Id: I7054bded1154c5d653129262e052215f0106f5a3
Change-Id: I61956711952f596559f9be940cfd746d60191403
…mic-labels

Change-Id: Ica0541be7679d97cbd81b1f598e5c2865e047841
@Takuka0311
Copy link
Copy Markdown
Collaborator

Takuka0311 commented Apr 27, 2026

百炼自动化审查:建议保持开启。

本 PR 为自监控模块引入动态标签、指标序列 GC 及 Histogram 支持,并修改了核心 API ExportMetricRecords 的返回值类型。当前存在合并冲突且涉及 API 签名变更,需维护者审查兼容性与合并策略,故保持开启。.

最佳落地路径:

建议作者先 rebase main 解决合并冲突。维护者需重点评估 ExportMetricRecords 签名变更对下游插件的向后兼容性、动态标签与 GC 机制的并发安全性及高基数内存控制。CI 通过且审查完成后可合入。.

已核对内容:

  • merge_conflict: PR 当前 mergeable 状态为 false,存在合并冲突,需 rebase main。. (68a8d097e14f)
  • api_breaking_change: ExportMetricRecords 返回值由 map[string]string 改为 []map[string]string,同步修改了多处调用方展开逻辑,属于核心自监控 API 签名变更。. (pkg/selfmonitor/metrics_record.go:48, 68a8d097e14f)
  • feature_scope: 新增动态标签支持、指标过期 GC 机制及 Histogram 类型,涉及 pkg/selfmonitor 下多个核心实现文件与测试用例。. (pkg/selfmonitor/metrics_imp_v2.go, 68a8d097e14f)

百炼审查备注:模型 qwen3.6-max-preview;对照提交 7099f790b8a3

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

Successfully merging this pull request may close these issues.

2 participants