Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change rabbit API usage

  • Loading branch information...
commit e462c45aeed3ad53445112a4944516dc931c516f 1 parent 7c734d4
@talya talya authored
View
32 ...lient/src/main/java/com/springsource/insight/plugin/rabbitmqClient/AbstractRabbitMQResourceAnalyzer.java
@@ -47,24 +47,24 @@
protected abstract String getRoutingKey(Operation op);
public EndPointAnalysis locateEndPoint(Trace trace) {
- EndPointAnalysis analysis = null;
Frame frame = trace.getFirstFrameOfType(operationType.getOperationType());
+ if (frame == null) {
+ return null;
+ }
- if (frame != null) {
- Operation op = frame.getOperation();
- if (op != null) {
- String label = buildLabel(op);
- String endPointLabel = RABBIT + "-" + label;
+ Operation op = frame.getOperation();
+ if (op != null) {
+ String label = buildLabel(op);
+ String endPointLabel = RABBIT + "-" + label;
- String example = getExample(label);
- EndPointName endPointName = getName(label);
+ String example = getExample(label);
+ EndPointName endPointName = getName(label);
- TimeRange responseTime = frame.getRange();
- return new EndPointAnalysis(responseTime, endPointName, endPointLabel, example, 0);
- }
+ TimeRange responseTime = frame.getRange();
+ return new EndPointAnalysis(responseTime, endPointName, endPointLabel, example, 0);
}
- return analysis;
+ return null;
}
public List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace) {
@@ -96,7 +96,7 @@ private EndPointName getName(String label) {
}
private String getExample(String label) {
- return operationType.getEndPointPrefix()+label;
+ return operationType.getEndPointPrefix() + label;
}
private String buildLabel(Operation op) {
@@ -120,9 +120,9 @@ private String buildLabel(Operation op) {
return sb.toString();
}
-
+
private static boolean isTrimEmpty(String str){
- return (str == null) || (str.trim().length() == 0);
- }
+ return (str == null) || (str.trim().length() == 0);
+ }
}
View
12 ...-client/src/main/java/com/springsource/insight/plugin/rabbitmqClient/AbstractRabbitMetricsGenerator.java
@@ -24,7 +24,7 @@
import com.springsource.insight.intercept.trace.Trace;
abstract class AbstractRabbitMetricsGenerator extends AbstractMetricsGenerator {
- public static final String RABBIT_COUNT_SUFFIX = "rabbitMQ:type=counter";
+ public static final String RABBIT_COUNT_SUFFIX = ":type=counter";
private RabbitPluginOperationType rabbitOpType;
@@ -34,15 +34,15 @@
}
@Override
- protected void addExtraEndPointMetrics(Trace trace, MetricsBag mb, Boolean atLeastOneExternal) {
- if (atLeastOneExternal){
- addCounterMetricToBag(trace, mb, createMetricKey(), 1);
+ protected void addExtraEndPointMetrics(Trace trace, MetricsBag mb, List<Frame> externalFrames) {
+ if (externalFrames != null && externalFrames.size() > 0){
+ addCounterMetricToBag(trace, mb, createMetricKey(), externalFrames.size());
}
}
@Override
protected void addExtraExternalResourceMetrics(Trace trace, MetricsBag mb) {
- addCounterMetricToBag(trace, mb, createMetricKey(), 1);
+ addCounterMetricToBag(trace, mb, "external-" + createMetricKey(), 1);
}
@Override
@@ -51,6 +51,6 @@ protected void addExtraExternalResourceMetrics(Trace trace, MetricsBag mb) {
}
String createMetricKey() {
- return rabbitOpType.name() + RABBIT_COUNT_SUFFIX;
+ return rabbitOpType.getOperationType().getName() + RABBIT_COUNT_SUFFIX;
}
}
View
47 ...t/src/test/java/com/springsource/insight/plugin/rabbitmqClient/AbstractRabbitMQMetricsGeneratorTest.java
@@ -17,8 +17,6 @@
package com.springsource.insight.plugin.rabbitmqClient;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -60,13 +58,27 @@ public final void testGenerateMetrics() {
AbstractRabbitMetricsGenerator gen = createRabbitMetricsGenerator();
List<MetricsBag> mbs = gen.generateMetrics(trace, ResourceKey.valueOf("EndPoint", "epName"));
- assertNotNull(mbs);
- assertFalse(mbs.isEmpty());
assertEquals(3, mbs.size());
- MetricsBag mb = mbs.get(0);
+ assertExternalResourceMetricBag(gen, mbs.get(0));
+ assertExternalResourceMetricBag(gen, mbs.get(1));
- assertEquals("opExtKey", mb.getResourceKey().getName());
+ List<String> keys;
+ List<IDataPoint> points;
+ MetricsBag mb = mbs.get(2);
+ assertEquals("epName", mb.getResourceKey().getName());
+ keys = mb.getMetricKeys();
+ assertEquals(1, keys.size());
+
+ assertTrue(keys.get(0).equals(gen.createMetricKey()));
+ points = mb.getPoints(gen.createMetricKey());
+ assertEquals(1, points.size());
+ assertEquals(2d , points.get(0).getValue(), 0);
+ }
+
+ private void assertExternalResourceMetricBag(
+ AbstractRabbitMetricsGenerator gen, MetricsBag mb) {
+ assertEquals("opExtKey", mb.getResourceKey().getName());
List<String> keys = mb.getMetricKeys();
assertEquals(3, keys.size());
@@ -80,21 +92,11 @@ public final void testGenerateMetrics() {
assertEquals(1, points.size());
assertEquals(1.0 , points.get(0).getValue(), 0.01);
- assertTrue(keys.get(2).equals(gen.createMetricKey()));
- points = mb.getPoints(gen.createMetricKey());
+ assertTrue(keys.get(2).equals(AbstractRabbitMetricsGenerator.EXTERNAL_METRIC_PREFIX + gen.createMetricKey()));
+ points = mb.getPoints(AbstractRabbitMetricsGenerator.EXTERNAL_METRIC_PREFIX + gen.createMetricKey());
assertEquals(1, points.size());
assertEquals(1d, points.get(0).getValue(), 0);
-
- mb = mbs.get(2);
- assertEquals("epName", mb.getResourceKey().getName());
- keys = mb.getMetricKeys();
- assertEquals(1, keys.size());
-
- assertTrue(keys.get(0).equals(gen.createMetricKey()));
- points = mb.getPoints(gen.createMetricKey());
- assertEquals(1, points.size());
- assertEquals(1d , points.get(0).getValue(), 0);
- }
+ }
@Test
public final void noRabbitFrame() {
@@ -116,12 +118,5 @@ public final void noRabbitFrame() {
return res;
}
-
- Operation createOperation() {
- Operation op = new Operation()
- .type(operationType.getOperationType())
- .label(operationType.getLabel());
- return op;
- }
}
Please sign in to comment.
Something went wrong with that request. Please try again.