Skip to content

Feat: enhance mapping observability - #3605

Open
Modo-me wants to merge 3 commits into
apache:developfrom
Modo-me:feat/enhance-mapping-observability
Open

Feat: enhance mapping observability#3605
Modo-me wants to merge 3 commits into
apache:developfrom
Modo-me:feat/enhance-mapping-observability

Conversation

@Modo-me

@Modo-me Modo-me commented Aug 6, 2026

Copy link
Copy Markdown

Description

Related to #3356 PR1
Add metrics and logs for register, get, listen, and remove

Changes

  • metadata/report_instance.go: Instrumented the four mapping methods on DelegateMetadataReportRegisterServiceAppMapping (register), GetServiceAppMapping (switches to the listen event when listener is non-nil), RemoveServiceAppMappingListener (remove), emitting events with interface/group/application context, success status, and duration via the existing metrics.Publish pattern

  • metrics/metadata/metric_set.go: Added metric definitions for the four mapping operations — 4 event names (MetadataMappingRegister/Get/Listen/Remove), each with _num_total / _num_succeed_total / _num_failed_total / _rt_milliseconds, mapped to Prometheus names dubbo_metadata_mapping_{register,get,listen,remove}_*

  • metrics/metadata/collector.go: Added 4 event handlers (StateCount counters + Rt duration observations) and a metadataMappingMetricLevel tag layer exposing interface/group labels, with application overriding application_name on register, keeping label cardinality bounded

  • metadata/mapping/metadata/service_name_mapping.go: Added logs for mapping operations — Map/Get/Remove log success at Debug level and failures at Warn/Error with interface, group, application, report count, operation (get/listen), and error fields; Get now explicitly returns nil result on empty success

  • Added corresponding tests

Checklist

  • I confirm the target branch is develop
  • Code has passed local testing
  • I have added tests that prove my fix is effective or that my feature works

@Modo-me Modo-me changed the title Feat/enhance mapping observability Feat: enhance mapping observability Aug 6, 2026
@codecov-commenter

codecov-commenter commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.83721% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 53.99%. Comparing base (48d6e69) to head (f25bd1a).
⚠️ Report is 13 commits behind head on develop.

Files with missing lines Patch % Lines
metadata/mapping/metadata/service_name_mapping.go 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3605      +/-   ##
===========================================
- Coverage    54.57%   53.99%   -0.59%     
===========================================
  Files          460      474      +14     
  Lines        35443    36466    +1023     
===========================================
+ Hits         19344    19690     +346     
- Misses       14543    15200     +657     
- Partials      1556     1576      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread metrics/metadata/collector.go
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@Modo-me

Modo-me commented Aug 7, 2026

Copy link
Copy Markdown
Author

看了一下这个CI流程的失败应该不是由于这次commits修改导致的,好像是dubbo-go-samples仓库的新变动导致ci流程有竞态缺陷,会偶发失败
apache/dubbo-go-samples#1129

registry := newMockMetricRegistry()
collector := &MetadataMetricCollector{BaseCollector: metrics.BaseCollector{R: registry}}
collector.start()
defer metrics.Unsubscribe(constant.MetricsMetadata)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 不要关闭包级 channel,并同步异步 registry 断言

collector.start() 使用包级 channel,这里的 Unsubscribe 会把它永久关闭;当前用例执行 -count=2 时第二轮稳定 panic:send on closed channel / close of closed channel。同时 collector goroutine 在写 mock maps,而 Eventually 并发读取,go test -race 也稳定失败。请给测试提供可重建的专用 channel/teardown seam,不要关闭生产包级 channel,并给 mock registry 加锁或等待完成信号后再断言;修复后补 -race-count=2 门禁。

collector.start()
defer metrics.Unsubscribe(constant.MetricsMetadata)

publish := func(name MetricName, succ bool) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 让回归测试从 DelegateMetadataReport 驱动真实附件链

当前测试从手工构造 MetadataMetricEvent 开始,并自行填充 interface/group/application,仍绕过 DelegateMetadataReport。在 exact Head 的隔离副本中删除 metadata/report_instance.go 全部七处新增附件赋值后,go test ./metadata ./metrics/metadata -count=1 仍通过;生产指标此时会丢失标签。请用 mock report 调用 Register/Get/Listen/Remove 的 Delegate 方法,经过真实 event bus、start() switch、handler 到 registry,并断言标签;删除任一附件连接时测试应失败。

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.

3 participants