You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2018/03/31 07:17:21 UTC
[incubator-servicecomb-java-chassis] 03/07: SCB-384 define publish
model
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 44ba7329d61dd28bb1390864d33874fd240df143
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Mar 23 16:43:42 2018 +0800
SCB-384 define publish model
---
.../core/publish/model/ConsumerPublishModel.java | 31 ++++++++
.../core/publish/model/DefaultPublishModel.java | 31 ++++++++
.../core/publish/model/ProducerPublishModel.java | 31 ++++++++
.../publish/model/invocation/OperationPerf.java | 56 ++++++++++++++
.../model/invocation/OperationPerfGroup.java | 61 ++++++++++++++++
.../model/invocation/OperationPerfGroups.java | 34 +++++++++
.../core/publish/model/invocation/PerfInfo.java | 68 +++++++++++++++++
.../model/invocation/TestOperationPerf.java | 47 ++++++++++++
.../model/invocation/TestOperationPerfGroup.java | 60 +++++++++++++++
.../publish/model/invocation/TestPerfInfo.java | 85 ++++++++++++++++++++++
.../core/publish/model/invocation/Utils.java | 71 ++++++++++++++++++
11 files changed, 575 insertions(+)
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/ConsumerPublishModel.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/ConsumerPublishModel.java
new file mode 100644
index 0000000..22e40bd
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/ConsumerPublishModel.java
@@ -0,0 +1,31 @@
+/*
+ * 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.publish.model;
+
+import org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerfGroups;
+
+public class ConsumerPublishModel {
+ private OperationPerfGroups operationPerfGroups;
+
+ public OperationPerfGroups getOperationPerfGroups() {
+ return operationPerfGroups;
+ }
+
+ public void setOperationPerfGroups(OperationPerfGroups operationPerfGroups) {
+ this.operationPerfGroups = operationPerfGroups;
+ }
+}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/DefaultPublishModel.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/DefaultPublishModel.java
new file mode 100644
index 0000000..8258425
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/DefaultPublishModel.java
@@ -0,0 +1,31 @@
+/*
+ * 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.publish.model;
+
+public class DefaultPublishModel {
+ private ConsumerPublishModel consumer = new ConsumerPublishModel();
+
+ private ProducerPublishModel producer = new ProducerPublishModel();
+
+ public ConsumerPublishModel getConsumer() {
+ return consumer;
+ }
+
+ public ProducerPublishModel getProducer() {
+ return producer;
+ }
+}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/ProducerPublishModel.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/ProducerPublishModel.java
new file mode 100644
index 0000000..d02c986
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/ProducerPublishModel.java
@@ -0,0 +1,31 @@
+/*
+ * 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.publish.model;
+
+import org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerfGroups;
+
+public class ProducerPublishModel {
+ private OperationPerfGroups operationPerfGroups;
+
+ public OperationPerfGroups getOperationPerfGroups() {
+ return operationPerfGroups;
+ }
+
+ public void setOperationPerfGroups(OperationPerfGroups operationPerfGroups) {
+ this.operationPerfGroups = operationPerfGroups;
+ }
+}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerf.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerf.java
new file mode 100644
index 0000000..4679d9c
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerf.java
@@ -0,0 +1,56 @@
+/*
+ * 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.publish.model.invocation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class OperationPerf {
+ private String operation;
+
+ private Map<String, PerfInfo> stages = new HashMap<>();
+
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ public Map<String, PerfInfo> getStages() {
+ return stages;
+ }
+
+ public void setStages(Map<String, PerfInfo> stages) {
+ this.stages = stages;
+ }
+
+ public PerfInfo findStage(String stage) {
+ return stages.get(stage);
+ }
+
+ public void add(OperationPerf operationPerf) {
+ for (Entry<String, PerfInfo> entry : operationPerf.stages.entrySet()) {
+ PerfInfo perfInfo = stages.computeIfAbsent(entry.getKey(), n -> {
+ return new PerfInfo();
+ });
+ perfInfo.add(entry.getValue());
+ }
+ }
+}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerfGroup.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerfGroup.java
new file mode 100644
index 0000000..01e0fb8
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerfGroup.java
@@ -0,0 +1,61 @@
+/*
+ * 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.publish.model.invocation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class OperationPerfGroup {
+ private String transport;
+
+ private String status;
+
+ private List<OperationPerf> operationPerfs = new ArrayList<>();
+
+ private OperationPerf summary;
+
+ public OperationPerfGroup(String transport, String status) {
+ this.transport = transport;
+ this.status = status;
+ }
+
+ public String getTransport() {
+ return transport;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public List<OperationPerf> getOperationPerfs() {
+ return operationPerfs;
+ }
+
+ public OperationPerf getSummary() {
+ return summary;
+ }
+
+ public void addOperationPerf(OperationPerf operationPerf) {
+ operationPerfs.add(operationPerf);
+
+ if (summary == null) {
+ summary = new OperationPerf();
+ summary.setOperation("");
+ }
+ summary.add(operationPerf);
+ }
+}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerfGroups.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerfGroups.java
new file mode 100644
index 0000000..addef3f
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/OperationPerfGroups.java
@@ -0,0 +1,34 @@
+/*
+ * 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.publish.model.invocation;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OperationPerfGroups {
+ // first key: transport
+ // second key: statusCode
+ private Map<String, Map<String, OperationPerfGroup>> groups = new HashMap<>();
+
+ public Map<String, Map<String, OperationPerfGroup>> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Map<String, Map<String, OperationPerfGroup>> groups) {
+ this.groups = groups;
+ }
+}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/PerfInfo.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/PerfInfo.java
new file mode 100644
index 0000000..6ab8b4d
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/publish/model/invocation/PerfInfo.java
@@ -0,0 +1,68 @@
+/*
+ * 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.publish.model.invocation;
+
+public class PerfInfo {
+ private int tps;
+
+ private double msTotalTime;
+
+ private double msMaxLatency;
+
+ public int getTps() {
+ return tps;
+ }
+
+ public void setTps(int tps) {
+ this.tps = tps;
+ }
+
+ public double getMsTotalTime() {
+ return msTotalTime;
+ }
+
+ public void setMsTotalTime(double msTotalTime) {
+ this.msTotalTime = msTotalTime;
+ }
+
+ public double getMsMaxLatency() {
+ return msMaxLatency;
+ }
+
+ public void setMsMaxLatency(double msMaxLatency) {
+ this.msMaxLatency = msMaxLatency;
+ }
+
+ public void add(PerfInfo other) {
+ tps += other.tps;
+ msTotalTime += other.msTotalTime;
+ if (msMaxLatency < other.msMaxLatency) {
+ msMaxLatency = other.msMaxLatency;
+ }
+ }
+
+ public double calcMsLatency() {
+ return (tps != 0) ? msTotalTime / tps : 0;
+ }
+
+ @Override
+ public String toString() {
+ return "PerfInfo [tps=" + tps + ", msTotalTime=" + msTotalTime + ", msLatency=" + calcMsLatency()
+ + ", msMaxLatency="
+ + msMaxLatency + "]";
+ }
+}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerf.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerf.java
new file mode 100644
index 0000000..ef7af23
--- /dev/null
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerf.java
@@ -0,0 +1,47 @@
+/*
+ * 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.publish.model.invocation;
+
+import org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestOperationPerf {
+ String op = "op";
+
+ OperationPerf opPerf = new OperationPerf();
+
+ @Test
+ public void add() {
+ Assert.assertTrue(opPerf.getStages().isEmpty());
+
+ OperationPerf otherOpPerf = Utils.createOperationPerf(op);
+ opPerf.add(otherOpPerf);
+
+ Assert.assertEquals(op, otherOpPerf.getOperation());
+
+ PerfInfo perfInfo = opPerf.findStage(MeterInvocationConst.STAGE_TOTAL);
+ Assert.assertEquals(10, perfInfo.getTps());
+ Assert.assertEquals(1000, perfInfo.calcMsLatency(), 0);
+ Assert.assertEquals(100000, perfInfo.getMsMaxLatency(), 0);
+
+ perfInfo = opPerf.findStage(MeterInvocationConst.STAGE_EXECUTION);
+ Assert.assertEquals(10, perfInfo.getTps());
+ Assert.assertEquals(1000, perfInfo.calcMsLatency(), 0);
+ Assert.assertEquals(100000, perfInfo.getMsMaxLatency(), 0);
+ }
+}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java
new file mode 100644
index 0000000..f3655fa
--- /dev/null
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java
@@ -0,0 +1,60 @@
+/*
+ * 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.publish.model.invocation;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestOperationPerfGroup {
+ String op = "op";
+
+ OperationPerfGroup group = new OperationPerfGroup(Const.RESTFUL, Status.OK.name());
+
+ @Test
+ public void construct() {
+ Assert.assertEquals(Const.RESTFUL, group.getTransport());
+ Assert.assertEquals(Status.OK.name(), group.getStatus());
+ Assert.assertTrue(group.getOperationPerfs().isEmpty());
+ Assert.assertNull(group.getSummary());
+ }
+
+ @Test
+ public void addOperationPerf() {
+ OperationPerf opPerf = Utils.createOperationPerf(op);
+ group.addOperationPerf(opPerf);
+ group.addOperationPerf(opPerf);
+
+ Assert.assertThat(group.getOperationPerfs(), Matchers.contains(opPerf, opPerf));
+
+ OperationPerf summary = group.getSummary();
+
+ PerfInfo perfInfo = summary.findStage(MeterInvocationConst.STAGE_TOTAL);
+ Assert.assertEquals(20, perfInfo.getTps());
+ Assert.assertEquals(1000, perfInfo.calcMsLatency(), 0);
+ Assert.assertEquals(100000, perfInfo.getMsMaxLatency(), 0);
+
+ perfInfo = summary.findStage(MeterInvocationConst.STAGE_EXECUTION);
+ Assert.assertEquals(20, perfInfo.getTps());
+ Assert.assertEquals(1000, perfInfo.calcMsLatency(), 0);
+ Assert.assertEquals(100000, perfInfo.getMsMaxLatency(), 0);
+ }
+}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestPerfInfo.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestPerfInfo.java
new file mode 100644
index 0000000..ce147e6
--- /dev/null
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestPerfInfo.java
@@ -0,0 +1,85 @@
+/*
+ * 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.publish.model.invocation;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestPerfInfo {
+ @Test
+ public void construct() {
+ PerfInfo perf = new PerfInfo();
+
+ Assert.assertEquals(0, perf.getTps());
+ Assert.assertEquals(0, perf.getMsTotalTime(), 0);
+ Assert.assertEquals(0, perf.getMsMaxLatency(), 0);
+ Assert.assertEquals(0, perf.calcMsLatency(), 0);
+ }
+
+ @Test
+ public void add_changeMax() {
+ PerfInfo sum = new PerfInfo();
+
+ PerfInfo other = new PerfInfo();
+ other.setTps(10);
+ other.setMsTotalTime(10);
+ other.setMsMaxLatency(100);
+ sum.add(other);
+
+ other = new PerfInfo();
+ other.setTps(20);
+ other.setMsTotalTime(20);
+ other.setMsMaxLatency(200);
+ sum.add(other);
+
+ Assert.assertEquals(30, sum.getTps());
+ Assert.assertEquals(30, sum.getMsTotalTime(), 0);
+ Assert.assertEquals(200, sum.getMsMaxLatency(), 0);
+ Assert.assertEquals(1.0, sum.calcMsLatency(), 0);
+ }
+
+ @Test
+ public void add_notChangeMax() {
+ PerfInfo sum = new PerfInfo();
+
+ PerfInfo other = new PerfInfo();
+ other.setTps(10);
+ other.setMsTotalTime(10);
+ other.setMsMaxLatency(100);
+ sum.add(other);
+
+ other = new PerfInfo();
+ other.setTps(20);
+ other.setMsTotalTime(20);
+ other.setMsMaxLatency(50);
+ sum.add(other);
+
+ Assert.assertEquals(30, sum.getTps());
+ Assert.assertEquals(1.0, sum.calcMsLatency(), 0);
+ Assert.assertEquals(100, sum.getMsMaxLatency(), 0);
+ }
+
+ @Test
+ public void testToString() {
+ PerfInfo perf = new PerfInfo();
+ perf.setTps(10);
+ perf.setMsTotalTime(10);
+ perf.setMsMaxLatency(100);
+
+ Assert.assertEquals("PerfInfo [tps=10, msTotalTime=10.0, msLatency=1.0, msMaxLatency=100.0]", perf.toString());
+ }
+}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/Utils.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/Utils.java
new file mode 100644
index 0000000..ec2f770
--- /dev/null
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/Utils.java
@@ -0,0 +1,71 @@
+/*
+ * 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.publish.model.invocation;
+
+import java.util.HashMap;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.servicecomb.foundation.metrics.publish.spectator.MeasurementNode;
+import org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst;
+import org.apache.servicecomb.metrics.core.publish.PublishUtils;
+
+import com.netflix.spectator.api.DefaultRegistry;
+import com.netflix.spectator.api.Id;
+import com.netflix.spectator.api.Measurement;
+import com.netflix.spectator.api.Registry;
+import com.netflix.spectator.api.Statistic;
+
+public class Utils {
+ static Registry registry = new DefaultRegistry();
+
+ public static MeasurementNode totalStageNode = Utils.createStageNode(MeterInvocationConst.STAGE_TOTAL, 10, 10, 100);
+
+ public static MeasurementNode executeStageNode =
+ Utils.createStageNode(MeterInvocationConst.STAGE_EXECUTION, 10, 10, 100);
+
+ public static MeasurementNode createStageNode(String stage,
+ double count,
+ double totalTime,
+ double max) {
+ Id id = registry.createId("id").withTag(Statistic.count);
+ Measurement countMeasurement = new Measurement(id.withTag(Statistic.count), 0, count);
+ Measurement totalTimeMeasurement = new Measurement(id.withTag(Statistic.totalTime), 0, totalTime);
+ Measurement maxMeasurement = new Measurement(id.withTag(Statistic.max), 0, max);
+
+ MeasurementNode stageNode = new MeasurementNode(stage, null);
+ stageNode.addChild(Statistic.count.name(), countMeasurement);
+ stageNode.addChild(Statistic.totalTime.name(), totalTimeMeasurement);
+ stageNode.addChild(Statistic.max.name(), maxMeasurement);
+
+ return stageNode;
+ }
+
+ public static MeasurementNode createStatusNode(String status, MeasurementNode... stageNodes) {
+ MeasurementNode statusNode = new MeasurementNode(status, new HashMap<>());
+
+ for (MeasurementNode stageNode : stageNodes) {
+ statusNode.getChildren().put(stageNode.getName(), stageNode);
+ }
+ return statusNode;
+ }
+
+ public static OperationPerf createOperationPerf(String op) {
+ MeasurementNode statusNode = createStatusNode(Status.OK.name(), totalStageNode, executeStageNode);
+ return PublishUtils.createOperationPerf(op, statusNode);
+ }
+}
--
To stop receiving notification emails like this one, please contact
wujimin@apache.org.