Skip to content

[SCB-358] fix bug for monitor output id that register only name without any tags#562

Merged
WillemJiang merged 6 commits into
apache:masterfrom
zhengyangyong:SCB-358
Mar 1, 2018
Merged

[SCB-358] fix bug for monitor output id that register only name without any tags#562
WillemJiang merged 6 commits into
apache:masterfrom
zhengyangyong:SCB-358

Conversation

@zhengyangyong
Copy link
Copy Markdown

@zhengyangyong zhengyangyong commented Feb 28, 2018

Signed-off-by: zhengyangyong yangyong.zheng@huawei.com

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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.

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@coveralls
Copy link
Copy Markdown

coveralls commented Feb 28, 2018

Coverage Status

Coverage increased (+0.04%) to 87.247% when pulling ea0e61c on zhengyangyong:SCB-358 into b09a6c2 on apache:master.

zhengyangyong added 3 commits February 28, 2018 22:13
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>
Copy link
Copy Markdown
Member

@WillemJiang WillemJiang left a comment

Choose a reason for hiding this comment

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

Please fix the issues of the comments.

@Test
public void checkHealth() {
public void checkHealthBad() {
reset();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using the method with Setup to do work (annotation Before)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

this.getGauge(callable, MetricsConst.JVM, MetricsConst.TAG_STATISTIC, "gauge", MetricsConst.TAG_NAME, name);
}

private boolean isCorrectMonitorNameAndTags(String name, String... tags) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isCorrect -> validate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

public void checkUnmatchTypeWillNotReceived() throws InterruptedException {
AtomicBoolean eventReceived = new AtomicBoolean(false);

EventListener<String> listener = new EventListener<String>() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The EventListener can be reused out of the checkUmatchType method.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isCorrectId -> validateMetricId.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

if (!id.endsWith(")")) {
this.name = nameAndTag[0];
} else {
throw new ServiceCombException("bad format id");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add the id the message, otherwise the user cannot know which id is wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

return count;
}

private boolean isCorrectId(String id) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what if the id is empty string such as "".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

private void checkBadIdFormat(String id) throws Exception {
try {
new Metric(id, 100);
throw new Exception("CheckFailed");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use fail("xxx") here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

}
}

private void checkBadIdFormat(String id) throws Exception {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using the Expected Exception can do the work.
https://github.com/junit-team/junit4/wiki/exception-testing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

}
//ignore because throw exception is correct
catch (ServiceCombException ignore) {
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need to verify the ServiceCombException message here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

basicMonitorRegistry.register(counter);
return counter;
});
if (isCorrectMonitorNameAndTags(name, tags)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's more easy to throw the exception here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

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)) {
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.

so many if/else...... flat them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

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)) {
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.

why need to validate id?
servo/spectator's id, we can not use?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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增加你说的内容

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.

i will remove metric.java in new PR.

if (validateMetricId(id)) {
this.tags = new HashMap<>();
this.value = value;
String[] nameAndTag = id.split("[()]");
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.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

我会在新的PR增加从MonitorConfig创建Metric,不必parse

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.

i will remove metric.java in new PR.

@@ -81,4 +73,14 @@ public void process(String data) {
Thread.sleep(1000);
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.

why sleep?
our case run too fast????????????????????????????

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed,removed

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@WillemJiang WillemJiang merged commit 255f86e into apache:master Mar 1, 2018
@zhengyangyong zhengyangyong deleted the SCB-358 branch March 27, 2018 06:29
hujinming178 added a commit to hujinming178/servicecomb-java-chassis that referenced this pull request Jul 11, 2022
…e contract changes but the version number is not changed
hujinming178 added a commit to hujinming178/servicecomb-java-chassis that referenced this pull request Jul 15, 2022
…e contract changes but the version number is not changed fixed
hujinming178 added a commit to hujinming178/servicecomb-java-chassis that referenced this pull request Jul 20, 2022
…e contract changes but the version number is not changed fixed
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.

4 participants