Search in sources :

Example 1 with CompositeRegistry

use of com.netflix.spectator.api.CompositeRegistry in project incubator-servicecomb-java-chassis by apache.

the class TestPublishModelFactory method prepareRegistry.

protected Registry prepareRegistry() {
    CompositeRegistry globalRegistry = SpectatorUtils.createCompositeRegistry(null);
    Registry registry = new DefaultRegistry(new ManualClock());
    EventBus eventBus = new EventBus();
    DefaultMetricsInitializer metricsInitializer = new DefaultMetricsInitializer() {

        protected Registry createRegistry(MetricsBootstrapConfig config) {
            return registry;
        }
    };
    metricsInitializer.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    new MockUp<System>() {

        @Mock
        long nanoTime() {
            return 10;
        }
    };
    invocationType = InvocationType.CONSUMER;
    new MockUp<Invocation>() {

        @Mock
        InvocationType getInvocationType() {
            return invocationType;
        }

        @Mock
        boolean isConsumer() {
            return InvocationType.CONSUMER.equals(invocationType);
        }

        @Mock
        String getRealTransportName() {
            return Const.RESTFUL;
        }

        @Mock
        String getMicroserviceQualifiedName() {
            return "m.s.o";
        }

        @Mock
        long getStartExecutionTime() {
            return 5;
        }
    };
    new Expectations() {

        {
            response.getStatusCode();
            result = 200;
        }
    };
    InvocationFinishEvent finishEvent = new InvocationFinishEvent(invocation, response);
    eventBus.post(finishEvent);
    invocationType = InvocationType.PRODUCER;
    eventBus.post(finishEvent);
    return registry;
}
Also used : Expectations(mockit.Expectations) ManualClock(com.netflix.spectator.api.ManualClock) InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) MockUp(mockit.MockUp) CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Registry(com.netflix.spectator.api.Registry) EventBus(com.google.common.eventbus.EventBus) DefaultMetricsInitializer(org.apache.servicecomb.metrics.core.DefaultMetricsInitializer)

Example 2 with CompositeRegistry

use of com.netflix.spectator.api.CompositeRegistry in project zuul by Netflix.

the class SpectatorUtils method newGauge.

public static <T extends Number> T newGauge(String name, String id, T number, String... tags) {
    final CompositeRegistry registry = Spectator.globalRegistry();
    Id gaugeId = registry.createId(name, getTagsWithId(id, tags));
    return registry.gauge(gaugeId, number);
}
Also used : CompositeRegistry(com.netflix.spectator.api.CompositeRegistry) Id(com.netflix.spectator.api.Id)

Aggregations

CompositeRegistry (com.netflix.spectator.api.CompositeRegistry)2 EventBus (com.google.common.eventbus.EventBus)1 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)1 Id (com.netflix.spectator.api.Id)1 ManualClock (com.netflix.spectator.api.ManualClock)1 Registry (com.netflix.spectator.api.Registry)1 Expectations (mockit.Expectations)1 MockUp (mockit.MockUp)1 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)1 MetricsBootstrapConfig (org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig)1 DefaultMetricsInitializer (org.apache.servicecomb.metrics.core.DefaultMetricsInitializer)1