Search in sources :

Example 1 with DefaultPublishModel

use of org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel in project incubator-servicecomb-java-chassis by apache.

the class TestDefaultLogPublisher method onPolledEvent.

@Test
public void onPolledEvent(@Mocked VertxImplEx vertxImplEx) {
    new Expectations(VertxUtils.class) {

        {
            VertxUtils.getVertxMap();
            result = Collections.singletonMap("v", vertxImplEx);
            vertxImplEx.getEventLoopContextCreatedCount();
            result = 1;
        }
    };
    DefaultPublishModel model = new DefaultPublishModel();
    PerfInfo perfTotal = new PerfInfo();
    perfTotal.setTps(10);
    perfTotal.setMsTotalTime(100);
    OperationPerf operationPerf = new OperationPerf();
    operationPerf.setOperation("op");
    operationPerf.getStages().put(MeterInvocationConst.STAGE_TOTAL, perfTotal);
    operationPerf.getStages().put(MeterInvocationConst.STAGE_EXECUTOR_QUEUE, perfTotal);
    operationPerf.getStages().put(MeterInvocationConst.STAGE_EXECUTION, perfTotal);
    OperationPerfGroup operationPerfGroup = new OperationPerfGroup(Const.RESTFUL, Status.OK.name());
    operationPerfGroup.addOperationPerf(operationPerf);
    OperationPerfGroups operationPerfGroups = new OperationPerfGroups();
    operationPerfGroups.getGroups().put(operationPerfGroup.getTransport(), Collections.singletonMap(operationPerfGroup.getStatus(), operationPerfGroup));
    model.getConsumer().setOperationPerfGroups(operationPerfGroups);
    model.getProducer().setOperationPerfGroups(operationPerfGroups);
    new MockUp<PublishModelFactory>() {

        @Mock
        DefaultPublishModel createDefaultPublishModel() {
            return model;
        }
    };
    publisher.onPolledEvent(new PolledEvent(Collections.emptyList()));
    List<LoggingEvent> events = collector.getEvents().stream().filter(e -> {
        return DefaultLogPublisher.class.getName().equals(e.getLoggerName());
    }).collect(Collectors.toList());
    LoggingEvent event = events.get(0);
    Assert.assertEquals("\n" + "vertx:\n" + "  name       eventLoopContext-created\n" + "  v          1\n" + "consumer:\n" + "  tps     latency(ms) max-latency(ms) operation\n" + "  rest.OK:\n" + "  10      10.000      0.000           op\n" + "  10      10.000      0.000           \n" + "producer:\n" + "  tps     latency(ms) max-latency(ms) queue(ms) max-queue(ms) execute(ms) max-execute(ms) operation\n" + "  rest.OK:\n" + "  10      10.000      0.000           10.000    0.000         10.000      0.000           op\n" + "  10      10.000      0.000           10.000    0.000         10.000      0.000           \n" + "", event.getMessage());
}
Also used : Expectations(mockit.Expectations) LoggingEvent(org.apache.log4j.spi.LoggingEvent) OperationPerfGroup(org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerfGroup) CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) Expectations(mockit.Expectations) ArchaiusUtils(org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils) DefaultPublishModel(org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel) MeterInvocationConst(org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst) PerfInfo(org.apache.servicecomb.metrics.core.publish.model.invocation.PerfInfo) VertxImplEx(io.vertx.core.impl.VertxImplEx) MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) EventBus(com.google.common.eventbus.EventBus) OperationPerfGroups(org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerfGroups) VertxUtils(org.apache.servicecomb.foundation.vertx.VertxUtils) After(org.junit.After) Mock(mockit.Mock) PolledEvent(org.apache.servicecomb.foundation.metrics.PolledEvent) OperationPerf(org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerf) Status(javax.ws.rs.core.Response.Status) Before(org.junit.Before) LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) MockUp(mockit.MockUp) Const(org.apache.servicecomb.core.Const) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) Holder(javax.xml.ws.Holder) Assert(org.junit.Assert) Collections(java.util.Collections) Mocked(mockit.Mocked) OperationPerfGroups(org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerfGroups) PolledEvent(org.apache.servicecomb.foundation.metrics.PolledEvent) OperationPerf(org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerf) DefaultPublishModel(org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel) MockUp(mockit.MockUp) PerfInfo(org.apache.servicecomb.metrics.core.publish.model.invocation.PerfInfo) OperationPerfGroup(org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPerfGroup) Test(org.junit.Test)

