This is an automated email from the ASF dual-hosted git repository. wujimin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 7b751501ef8a483034ca20a6ff130acdfec3b92a Author: wujimin <wuji...@huawei.com> AuthorDate: Wed Apr 4 17:02:45 2018 +0800 SCB-445 delete old metrics mechanism --- .../org/apache/servicecomb/core/Invocation.java | 30 -- .../core/metrics/InvocationFinishedEvent.java | 68 ----- .../metrics/InvocationStartExecutionEvent.java | 30 -- .../core/metrics/InvocationStartedEvent.java | 46 --- .../foundation/metrics/MetricsConst.java | 44 --- .../foundation/metrics/publish/Metric.java | 131 --------- .../foundation/metrics/publish/MetricNode.java | 145 ---------- .../foundation/metrics/publish/MetricsLoader.java | 62 ---- .../foundation/metrics/publish/TestMetric.java | 118 -------- .../foundation/metrics/publish/TestMetricNode.java | 109 ------- .../metrics/publish/TestMetricsLoader.java | 69 ----- .../metrics/core/AbstractInvocationMetrics.java | 73 ----- .../metrics/core/ConsumerInvocationMetrics.java | 33 --- .../metrics/core/InvocationMetricsManager.java | 85 ------ .../servicecomb/metrics/core/MetricsConfig.java | 22 -- .../servicecomb/metrics/core/MonitorManager.java | 217 -------------- .../metrics/core/ProducerInvocationMetrics.java | 37 --- .../event/InvocationFinishedEventListener.java | 41 --- .../InvocationStartExecutionEventListener.java | 34 --- .../core/event/InvocationStartedEventListener.java | 37 --- .../metrics/core/TestAnMonitorManager.java | 321 --------------------- 21 files changed, 1752 deletions(-) diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java b/core/src/main/java/org/apache/servicecomb/core/Invocation.java index 369f071..b3ba281 100644 --- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java +++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java @@ -26,10 +26,7 @@ import org.apache.servicecomb.core.definition.OperationMeta; import org.apache.servicecomb.core.definition.SchemaMeta; import org.apache.servicecomb.core.event.InvocationFinishEvent; import org.apache.servicecomb.core.event.InvocationStartEvent; -import org.apache.servicecomb.core.metrics.InvocationStartExecutionEvent; -import org.apache.servicecomb.core.metrics.InvocationStartedEvent; import org.apache.servicecomb.core.provider.consumer.ReferenceConfig; -import org.apache.servicecomb.foundation.common.event.EventBus; import org.apache.servicecomb.foundation.common.event.EventManager; import org.apache.servicecomb.swagger.invocation.AsyncResponse; import org.apache.servicecomb.swagger.invocation.InvocationType; @@ -195,41 +192,14 @@ public class Invocation extends SwaggerInvocation { public void onStart() { this.startTime = System.nanoTime(); EventManager.post(new InvocationStartEvent(this)); - - // old logic, need to be deleted - EventBus.getInstance().triggerEvent(new InvocationStartedEvent(getMicroserviceQualifiedName(), - invocationType, startTime)); } public void onStartExecute() { this.startExecutionTime = System.nanoTime(); - - // old logic, need to be deleted - triggerStartExecutionEvent(); - } - - private void triggerStartExecutionEvent() { - if (InvocationType.PRODUCER.equals(invocationType)) { - this.startExecutionTime = System.nanoTime(); - EventBus.getInstance() - .triggerEvent(new InvocationStartExecutionEvent(operationMeta.getMicroserviceQualifiedName())); - } } public void onFinish(Response response) { EventManager.post(new InvocationFinishEvent(this, response)); - - // old logic, need to be deleted - triggerFinishedEvent(response.getStatusCode()); - } - - private void triggerFinishedEvent(int statusCode) { - long finishedTime = System.nanoTime(); - EventBus.getInstance() - .triggerEvent(new org.apache.servicecomb.core.metrics.InvocationFinishedEvent( - operationMeta.getMicroserviceQualifiedName(), this.invocationType, - startExecutionTime - startTime, finishedTime - startExecutionTime, - finishedTime - startTime, statusCode)); } public boolean isSync() { diff --git a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java deleted file mode 100644 index e0a10d1..0000000 --- a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.core.metrics; - -import org.apache.servicecomb.swagger.invocation.InvocationType; - -public class InvocationFinishedEvent { - private final String operationName; - - private final InvocationType invocationType; - - private final long inQueueNanoTime; - - private final long executionElapsedNanoTime; - - private final long totalElapsedNanoTime; - - private final int statusCode; - - public String getOperationName() { - return operationName; - } - - public InvocationType getInvocationType() { - return invocationType; - } - - public long getInQueueNanoTime() { - return inQueueNanoTime; - } - - public long getExecutionElapsedNanoTime() { - return executionElapsedNanoTime; - } - - public long getTotalElapsedNanoTime() { - return totalElapsedNanoTime; - } - - public int getStatusCode() { - return statusCode; - } - - public InvocationFinishedEvent(String operationName, InvocationType invocationType, - long inQueueNanoTime, long executionElapsedNanoTime, long totalElapsedNanoTime, int statusCode) { - this.operationName = operationName; - this.invocationType = invocationType; - this.inQueueNanoTime = inQueueNanoTime; - this.executionElapsedNanoTime = executionElapsedNanoTime; - this.totalElapsedNanoTime = totalElapsedNanoTime; - this.statusCode = statusCode; - } -} diff --git a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartExecutionEvent.java b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartExecutionEvent.java deleted file mode 100644 index 2d7c5a9..0000000 --- a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartExecutionEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.core.metrics; - -public class InvocationStartExecutionEvent { - private final String operationName; - - public String getOperationName() { - return operationName; - } - - public InvocationStartExecutionEvent(String operationName) { - this.operationName = operationName; - } -} diff --git a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java deleted file mode 100644 index 9ce7759..0000000 --- a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.core.metrics; - -import org.apache.servicecomb.swagger.invocation.InvocationType; - -public class InvocationStartedEvent { - private final String operationName; - - private final InvocationType invocationType; - - private final long startedTime; - - public String getOperationName() { - return operationName; - } - - public InvocationType getInvocationType() { - return invocationType; - } - - public long getStartedTime() { - return startedTime; - } - - public InvocationStartedEvent(String operationName, InvocationType invocationType, long startedTime) { - this.operationName = operationName; - this.invocationType = invocationType; - this.startedTime = startedTime; - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsConst.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsConst.java deleted file mode 100644 index fe82da4..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsConst.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics; - -public class MetricsConst { - public static final String JVM = "jvm"; - - public static final String SERVICECOMB_INVOCATION = "servicecomb.invocation"; - - public static final String TAG_NAME = "name"; - - public static final String TAG_OPERATION = "operation"; - - public static final String TAG_STATUS = "status"; - - public static final String TAG_STAGE = "stage"; - - public static final String TAG_ROLE = "role"; - - public static final String TAG_STATISTIC = "statistic"; - - public static final String TAG_UNIT = "unit"; - - public static final String STAGE_TOTAL = "total"; - - public static final String STAGE_QUEUE = "queue"; - - public static final String STAGE_EXECUTION = "execution"; -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/Metric.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/Metric.java deleted file mode 100644 index b894b58..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/Metric.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics.publish; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; -import org.apache.servicecomb.foundation.metrics.MetricsConst; - -public class Metric { - private String name; - - private Map<String, String> tags; - - private double value; - - public String getName() { - return name; - } - - public Metric(String id, double value) { - if (validateMetricId(id)) { - this.tags = new HashMap<>(); - this.value = value; - String[] nameAndTag = id.split("[()]"); - if (nameAndTag.length == 1) { - processIdWithoutTags(id, nameAndTag[0]); - } else if (nameAndTag.length == 2) { - processIdHadTags(id, nameAndTag); - } else { - throw new ServiceCombException("bad format id " + id); - } - } else { - throw new ServiceCombException("bad format id " + id); - } - } - - private void processIdWithoutTags(String id, String name) { - if (!id.endsWith(")")) { - this.name = name; - } else { - throw new ServiceCombException("bad format id " + id); - } - } - - private void processIdHadTags(String id, String[] nameAndTag) { - this.name = nameAndTag[0]; - String[] tagAnValues = nameAndTag[1].split(","); - for (String tagAnValue : tagAnValues) { - String[] kv = tagAnValue.split("="); - if (kv.length == 2) { - this.tags.put(kv[0], kv[1]); - } else { - throw new ServiceCombException("bad format tag " + id); - } - } - } - - public double getValue() { - return value; - } - - public double getValue(TimeUnit unit) { - if (tags.containsKey(MetricsConst.TAG_UNIT)) { - if (!tags.get(MetricsConst.TAG_UNIT).equals(String.valueOf(unit))) { - return unit.convert((long) value, TimeUnit.valueOf(tags.get(MetricsConst.TAG_UNIT))); - } - } - return value; - } - - public int getTagsCount() { - return tags.size(); - } - - public boolean containsTagKey(String tagKey) { - return tags.containsKey(tagKey); - } - - public String getTagValue(String tagKey) { - return tags.get(tagKey); - } - - public boolean containsTag(String tagKey, String tagValue) { - return tags.containsKey(tagKey) && tagValue.equals(tags.get(tagKey)); - } - - public boolean containsTag(String... tags) { - if (tags.length >= 2 && tags.length % 2 == 0) { - for (int i = 0; i < tags.length; i += 2) { - if (!containsTag(tags[i], tags[i + 1])) { - return false; - } - } - return true; - } - throw new ServiceCombException("bad tags count : " + String.join(",", tags)); - } - - private int getCharCount(String id, char c) { - int count = 0; - for (char cr : id.toCharArray()) { - if (cr == c) { - count++; - } - } - return count; - } - - private boolean validateMetricId(String id) { - return id != null && !"".equals(id) && !id.endsWith("(") && - getCharCount(id, '(') <= 1 && getCharCount(id, ')') <= 1; - } -} \ No newline at end of file diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MetricNode.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MetricNode.java deleted file mode 100644 index 1d47366..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MetricNode.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics.publish; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; - -import org.apache.servicecomb.foundation.metrics.MetricsConst; - -import com.google.common.collect.Lists; - -public class MetricNode { - private final String tagKey; - - private final List<Metric> metrics; - - private final Map<String, MetricNode> children; - - public MetricNode(Iterable<Metric> metrics, String... groupTagKeys) { - if (groupTagKeys == null || groupTagKeys.length == 0) { - this.tagKey = null; - this.metrics = Lists.newArrayList(metrics); - this.children = null; - } else { - this.tagKey = groupTagKeys[0]; - this.metrics = null; - this.children = new HashMap<>(); - Map<String, List<Metric>> groups = groupByTag(metrics, this.tagKey); - if (groupTagKeys.length == 1) { - for (Entry<String, List<Metric>> group : groups.entrySet()) { - this.children.put(group.getKey(), new MetricNode(null, group.getValue(), null)); - } - } else { - for (Entry<String, List<Metric>> group : groups.entrySet()) { - this.children.put(group.getKey(), - new MetricNode(group.getValue(), Arrays.copyOfRange(groupTagKeys, 1, groupTagKeys.length))); - } - } - } - } - - private MetricNode(String tagKey, List<Metric> metrics, Map<String, MetricNode> children) { - this.tagKey = tagKey; - this.metrics = metrics; - this.children = children; - } - - public Iterable<Metric> getMetrics() { - return metrics; - } - - public int getMetricCount() { - return metrics.size(); - } - - public Iterable<Entry<String, MetricNode>> getChildren() { - return children.entrySet(); - } - - public MetricNode getChildren(String tagValue) { - return children.get(tagValue); - } - - public int getChildrenCount() { - return children.size(); - } - - public MetricNode getChildrenNode(String tagValue) { - return children.get(tagValue); - } - - public Double getFirstMatchMetricValue(String tagKey, String tagValue) { - for (Metric metric : this.metrics) { - if (metric.containsTag(tagKey, tagValue)) { - return metric.getValue(); - } - } - return Double.NaN; - } - - public Double getFirstMatchMetricValue(TimeUnit unit, String tagKey, String tagValue) { - for (Metric metric : this.metrics) { - if (metric.containsTag(tagKey, tagValue)) { - return metric.getValue(unit); - } - } - return Double.NaN; - } - - public Double getFirstMatchMetricValue(String... tags) { - for (Metric metric : this.metrics) { - if (metric.containsTag(tags)) { - return metric.getValue(); - } - } - return Double.NaN; - } - - public Double getFirstMatchMetricValue(TimeUnit unit, String... tags) { - for (Metric metric : this.metrics) { - if (metric.containsTag(tags)) { - return metric.getValue(unit); - } - } - return Double.NaN; - } - - public double getMatchStatisticMetricValue(String statisticValue) { - return getFirstMatchMetricValue(MetricsConst.TAG_STATISTIC, statisticValue); - } - - public double getMatchStatisticMetricValue(TimeUnit unit, String statisticValue) { - return getFirstMatchMetricValue(unit, MetricsConst.TAG_STATISTIC, statisticValue); - } - - private Map<String, List<Metric>> groupByTag(Iterable<Metric> metrics, String tagKey) { - Map<String, List<Metric>> groups = new HashMap<>(); - for (Metric metric : metrics) { - if (metric.containsTagKey(tagKey)) { - groups.computeIfAbsent(metric.getTagValue(tagKey), g -> new ArrayList<>()).add(metric); - } - } - return groups; - } -} \ No newline at end of file diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MetricsLoader.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MetricsLoader.java deleted file mode 100644 index 6d3a396..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MetricsLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics.publish; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; - -//load origin metrics value and publish tree -public class MetricsLoader { - - private final Map<String, List<Metric>> metrics; - - public MetricsLoader(Map<String, Double> metrics) { - this.metrics = new HashMap<>(); - for (Entry<String, Double> entry : metrics.entrySet()) { - Metric metric = new Metric(entry.getKey(), entry.getValue()); - this.metrics.computeIfAbsent(metric.getName(), m -> new ArrayList<>()).add(metric); - } - } - - public MetricNode getMetricTree(String id, String... groupTagKeys) { - if (containsId(id)) { - return new MetricNode(metrics.get(id), groupTagKeys); - } - throw new ServiceCombException("no such id : " + id); - } - - public boolean containsId(String id) { - return metrics.containsKey(id); - } - - public double getFirstMatchMetricValue(String name, String tagKey, String tagValue) { - if (metrics.containsKey(name)) { - for (Metric metric : this.metrics.get(name)) { - if (metric.containsTag(tagKey, tagValue)) { - return metric.getValue(); - } - } - } - return Double.NaN; - } -} \ No newline at end of file diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetric.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetric.java deleted file mode 100644 index eb47dd7..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetric.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics.publish; - -import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class TestMetric { - @Test - public void testNewMetric() { - - Metric metric = new Metric("Key", 100); - Assert.assertEquals(0, metric.getTagsCount()); - - metric = new Metric("Key(A=1)", 100); - Assert.assertEquals(1, metric.getTagsCount()); - Assert.assertEquals(true, metric.containsTagKey("A")); - - metric = new Metric("Key(A=1,B=X)", 100); - Assert.assertEquals(2, metric.getTagsCount()); - Assert.assertEquals(true, metric.containsTagKey("A")); - Assert.assertEquals(true, metric.containsTagKey("B")); - Assert.assertEquals("1", metric.getTagValue("A")); - Assert.assertEquals("X", metric.getTagValue("B")); - - checkBadIdFormat(null); - checkBadIdFormat(""); - checkBadIdFormat("("); - checkBadIdFormat(")"); - checkBadIdFormat("()"); - - checkBadIdFormat("Key("); - checkBadIdFormat("Key)"); - checkBadIdFormat("Key()"); - - checkBadIdFormat("Key(X)"); - checkBadIdFormat("Key(X"); - checkBadIdFormat("Key(X))"); - checkBadIdFormat("Key((X)"); - - checkBadIdFormat("Key(X=)"); - checkBadIdFormat("Key(X="); - checkBadIdFormat("Key(X=))"); - checkBadIdFormat("Key((X=)"); - - checkBadIdFormat("Key(X=,)"); - checkBadIdFormat("Key(X=,"); - checkBadIdFormat("Key(X=,))"); - checkBadIdFormat("Key((X=,)"); - - checkBadIdFormat("Key(X=,Y)"); - checkBadIdFormat("Key(X=,Y"); - checkBadIdFormat("Key(X=,Y))"); - checkBadIdFormat("Key((X=,Y)"); - - checkBadIdFormat("Key(X=1,Y)"); - checkBadIdFormat("Key(X=1,Y"); - checkBadIdFormat("Key(X=1,Y))"); - checkBadIdFormat("Key((X=1,Y)"); - - checkBadIdFormat("Key(X=1))"); - checkBadIdFormat("Key((X=1)"); - - checkBadIdFormat("Key(X=1) "); - checkBadIdFormat("Key(X=1,Y=2)Z"); - - checkBadIdFormat("Key(X=1)()"); - checkBadIdFormat("Key(X=1)(Y=1)"); - } - - @Test - public void checkMetricContainsTag() { - Metric metric = new Metric("Key(A=1,B=X)", 100); - Assert.assertEquals(true, metric.containsTag("A", "1")); - } - - @Test - public void checkMetricContainsTagWithWrongTagsCount() { - Metric metric = new Metric("Key(A=1,B=X)", 100); - checkMetricContainsTagWithWrongTagsCount(metric, "A"); - checkMetricContainsTagWithWrongTagsCount(metric, "A", "1", "B"); - checkMetricContainsTagWithWrongTagsCount(metric, "A", "1", "B", "X", "C"); - } - - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private void checkMetricContainsTagWithWrongTagsCount(Metric metric, String... tags) { - thrown.expect(ServiceCombException.class); - metric.containsTag(tags); - Assert.fail("checkMetricContainsTagWithWrongTagsCount failed : " + String.join(",", tags)); - } - - private void checkBadIdFormat(String id) { - thrown.expect(ServiceCombException.class); - new Metric(id, 100); - Assert.fail("checkBadIdFormat failed : " + id); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetricNode.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetricNode.java deleted file mode 100644 index 53427b5..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetricNode.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics.publish; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestMetricNode { - private static MetricsLoader loader; - - @BeforeClass - public static void steup() { - Map<String, Double> metrics = new HashMap<>(); - metrics.put("X(K1=1,K2=2,K3=3,unit=SECONDS,statistic=A)", 100.0); - metrics.put("X(K1=1,K2=2,K3=30000,unit=SECONDS,statistic=AA)", 110.0); - metrics.put("X(K1=1,K2=20,K3=30,unit=SECONDS,statistic=B)", 200.0); - metrics.put("X(K1=2,K2=200,K3=300,unit=SECONDS,statistic=C)", 300.0); - metrics.put("X(K1=2,K2=2000,K3=3000,unit=SECONDS,statistic=D)", 400.0); - - metrics.put("Y(K1=1,K2=2,K3=3)", 500.0); - metrics.put("Y(K1=10,K2=20,K3=30)", 600.0); - metrics.put("Y(K1=100,K2=200,K3=300)", 700.0); - metrics.put("Y(K1=1000,K2=2000,K3=3000)", 800.0); - - loader = new MetricsLoader(metrics); - } - - @Test - public void checkNodeMetricCount() { - MetricNode node = loader.getMetricTree("X", "K1"); - MetricNode node_k1 = node.getChildrenNode("1"); - Assert.assertEquals(3, node_k1.getMetricCount()); - } - - @Test - public void checkGetFirstMatchMetricValueWithSingleTag() { - MetricNode node = loader.getMetricTree("X", "K1"); - MetricNode node_k1 = node.getChildrenNode("1"); - Assert.assertEquals(100, node_k1.getFirstMatchMetricValue("K2", "2"), 0); - Assert.assertEquals(100 * 1000, node_k1.getFirstMatchMetricValue(TimeUnit.MILLISECONDS, "K2", "2"), 0); - Assert.assertEquals(100 * 1000, node_k1.getFirstMatchMetricValue(TimeUnit.MILLISECONDS, "K2", "2"), 0); - } - - @Test - public void checkGetFirstMatchMetricValueWithMultiTag() { - MetricNode node = loader.getMetricTree("X", "K1"); - MetricNode node_k1 = node.getChildrenNode("1"); - Assert.assertEquals(200, node_k1.getFirstMatchMetricValue("K3", "30", "K2", "20"), 0); - Assert.assertEquals(200 * 1000, node_k1.getFirstMatchMetricValue(TimeUnit.MILLISECONDS, "K3", "30", "K2", "20"), 0); - Assert.assertEquals(110.0, node_k1.getFirstMatchMetricValue("K2", "2", "K3", "30000"), 0); - Assert - .assertEquals(110 * 1000, node_k1.getFirstMatchMetricValue(TimeUnit.MILLISECONDS, "K2", "2", "K3", "30000"), 0); - } - - @Test - public void checkGetMatchStatisticMetricValue() { - MetricNode node = loader.getMetricTree("X", "K1"); - MetricNode node_k1 = node.getChildrenNode("1"); - Assert.assertEquals(100, node_k1.getMatchStatisticMetricValue("A"), 0); - Assert.assertEquals(100 * 1000, node_k1.getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "A"), 0); - } - - @Test - public void checkGenerateMetricNodeFromExistedNode() { - MetricNode node = loader.getMetricTree("X", "K1"); - MetricNode node_k1 = node.getChildrenNode("1"); - MetricNode newNode = new MetricNode(node_k1.getMetrics(), "K2", "K3"); - Assert.assertEquals(1, newNode.getChildrenNode("2").getChildrenNode("3").getMetricCount(), 0); - } - - @Test - public void testNewMetricNode() { - List<Metric> metrics = new ArrayList<>(); - metrics.add(new Metric("Y(K1=1,K2=2,K3=3)", 1)); - metrics.add(new Metric("Y(K1=1,K2=20,K3=30)", 10)); - metrics.add(new Metric("Y(K1=10,K2=20,K3=300)", 100)); - metrics.add(new Metric("Y(K1=10,K2=20,K3=3000)", 1000)); - - MetricNode node = new MetricNode(metrics); - Assert.assertEquals(4, node.getMetricCount()); - Assert.assertEquals(1.0, node.getFirstMatchMetricValue("K3", "3"), 0); - - node = new MetricNode(metrics, "K1"); - Assert.assertEquals(2, node.getChildrenCount()); - Assert.assertEquals(1.0, node.getChildren("1").getFirstMatchMetricValue("K3", "3"), 0); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetricsLoader.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetricsLoader.java deleted file mode 100644 index c3eed5e..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetricsLoader.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.foundation.metrics.publish; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class TestMetricsLoader { - private static MetricsLoader loader; - - @BeforeClass - public static void setup() { - Map<String, Double> metrics = new HashMap<>(); - metrics.put("X(K1=1,K2=2,K3=3)", 100.0); - metrics.put("X(K1=1,K2=20,K3=30)", 200.0); - metrics.put("X(K1=2,K2=200,K3=300)", 300.0); - metrics.put("X(K1=2,K2=2000,K3=3000)", 400.0); - - metrics.put("Y(K1=1,K2=2,K3=3)", 500.0); - metrics.put("Y(K1=10,K2=20,K3=30)", 600.0); - metrics.put("Y(K1=100,K2=200,K3=300)", 700.0); - metrics.put("Y(K1=1000,K2=2000,K3=3000)", 800.0); - - loader = new MetricsLoader(metrics); - } - - @Test - public void checkFirstMatchMetricValue() { - Assert.assertEquals(200.0, loader.getFirstMatchMetricValue("X", "K3", "30"), 0); - } - - @Test - public void checkGetChildrenCount() { - MetricNode node = loader.getMetricTree("X", "K1"); - Assert.assertEquals(2, node.getChildrenCount()); - } - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void checkNoSuchId() { - thrown.expect(ServiceCombException.class); - loader.getMetricTree("Z"); - Assert.fail("checkNoSuchId failed"); - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/AbstractInvocationMetrics.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/AbstractInvocationMetrics.java deleted file mode 100644 index 104aa64..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/AbstractInvocationMetrics.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.servicecomb.foundation.metrics.MetricsConst; - -import com.netflix.servo.monitor.Counter; -import com.netflix.servo.monitor.MaxGauge; -import com.netflix.servo.monitor.StepCounter; -import com.netflix.servo.monitor.Timer; - -abstract class AbstractInvocationMetrics { - private final Counter tps; - - private final Counter count; - - private final Map<String, Timer> averageLatencies; - - private final Map<String, MaxGauge> maxLatencies; - - AbstractInvocationMetrics(String... tags) { - String[] tagsWithStage = ArrayUtils.addAll(tags, MetricsConst.TAG_STAGE, MetricsConst.STAGE_TOTAL); - this.tps = MonitorManager.getInstance().getCounter(StepCounter::new, MetricsConst.SERVICECOMB_INVOCATION, - ArrayUtils.addAll(tagsWithStage, MetricsConst.TAG_STATISTIC, "tps")); - this.count = MonitorManager.getInstance().getCounter(MetricsConst.SERVICECOMB_INVOCATION, - ArrayUtils.addAll(tagsWithStage, MetricsConst.TAG_STATISTIC, "count")); - - this.averageLatencies = new HashMap<>(); - this.maxLatencies = new HashMap<>(); - this.addLatencyMonitors(MetricsConst.STAGE_TOTAL, tags); - } - - void updateCallMonitors() { - tps.increment(); - count.increment(); - } - - void updateLatencyMonitors(String stage, long value, TimeUnit unit) { - averageLatencies.get(stage).record(value, unit); - maxLatencies.get(stage).update(unit.toMillis(value)); - } - - void addLatencyMonitors(String stage, String... tags) { - String[] tagsWithStageAndUnit = ArrayUtils - .addAll(tags, MetricsConst.TAG_STAGE, stage, MetricsConst.TAG_UNIT, String.valueOf(TimeUnit.MILLISECONDS)); - this.averageLatencies.put(stage, MonitorManager.getInstance() - .getTimer(MetricsConst.SERVICECOMB_INVOCATION, - ArrayUtils.addAll(tagsWithStageAndUnit, MetricsConst.TAG_STATISTIC, "latency"))); - this.maxLatencies.put(stage, MonitorManager.getInstance() - .getMaxGauge(MetricsConst.SERVICECOMB_INVOCATION, - ArrayUtils.addAll(tagsWithStageAndUnit, MetricsConst.TAG_STATISTIC, "max"))); - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/ConsumerInvocationMetrics.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/ConsumerInvocationMetrics.java deleted file mode 100644 index c370f79..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/ConsumerInvocationMetrics.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -import java.util.concurrent.TimeUnit; - -import org.apache.servicecomb.foundation.metrics.MetricsConst; - -public class ConsumerInvocationMetrics extends AbstractInvocationMetrics { - public ConsumerInvocationMetrics(String... tags) { - super(tags); - } - - public void update(long totalElapsedNanoTime) { - this.updateCallMonitors(); - this.updateLatencyMonitors(MetricsConst.STAGE_TOTAL, totalElapsedNanoTime, TimeUnit.NANOSECONDS); - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/InvocationMetricsManager.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/InvocationMetricsManager.java deleted file mode 100644 index 887cc71..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/InvocationMetricsManager.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -import java.util.Map; - -import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx; -import org.apache.servicecomb.foundation.metrics.MetricsConst; -import org.apache.servicecomb.swagger.invocation.InvocationType; - -import com.netflix.servo.monitor.Counter; - -public class InvocationMetricsManager { - - //invocationName -> statusCode -> ConsumerInvocationMetrics - private final Map<String, Map<Integer, ConsumerInvocationMetrics>> consumerMetrics; - - //invocationName -> statusCode -> ProducerInvocationMetrics - private final Map<String, Map<Integer, ProducerInvocationMetrics>> producerMetrics; - - //invocationName -> Counter - private final Map<String, Counter> waitInQueueCounters; - - private static final InvocationMetricsManager INSTANCE = new InvocationMetricsManager(); - - public static InvocationMetricsManager getInstance() { - return INSTANCE; - } - - private InvocationMetricsManager() { - this.consumerMetrics = new ConcurrentHashMapEx<>(); - this.producerMetrics = new ConcurrentHashMapEx<>(); - this.waitInQueueCounters = new ConcurrentHashMapEx<>(); - } - - public void incrementWaitInQueue(String invocationName) { - updateWaitInQueue(invocationName, 1); - } - - public void decrementWaitInQueue(String invocationName) { - updateWaitInQueue(invocationName, -1); - } - - private void updateWaitInQueue(String invocationName, long value) { - waitInQueueCounters.computeIfAbsent(invocationName, - f -> MonitorManager.getInstance().getCounter( - MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, invocationName, - MetricsConst.TAG_STAGE, MetricsConst.STAGE_QUEUE, - MetricsConst.TAG_ROLE, String.valueOf(InvocationType.PRODUCER).toLowerCase(), - MetricsConst.TAG_STATISTIC, "waitInQueue")).increment(value); - } - - public void updateProducer(String invocationName, int statusCode, long inQueueNanoTime, long executionElapsedNanoTime, - long totalElapsedNanoTime) { - producerMetrics.computeIfAbsent(invocationName, f -> new ConcurrentHashMapEx<>()) - .computeIfAbsent(statusCode, f -> new ProducerInvocationMetrics( - MetricsConst.TAG_OPERATION, invocationName, - MetricsConst.TAG_ROLE, String.valueOf(InvocationType.PRODUCER).toLowerCase(), - MetricsConst.TAG_STATUS, String.valueOf(statusCode))) - .update(inQueueNanoTime, executionElapsedNanoTime, totalElapsedNanoTime); - } - - public void updateConsumer(String invocationName, int statusCode, long totalElapsedNanoTime) { - consumerMetrics.computeIfAbsent(invocationName, f -> new ConcurrentHashMapEx<>()) - .computeIfAbsent(statusCode, f -> new ConsumerInvocationMetrics( - MetricsConst.TAG_OPERATION, invocationName, - MetricsConst.TAG_ROLE, String.valueOf(InvocationType.CONSUMER).toLowerCase(), - MetricsConst.TAG_STATUS, String.valueOf(statusCode))).update(totalElapsedNanoTime); - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/MetricsConfig.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/MetricsConfig.java deleted file mode 100644 index 2bccfcf..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/MetricsConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -public class MetricsConfig { - public static final String METRICS_WINDOW_TIME = "servicecomb.metrics.window_time"; -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/MonitorManager.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/MonitorManager.java deleted file mode 100644 index be71b62..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/MonitorManager.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.concurrent.Callable; -import java.util.function.Function; - -import org.apache.commons.lang3.StringUtils; -import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx; -import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; -import org.apache.servicecomb.foundation.metrics.MetricsConst; - -import com.netflix.config.DynamicPropertyFactory; -import com.netflix.servo.BasicMonitorRegistry; -import com.netflix.servo.MonitorRegistry; -import com.netflix.servo.monitor.BasicCounter; -import com.netflix.servo.monitor.BasicGauge; -import com.netflix.servo.monitor.BasicTimer; -import com.netflix.servo.monitor.Counter; -import com.netflix.servo.monitor.Gauge; -import com.netflix.servo.monitor.MaxGauge; -import com.netflix.servo.monitor.Monitor; -import com.netflix.servo.monitor.MonitorConfig; -import com.netflix.servo.monitor.MonitorConfig.Builder; -import com.netflix.servo.monitor.Timer; -import com.netflix.servo.tag.Tag; -import com.netflix.servo.tag.TagList; - -public class MonitorManager { - - private final Map<String, Counter> counters; - - private final Map<String, MaxGauge> maxGauges; - - private final Map<String, Gauge<?>> gauges; - - private final Map<String, Timer> timers; - - private final MonitorRegistry basicMonitorRegistry; - - private static final char[] forbiddenCharacter = new char[] {'(', ')', '=', ','}; - - private static final MonitorManager INSTANCE = new MonitorManager(); - - public static MonitorManager getInstance() { - return INSTANCE; - } - - private MonitorManager() { - this.counters = new ConcurrentHashMapEx<>(); - this.maxGauges = new ConcurrentHashMapEx<>(); - this.gauges = new ConcurrentHashMapEx<>(); - this.timers = new ConcurrentHashMapEx<>(); - this.basicMonitorRegistry = new BasicMonitorRegistry(); - setupWindowTime(); - registerSystemMetrics(); - } - - private void setupWindowTime() { - int time = DynamicPropertyFactory.getInstance().getIntProperty(MetricsConfig.METRICS_WINDOW_TIME, 5000).get(); - System.getProperties().setProperty("servo.pollers", time > 0 ? String.valueOf(time) : "5000"); - } - - public Counter getCounter(String name, String... tags) { - validateMonitorNameAndTags(name, tags); - return counters.computeIfAbsent(getMonitorKey(name, tags), f -> { - Counter counter = new BasicCounter(getConfig(name, tags)); - basicMonitorRegistry.register(counter); - return counter; - }); - } - - public Counter getCounter(Function<MonitorConfig, Counter> function, String name, String... tags) { - validateMonitorNameAndTags(name, tags); - return counters.computeIfAbsent(getMonitorKey(name, tags), f -> { - Counter counter = function.apply(getConfig(name, tags)); - basicMonitorRegistry.register(counter); - return counter; - }); - } - - public MaxGauge getMaxGauge(String name, String... tags) { - validateMonitorNameAndTags(name, tags); - return maxGauges.computeIfAbsent(getMonitorKey(name, tags), f -> { - MaxGauge maxGauge = new MaxGauge(getConfig(name, tags)); - basicMonitorRegistry.register(maxGauge); - return maxGauge; - }); - } - - public <V extends Number> Gauge<?> getGauge(Callable<V> callable, String name, String... tags) { - validateMonitorNameAndTags(name, tags); - return gauges.computeIfAbsent(getMonitorKey(name, tags), f -> { - Gauge<?> gauge = new BasicGauge<>(getConfig(name, tags), callable); - basicMonitorRegistry.register(gauge); - return gauge; - }); - } - - public Timer getTimer(String name, String... tags) { - validateMonitorNameAndTags(name, tags); - return timers.computeIfAbsent(getMonitorKey(name, tags), f -> { - Timer timer = new BasicTimer(getConfig(name, tags)); - basicMonitorRegistry.register(timer); - return timer; - }); - } - - public Map<String, Double> measure() { - Map<String, Double> measurements = new HashMap<>(); - for (Monitor<?> monitor : basicMonitorRegistry.getRegisteredMonitors()) { - measurements.put(getMonitorKey(monitor.getConfig()), - ((Number) monitor.getValue(0)).doubleValue()); - } - return measurements; - } - - private MonitorConfig getConfig(String name, String... tags) { - validateMonitorNameAndTags(name, tags); - Builder builder = MonitorConfig.builder(name); - for (int i = 0; i < tags.length; i += 2) { - builder.withTag(tags[i], tags[i + 1]); - } - return builder.build(); - } - - private String getMonitorKey(String name, String... tags) { - validateMonitorNameAndTags(name, tags); - if (tags.length != 0) { - SortedMap<String, String> tagMap = new TreeMap<>(); - for (int i = 0; i < tags.length; i += 2) { - tagMap.put(tags[i], tags[i + 1]); - } - StringBuilder builder = new StringBuilder("("); - for (Entry<String, String> entry : tagMap.entrySet()) { - builder.append(String.format("%s=%s,", entry.getKey(), entry.getValue())); - } - builder.deleteCharAt(builder.length() - 1); - builder.append(")"); - return name + builder.toString(); - } - return name; - } - - private String getMonitorKey(MonitorConfig config) { - TagList tagList = config.getTags(); - List<String> tags = new ArrayList<>(); - for (Tag tag : tagList) { - if (!"type".equals(tag.getKey())) { - tags.add(tag.getKey()); - tags.add(tag.getValue()); - } - } - return getMonitorKey(config.getName(), tags.toArray(new String[0])); - } - - - private void registerSystemMetrics() { - SystemMetrics resource = new SystemMetrics(); - registerSystemMetricItem(resource::getCpuLoad, "cpuLoad"); - registerSystemMetricItem(resource::getCpuRunningThreads, "cpuRunningThreads"); - registerSystemMetricItem(resource::getHeapInit, "heapInit"); - registerSystemMetricItem(resource::getHeapCommit, "heapCommit"); - registerSystemMetricItem(resource::getHeapUsed, "heapUsed"); - registerSystemMetricItem(resource::getHeapMax, "heapMax"); - registerSystemMetricItem(resource::getNonHeapInit, "nonHeapInit"); - registerSystemMetricItem(resource::getNonHeapCommit, "nonHeapCommit"); - registerSystemMetricItem(resource::getNonHeapUsed, "nonHeapUsed"); - registerSystemMetricItem(resource::getNonHeapMax, "nonHeapMax"); - } - - private <V extends Number> void registerSystemMetricItem(Callable<V> callable, String name) { - this.getGauge(callable, MetricsConst.JVM, MetricsConst.TAG_STATISTIC, "gauge", MetricsConst.TAG_NAME, name); - } - - private void validateMonitorNameAndTags(String name, String... tags) { - boolean passed = StringUtils.isNotEmpty(name) && tags.length % 2 == 0; - if (passed) { - if (StringUtils.containsNone(name, forbiddenCharacter)) { - for (String tag : tags) { - if (StringUtils.containsAny(tag, forbiddenCharacter)) { - throw new ServiceCombException( - "validate name and tags failed name = " + name + " tags = " + String.join(",", tags)); - } - } - } else { - throw new ServiceCombException( - "validate name and tags failed name = " + name + " tags = " + String.join(",", tags)); - } - } else { - throw new ServiceCombException( - "validate name and tags failed name = " + name + " tags = " + String.join(",", tags)); - } - } -} \ No newline at end of file diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/ProducerInvocationMetrics.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/ProducerInvocationMetrics.java deleted file mode 100644 index c869be0..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/ProducerInvocationMetrics.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -import java.util.concurrent.TimeUnit; - -import org.apache.servicecomb.foundation.metrics.MetricsConst; - -public class ProducerInvocationMetrics extends AbstractInvocationMetrics { - public ProducerInvocationMetrics(String... tags) { - super(tags); - this.addLatencyMonitors(MetricsConst.STAGE_QUEUE, tags); - this.addLatencyMonitors(MetricsConst.STAGE_EXECUTION, tags); - } - - public void update(long inQueueNanoTime, long executionElapsedNanoTime, long totalElapsedNanoTime) { - this.updateCallMonitors(); - this.updateLatencyMonitors(MetricsConst.STAGE_QUEUE, inQueueNanoTime, TimeUnit.NANOSECONDS); - this.updateLatencyMonitors(MetricsConst.STAGE_EXECUTION, executionElapsedNanoTime, TimeUnit.NANOSECONDS); - this.updateLatencyMonitors(MetricsConst.STAGE_TOTAL, totalElapsedNanoTime, TimeUnit.NANOSECONDS); - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java deleted file mode 100644 index 51edc6b..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core.event; - -import org.apache.servicecomb.core.metrics.InvocationFinishedEvent; -import org.apache.servicecomb.foundation.common.event.EventListener; -import org.apache.servicecomb.metrics.core.InvocationMetricsManager; -import org.apache.servicecomb.swagger.invocation.InvocationType; - -public class InvocationFinishedEventListener implements EventListener<InvocationFinishedEvent> { - @Override - public Class<InvocationFinishedEvent> getEventClass() { - return InvocationFinishedEvent.class; - } - - @Override - public void process(InvocationFinishedEvent data) { - if (InvocationType.PRODUCER.equals(data.getInvocationType())) { - InvocationMetricsManager.getInstance().updateProducer(data.getOperationName(), data.getStatusCode(), - data.getInQueueNanoTime(), data.getExecutionElapsedNanoTime(), data.getTotalElapsedNanoTime()); - } else { - InvocationMetricsManager.getInstance().updateConsumer(data.getOperationName(), data.getStatusCode(), - data.getTotalElapsedNanoTime()); - } - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartExecutionEventListener.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartExecutionEventListener.java deleted file mode 100644 index 89ff1b5..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartExecutionEventListener.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core.event; - -import org.apache.servicecomb.core.metrics.InvocationStartExecutionEvent; -import org.apache.servicecomb.foundation.common.event.EventListener; -import org.apache.servicecomb.metrics.core.InvocationMetricsManager; - -public class InvocationStartExecutionEventListener implements EventListener<InvocationStartExecutionEvent> { - @Override - public Class<InvocationStartExecutionEvent> getEventClass() { - return InvocationStartExecutionEvent.class; - } - - @Override - public void process(InvocationStartExecutionEvent data) { - InvocationMetricsManager.getInstance().decrementWaitInQueue(data.getOperationName()); - } -} diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java deleted file mode 100644 index 117387b..0000000 --- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core.event; - -import org.apache.servicecomb.core.metrics.InvocationStartedEvent; -import org.apache.servicecomb.foundation.common.event.EventListener; -import org.apache.servicecomb.metrics.core.InvocationMetricsManager; -import org.apache.servicecomb.swagger.invocation.InvocationType; - -public class InvocationStartedEventListener implements EventListener<InvocationStartedEvent> { - @Override - public Class<InvocationStartedEvent> getEventClass() { - return InvocationStartedEvent.class; - } - - @Override - public void process(InvocationStartedEvent data) { - if (InvocationType.PRODUCER.equals(data.getInvocationType())) { - InvocationMetricsManager.getInstance().incrementWaitInQueue(data.getOperationName()); - } - } -} diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestAnMonitorManager.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestAnMonitorManager.java deleted file mode 100644 index 0fe669a..0000000 --- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestAnMonitorManager.java +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.metrics.core; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.apache.servicecomb.core.metrics.InvocationFinishedEvent; -import org.apache.servicecomb.core.metrics.InvocationStartExecutionEvent; -import org.apache.servicecomb.core.metrics.InvocationStartedEvent; -import org.apache.servicecomb.foundation.common.event.EventBus; -import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; -import org.apache.servicecomb.foundation.metrics.MetricsConst; -import org.apache.servicecomb.foundation.metrics.publish.MetricNode; -import org.apache.servicecomb.foundation.metrics.publish.MetricsLoader; -import org.apache.servicecomb.swagger.invocation.InvocationType; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import com.netflix.servo.monitor.Counter; - -public class TestAnMonitorManager { - - private static MetricsLoader currentWindowMetricsLoader; - - // private static MetricsLoader nextWindowMetricsLoader; - - @BeforeClass - public static void setup() throws InterruptedException { - System.getProperties().setProperty(MetricsConfig.METRICS_WINDOW_TIME, "2000"); - - //========================================================================== - //fun1 is a PRODUCER invocation call 2 time and all is completed - //two time success - EventBus.getInstance().triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime())); - EventBus.getInstance().triggerEvent(new InvocationStartExecutionEvent("fun1")); - EventBus.getInstance() - .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER, TimeUnit.MILLISECONDS.toNanos(100), - TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200)); - - EventBus.getInstance().triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime())); - EventBus.getInstance().triggerEvent(new InvocationStartExecutionEvent("fun1")); - EventBus.getInstance() - .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER, TimeUnit.MILLISECONDS.toNanos(300), - TimeUnit.MILLISECONDS.toNanos(400), TimeUnit.MILLISECONDS.toNanos(700), 200)); - - EventBus.getInstance().triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime())); - EventBus.getInstance().triggerEvent(new InvocationStartExecutionEvent("fun1")); - EventBus.getInstance() - .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER, TimeUnit.MILLISECONDS.toNanos(300), - TimeUnit.MILLISECONDS.toNanos(400), TimeUnit.MILLISECONDS.toNanos(700), 500)); - - //========================================================================== - //fun2 is a CONSUMER invocation call once and completed - EventBus.getInstance() - .triggerEvent(new InvocationFinishedEvent("fun2", InvocationType.CONSUMER, 0, 0, - TimeUnit.MILLISECONDS.toNanos(300), 200)); - - //========================================================================== - //fun3 is a PRODUCER invocation call uncompleted - EventBus.getInstance().triggerEvent(new InvocationStartedEvent("fun3", InvocationType.PRODUCER, System.nanoTime())); - EventBus.getInstance().triggerEvent(new InvocationStartExecutionEvent("fun3")); - - //========================================================================== - //fun4 is a PRODUCER call only started and no processing start and finished - EventBus.getInstance().triggerEvent(new InvocationStartedEvent("fun4", InvocationType.PRODUCER, System.nanoTime())); - - Map<String, Double> metrics = MonitorManager.getInstance().measure(); - currentWindowMetricsLoader = new MetricsLoader(metrics); - - //sim at lease one window time - Thread.sleep(2000); - - metrics = MonitorManager.getInstance().measure(); -// nextWindowMetricsLoader = new MetricsLoader(metrics); - } - - @Test - public void checkFun1WaitInQueue() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node1_queue = node.getChildrenNode("fun1") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_QUEUE); - Assert.assertEquals(0, node1_queue.getMatchStatisticMetricValue("waitInQueue"), 0); - } - - @Test - public void checkFun1Latency() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node1_queue = node.getChildrenNode("fun1") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_QUEUE); - MetricNode node1_queue_status = new MetricNode(node1_queue.getMetrics(), MetricsConst.TAG_STATUS); - Assert.assertEquals(200, - node1_queue_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - Assert.assertEquals(300, - node1_queue_status.getChildrenNode("500").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - - MetricNode node1_exec = node.getChildrenNode("fun1") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_EXECUTION); - MetricNode node1_exec_status = new MetricNode(node1_exec.getMetrics(), MetricsConst.TAG_STATUS); - Assert.assertEquals(300, - node1_exec_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - Assert.assertEquals(400, - node1_exec_status.getChildrenNode("500").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - - MetricNode node1_whole = node.getChildrenNode("fun1") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_TOTAL); - MetricNode node1_whole_status = new MetricNode(node1_whole.getMetrics(), MetricsConst.TAG_STATUS); - Assert.assertEquals(500, - node1_whole_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - Assert.assertEquals(700, - node1_whole_status.getChildrenNode("500").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - } - - @Test - public void checkFun1Count() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node1_whole = node.getChildrenNode("fun1") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_TOTAL); - MetricNode node1_whole_status = new MetricNode(node1_whole.getMetrics(), MetricsConst.TAG_STATUS); - Assert.assertEquals(2, node1_whole_status.getChildrenNode("200").getMatchStatisticMetricValue("count"), 0); - Assert.assertEquals(1, node1_whole_status.getChildrenNode("500").getMatchStatisticMetricValue("count"), 0); - } - - @Test - public void checkFun1Max() { - // MetricNode node = nextWindowMetricsLoader - // .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - // MetricsConst.TAG_STAGE); - // MetricNode node1_queue = node.getChildrenNode("fun1") - // .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - // .getChildrenNode(MetricsConst.STAGE_QUEUE); - // MetricNode node1_queue_status = new MetricNode(node1_queue.getMetrics(), MetricsConst.TAG_STATUS); - // Assert.assertEquals(300, - // node1_queue_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - // Assert.assertEquals(300, - // node1_queue_status.getChildrenNode("500").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - // - // MetricNode node1_exec = node.getChildrenNode("fun1") - // .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - // .getChildrenNode(MetricsConst.STAGE_EXECUTION); - // MetricNode node1_exec_status = new MetricNode(node1_exec.getMetrics(), MetricsConst.TAG_STATUS); - // Assert.assertEquals(400, - // node1_exec_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - // Assert.assertEquals(400, - // node1_exec_status.getChildrenNode("500").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - // - // MetricNode node1_whole = node.getChildrenNode("fun1") - // .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - // .getChildrenNode(MetricsConst.STAGE_TOTAL); - // MetricNode node1_whole_status = new MetricNode(node1_whole.getMetrics(), MetricsConst.TAG_STATUS); - // Assert.assertEquals(700, - // node1_whole_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - // Assert.assertEquals(700, - // node1_whole_status.getChildrenNode("500").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - } - - @Test - public void checkFun1Tps() { - // MetricNode node = nextWindowMetricsLoader - // .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - // MetricsConst.TAG_STAGE); - // MetricNode node1_whole = node.getChildrenNode("fun1") - // .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - // .getChildrenNode(MetricsConst.STAGE_TOTAL); - // MetricNode node1_whole_status = new MetricNode(node1_whole.getMetrics(), MetricsConst.TAG_STATUS); - // Assert.assertEquals(1, node1_whole_status.getChildrenNode("200").getMatchStatisticMetricValue("tps"), 0); - // Assert.assertEquals(0.5, node1_whole_status.getChildrenNode("500").getMatchStatisticMetricValue("tps"), 0); - } - - @Test - public void checkFun2Latency() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node2_whole = node.getChildrenNode("fun2") - .getChildrenNode(String.valueOf(InvocationType.CONSUMER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_TOTAL); - MetricNode node2_whole_status = new MetricNode(node2_whole.getMetrics(), MetricsConst.TAG_STATUS); - Assert.assertEquals(300, - node2_whole_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "latency"), 0); - } - - @Test - public void checkFun2Count() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node2_whole = node.getChildrenNode("fun2") - .getChildrenNode(String.valueOf(InvocationType.CONSUMER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_TOTAL); - MetricNode node2_whole_status = new MetricNode(node2_whole.getMetrics(), MetricsConst.TAG_STATUS); - Assert.assertEquals(1, node2_whole_status.getChildrenNode("200").getMatchStatisticMetricValue("count"), 0); - } - - @Test - public void checkFun2Tps() { - // MetricNode node = nextWindowMetricsLoader - // .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - // MetricsConst.TAG_STAGE); - // MetricNode node2_whole = node.getChildrenNode("fun2") - // .getChildrenNode(String.valueOf(InvocationType.CONSUMER).toLowerCase()) - // .getChildrenNode(MetricsConst.STAGE_TOTAL); - // MetricNode node2_whole_status = new MetricNode(node2_whole.getMetrics(), MetricsConst.TAG_STATUS); - // Assert.assertEquals(0.5, node2_whole_status.getChildrenNode("200").getMatchStatisticMetricValue("tps"), 0); - } - - @Test - public void checkFun2Max() { - // MetricNode node = nextWindowMetricsLoader - // .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - // MetricsConst.TAG_STAGE); - // MetricNode node2_whole = node.getChildrenNode("fun2") - // .getChildrenNode(String.valueOf(InvocationType.CONSUMER).toLowerCase()) - // .getChildrenNode(MetricsConst.STAGE_TOTAL); - // MetricNode node2_whole_status = new MetricNode(node2_whole.getMetrics(), MetricsConst.TAG_STATUS); - // Assert.assertEquals(300, - // node2_whole_status.getChildrenNode("200").getMatchStatisticMetricValue(TimeUnit.MILLISECONDS, "max"), 0); - } - - @Test - public void checkFun3WaitInQueue() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node3_queue = node.getChildrenNode("fun3") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_QUEUE); - Assert.assertEquals(0, node3_queue.getMatchStatisticMetricValue("waitInQueue"), 0); - } - - @Test - public void checkFun4WaitInQueue() { - MetricNode node = currentWindowMetricsLoader - .getMetricTree(MetricsConst.SERVICECOMB_INVOCATION, MetricsConst.TAG_OPERATION, MetricsConst.TAG_ROLE, - MetricsConst.TAG_STAGE); - MetricNode node4_queue = node.getChildrenNode("fun4") - .getChildrenNode(String.valueOf(InvocationType.PRODUCER).toLowerCase()) - .getChildrenNode(MetricsConst.STAGE_QUEUE); - Assert.assertEquals(1, node4_queue.getMatchStatisticMetricValue("waitInQueue"), 0); - } - - @Test - public void checkRegisterMonitorWithoutAnyTags() { - Counter counter = MonitorManager.getInstance().getCounter("MonitorWithoutAnyTag"); - counter.increment(999); - Assert.assertTrue(MonitorManager.getInstance().measure().containsKey("MonitorWithoutAnyTag")); - Assert.assertEquals(999, MonitorManager.getInstance().measure().get("MonitorWithoutAnyTag"), 0); - } - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void checkRegisterMonitor() { - MonitorManager.getInstance().getCounter("Monitor", "X", "Y"); - } - - @Test - public void checkRegisterMonitorWithBadTags() { - thrown.expect(ServiceCombException.class); - MonitorManager.getInstance().getCounter("MonitorWithBadCountTag", "X"); - Assert.fail("checkRegisterMonitorWithBadTags failed"); - } - - @Test - public void checkRegisterMonitorWithBadNameAndTags_ContainLeftParenthesisChar() { - thrown.expect(ServiceCombException.class); - MonitorManager.getInstance().getCounter("MonitorWithBad("); - Assert.fail("checkRegisterMonitorWithBadTags failed : MonitorWithBad("); - } - - @Test - public void checkRegisterMonitorWithBadNameAndTags_ContainCommaChar() { - thrown.expect(ServiceCombException.class); - MonitorManager.getInstance().getCounter("MonitorWithBad,"); - Assert.fail("checkRegisterMonitorWithBadTags failed : MonitorWithBad,"); - } - - @Test - public void checkRegisterMonitorWithBadNameAndTags_ContainEqualChar() { - thrown.expect(ServiceCombException.class); - MonitorManager.getInstance().getCounter("MonitorWithBad", "TagX=", "Y"); - Assert.fail("checkRegisterMonitorWithBadTags failed : name = MonitorWithBad, tags = TagX=,Y"); - } - - @Test - public void checkRegisterMonitorWithBadNameAndTags_ContainRightParenthesisChar() { - thrown.expect(ServiceCombException.class); - MonitorManager.getInstance().getCounter("MonitorWithBad", "TagX", "Y)"); - Assert.fail("checkRegisterMonitorWithBadTags failed : name = MonitorWithBad, tags = TagX,Y)"); - } -} \ No newline at end of file -- To stop receiving notification emails like this one, please contact wuji...@apache.org.