alibaba / alibaba/Sentinel

关于MetricFetcher的writeMetric方法参数的建议

Open
#2,339 0 comments 0 reactions 0 assignees View on GitHub
area/dashboard
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

读源代码(版本:`1.8.2` )时, `MetricFetcher` 的 `writeMetric` 方法是写监控数据的,位置如下:
`com.alibaba.csp.sentinel.dashboard.metric.MetricFetcher.java(137)` ,如图:
![image](https://user-images.githubusercontent.com/12644274/129649997-e1786125-8c84-49fb-8596-651f021dce38.png)
这里是我改造之后的方法,其中我加了一个 `String app` 参数,原因如下:
1、 `Map map` 经过引用、迭代处理,多个方法之间传递到这里,表意已经不是那么清晰了, `String app` 参数与 `map` 配合使用,传到下层方法时,条理更加清晰明确
2、`Map map` 集合类 `MetricEntity` 里虽然有 `app` 属性,但 `map` 可能为空,如果下层方法需要对与之关联的应用进行处理,就没法进行,此时 `app` 就可以起到标示应用的作用
为此,我将接口 `com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository` 的两个方法 `save` 和 `saveAll` 做了如下改造,如图:
![image](https://user-images.githubusercontent.com/12644274/129655052-9322902b-4194-4bc2-a9f0-b033368b834a.png)
望采纳,如果有其它更好的标示应用 `app` 的方法,感谢指点,谢谢!

Contributor guide

Open the contributing guide

Research direction

Start by reading MetricFetcher.writeMetric in com.alibaba.csp.sentinel.dashboard.metric.MetricFetcher.java around line 137, then inspect save and saveAll in com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository. Trace how the map reaches these methods and determine whether the app context is lost when the map is empty. Done means the proposed API change is resolved consistently across these entry points and their callers.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
observability
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.