Example 2 with DefaultPublishModel

use of org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel in project incubator-servicecomb-java-chassis by apache.

the class DefaultLogPublisher method printLog.

protected void printLog(List<Meter> meters) {
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    printVertxMetrics(sb);
    PublishModelFactory factory = new PublishModelFactory(meters);
    DefaultPublishModel model = factory.createDefaultPublishModel();
    printConsumerLog(model, sb);
    printProducerLog(model, sb);
    LOGGER.info(sb.toString());
}
Also used : DefaultPublishModel(org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel)

Example 3 with DefaultPublishModel

use of org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel in project incubator-servicecomb-java-chassis by apache.

the class PublishModelFactory method createDefaultPublishModel.

public DefaultPublishModel createDefaultPublishModel() {
    DefaultPublishModel model = new DefaultPublishModel();
    model.getConsumer().setOperationPerfGroups(generateOperationPerfGroups(tree, InvocationType.CONSUMER.name()));
    model.getProducer().setOperationPerfGroups(generateOperationPerfGroups(tree, InvocationType.PRODUCER.name()));
    return model;
}
Also used : DefaultPublishModel(org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel)

Example 4 with DefaultPublishModel

use of org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel in project incubator-servicecomb-java-chassis by apache.

the class TestPublishModelFactory method createDefaultPublishModel.

@Test
public void createDefaultPublishModel() throws JsonProcessingException {
    Registry registry = prepareRegistry();
    List<Meter> meters = Lists.newArrayList(registry);
    PublishModelFactory factory = new PublishModelFactory(meters);
    DefaultPublishModel model = factory.createDefaultPublishModel();
    Assert.assertEquals("{\"consumer\":{\"operationPerfGroups\":{\"groups\":{\"rest\":{\"200\":{\"transport\":\"rest\",\"status\":\"200\",\"operationPerfs\":[{\"operation\":\"m.s.o\",\"stages\":{\"total\":{\"tps\":1,\"msTotalTime\":10000.0,\"msMaxLatency\":0.0}}}],\"summary\":{\"operation\":\"\",\"stages\":{\"total\":{\"tps\":1,\"msTotalTime\":10000.0,\"msMaxLatency\":0.0}}}}}}}},\"producer\":{\"operationPerfGroups\":{\"groups\":{\"rest\":{\"200\":{\"transport\":\"rest\",\"status\":\"200\",\"operationPerfs\":[{\"operation\":\"m.s.o\",\"stages\":{\"execution\":{\"tps\":1,\"msTotalTime\":5000.0,\"msMaxLatency\":0.0},\"total\":{\"tps\":1,\"msTotalTime\":10000.0,\"msMaxLatency\":0.0},\"queue\":{\"tps\":1,\"msTotalTime\":5000.0,\"msMaxLatency\":0.0}}}],\"summary\":{\"operation\":\"\",\"stages\":{\"execution\":{\"tps\":1,\"msTotalTime\":5000.0,\"msMaxLatency\":0.0},\"total\":{\"tps\":1,\"msTotalTime\":10000.0,\"msMaxLatency\":0.0},\"queue\":{\"tps\":1,\"msTotalTime\":5000.0,\"msMaxLatency\":0.0}}}}}}}}}", JsonUtils.writeValueAsString(model));
}
Also used : Meter(com.netflix.spectator.api.Meter) DefaultPublishModel(org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel) CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Registry(com.netflix.spectator.api.Registry) Test(org.junit.Test)

Aggregations

DefaultPublishModel (org.apache.servicecomb.metrics.core.publish.model.DefaultPublishModel)4 CompositeRegistry (com.netflix.spectator.api.CompositeRegistry)2 Test (org.junit.Test)2 EventBus (com.google.common.eventbus.EventBus)1 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)1 Meter (com.netflix.spectator.api.Meter)1 Registry (com.netflix.spectator.api.Registry)1 VertxImplEx (io.vertx.core.impl.VertxImplEx)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Status (javax.ws.rs.core.Response.Status)1 Holder (javax.xml.ws.Holder)1 Expectations (mockit.Expectations)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 Mocked (mockit.Mocked)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 Const (org.apache.servicecomb.core.Const)1 MetricsBootstrapConfig (org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig)1