[SCB-358] fix bug for monitor output id that register only name without any tags#562
Conversation
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…gs() Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
WillemJiang
left a comment
There was a problem hiding this comment.
Please fix the issues of the comments.
| @Test | ||
| public void checkHealth() { | ||
| public void checkHealthBad() { | ||
| reset(); |
There was a problem hiding this comment.
Using the method with Setup to do work (annotation Before)
| this.getGauge(callable, MetricsConst.JVM, MetricsConst.TAG_STATISTIC, "gauge", MetricsConst.TAG_NAME, name); | ||
| } | ||
|
|
||
| private boolean isCorrectMonitorNameAndTags(String name, String... tags) { |
| public void checkUnmatchTypeWillNotReceived() throws InterruptedException { | ||
| AtomicBoolean eventReceived = new AtomicBoolean(false); | ||
|
|
||
| EventListener<String> listener = new EventListener<String>() { |
There was a problem hiding this comment.
The EventListener can be reused out of the checkUmatchType method.
| String[] tagAnValues = nameAndTag[1].split("[=,)]"); | ||
| for (int i = 0; i < tagAnValues.length; i += 2) { | ||
| this.tags.put(tagAnValues[i], tagAnValues[i + 1]); | ||
| if (isCorrectId(id)) { |
There was a problem hiding this comment.
isCorrectId -> validateMetricId.
| if (!id.endsWith(")")) { | ||
| this.name = nameAndTag[0]; | ||
| } else { | ||
| throw new ServiceCombException("bad format id"); |
There was a problem hiding this comment.
Please add the id the message, otherwise the user cannot know which id is wrong.
| return count; | ||
| } | ||
|
|
||
| private boolean isCorrectId(String id) { |
There was a problem hiding this comment.
what if the id is empty string such as "".
| private void checkBadIdFormat(String id) throws Exception { | ||
| try { | ||
| new Metric(id, 100); | ||
| throw new Exception("CheckFailed"); |
There was a problem hiding this comment.
You can use fail("xxx") here.
| } | ||
| } | ||
|
|
||
| private void checkBadIdFormat(String id) throws Exception { |
There was a problem hiding this comment.
Using the Expected Exception can do the work.
https://github.com/junit-team/junit4/wiki/exception-testing
| } | ||
| //ignore because throw exception is correct | ||
| catch (ServiceCombException ignore) { | ||
| } |
There was a problem hiding this comment.
We need to verify the ServiceCombException message here.
| basicMonitorRegistry.register(counter); | ||
| return counter; | ||
| }); | ||
| if (isCorrectMonitorNameAndTags(name, tags)) { |
There was a problem hiding this comment.
It's more easy to throw the exception here.
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
| String[] tagAnValues = nameAndTag[1].split("[=,)]"); | ||
| for (int i = 0; i < tagAnValues.length; i += 2) { | ||
| this.tags.put(tagAnValues[i], tagAnValues[i + 1]); | ||
| if (validateMetricId(id)) { |
There was a problem hiding this comment.
so many if/else...... flat them.
| String[] tagAnValues = nameAndTag[1].split("[=,)]"); | ||
| for (int i = 0; i < tagAnValues.length; i += 2) { | ||
| this.tags.put(tagAnValues[i], tagAnValues[i + 1]); | ||
| if (validateMetricId(id)) { |
There was a problem hiding this comment.
why need to validate id?
servo/spectator's id, we can not use?
There was a problem hiding this comment.
Metric、MetricNode和MetricLoader是工具类用于分析从publish获取的metrics结果Map<String,Double>,如果从servo的config获取会更简单一点,现在从String id parse 比如servicecomb.invocation(operation={operationName},role={role},stage={stage},statistic={statistic},status={status},unit={unit})也是有必要的,我会在新的PR增加你说的内容
There was a problem hiding this comment.
i will remove metric.java in new PR.
| if (validateMetricId(id)) { | ||
| this.tags = new HashMap<>(); | ||
| this.value = value; | ||
| String[] nameAndTag = id.split("[()]"); |
There was a problem hiding this comment.
why need to split tags?
servo/spectator's already have tags information.
if lost these informations caused by our mechanism, then we should change our mechanism.
this is why i DO NOT agree work on current mechanism.
There was a problem hiding this comment.
我会在新的PR增加从MonitorConfig创建Metric,不必parse
There was a problem hiding this comment.
i will remove metric.java in new PR.
| @@ -81,4 +73,14 @@ public void process(String data) { | |||
| Thread.sleep(1000); | |||
There was a problem hiding this comment.
why sleep?
our case run too fast????????????????????????????
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…e contract changes but the version number is not changed
…e contract changes but the version number is not changed fixed
…e contract changes but the version number is not changed fixed
Signed-off-by: zhengyangyong yangyong.zheng@huawei.com
Follow this checklist to help us incorporate your contribution quickly and easily:
[SCB-XXX] Fixes bug in ApproximateQuantiles, where you replaceSCB-XXXwith the appropriate JIRA issue.mvn clean installto make sure basic checks pass. A more thorough check will be performed on your pull request automatically.User can register monitor only name without any tags like :
MonitorManager.getInstance().getCounter("MonitorWithoutAnyTag");
In this case output metric id will be MonitorWithoutAnyTag) , correct output metric id is MonitorWithoutAnyTag ,not include a ')'
Also fix MetricsLoader load this style of metric id.