Search in sources :

Example 1 with DefaultRegistry

use of com.netflix.spectator.api.DefaultRegistry in project kork by spinnaker.

the class StackdriverWriterTest method testMeasurementsToTimeSeries.

@Test
public void testMeasurementsToTimeSeries() throws IOException {
    Measurement measureAXY = new Measurement(idAXY, clock.monotonicTime(), 1);
    Measurement measureBXY = new Measurement(idBXY, clock.monotonicTime(), 2);
    DefaultRegistry testRegistry = new DefaultRegistry(clock);
    testRegistry.counter(idAXY).increment();
    testRegistry.counter(idBXY).increment(2);
    // Note this writer is still using the mock Monitoring client stub.
    TestableStackdriverWriter spy = spy(new TestableStackdriverWriter(writerConfig.build()));
    Meter counterA = testRegistry.counter(idAXY);
    Meter counterB = testRegistry.counter(idBXY);
    doReturn(new TimeSeries()).when(spy).measurementToTimeSeries(eq(descriptorA.getType()), eq(testRegistry), eq(counterA), eq(measureAXY));
    doReturn(new TimeSeries()).when(spy).measurementToTimeSeries(eq(descriptorB.getType()), eq(testRegistry), eq(counterB), eq(measureBXY));
    // Just testing the call flow produces descriptors since
    // we return empty TimeSeries values.
    spy.registryToTimeSeries(testRegistry);
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Meter(com.netflix.spectator.api.Meter) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Test(org.junit.Test)

Example 2 with DefaultRegistry

use of com.netflix.spectator.api.DefaultRegistry in project kork by spinnaker.

the class StackdriverWriterTest method testAddMeasurementsToTimeSeries.

@Test
public void testAddMeasurementsToTimeSeries() {
    DefaultRegistry testRegistry = new DefaultRegistry(clock);
    long millisA = TimeUnit.MILLISECONDS.convert(1472394975L, TimeUnit.SECONDS);
    long millisB = millisA + 987;
    String timeA = "2016-08-28T14:36:15.000000000Z";
    String timeB = "2016-08-28T14:36:15.987000000Z";
    Meter timerA = testRegistry.timer(idAXY);
    Meter timerB = testRegistry.timer(idBXY);
    Measurement measureAXY = new Measurement(idAXY, millisA, 1);
    Measurement measureBXY = new Measurement(idBXY, millisB, 20.1);
    descriptorRegistrySpy.addExtraTimeSeriesLabel(MetricDescriptorCache.INSTANCE_LABEL, INSTANCE_ID);
    Assert.assertEquals(makeTimeSeries(descriptorA, idAXY, 1, timeA), writer.measurementToTimeSeries(descriptorA.getType(), testRegistry, timerA, measureAXY));
    Assert.assertEquals(makeTimeSeries(descriptorB, idBXY, 20.1, timeB), writer.measurementToTimeSeries(descriptorB.getType(), testRegistry, timerB, measureBXY));
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Meter(com.netflix.spectator.api.Meter) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Test(org.junit.Test)

Example 3 with DefaultRegistry

use of com.netflix.spectator.api.DefaultRegistry in project kork by spinnaker.

the class StackdriverWriterTest method writeRegistryWithLargeRegistry.

@Test
public void writeRegistryWithLargeRegistry() throws IOException {
    TestableStackdriverWriter spy = spy(new TestableStackdriverWriter(writerConfig.build()));
    Monitoring.Projects.TimeSeries.Create mockCreateMethod = Mockito.mock(Monitoring.Projects.TimeSeries.Create.class);
    DefaultRegistry registry = new DefaultRegistry(clock);
    // The contents of this timeseries doesnt matter.
    // It is technically invalid to have null entries in the list,
    // but since we're mocking out the access the values does not matter.
    // What is important is the size of the list, so we can verify chunking.
    List<TimeSeries> tsList = new ArrayList<TimeSeries>();
    for (int i = 0; i < 200; ++i) {
        tsList.add(null);
    }
    // make last one different to test chunking
    tsList.add(new TimeSeries());
    doReturn(tsList).when(spy).registryToTimeSeries(registry);
    // the calls point to the same instance with the final mutated value.
    class MatchN implements ArgumentMatcher<CreateTimeSeriesRequest> {

        public int found = 0;

        private int n;

        public MatchN(int n) {
            super();
            this.n = n;
        }

        @Override
        public String toString() {
            return "Match n=" + n;
        }

        @Override
        public boolean matches(CreateTimeSeriesRequest obj) {
            boolean eq = ((CreateTimeSeriesRequest) obj).getTimeSeries().size() == n;
            found += eq ? 1 : 0;
            return eq;
        }
    }
    ;
    MatchN match200 = new MatchN(200);
    MatchN match1 = new MatchN(1);
    when(timeseriesApi.create(eq("projects/test-project"), argThat(match200))).thenReturn(mockCreateMethod);
    when(timeseriesApi.create(eq("projects/test-project"), argThat(match1))).thenReturn(mockCreateMethod);
    when(mockCreateMethod.execute()).thenReturn(null);
    spy.writeRegistry(registry);
    verify(mockCreateMethod, times(2)).execute();
    Assert.assertEquals(1, match200.found);
    Assert.assertEquals(1, match1.found);
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) ArrayList(java.util.ArrayList) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Monitoring(com.google.api.services.monitoring.v3.Monitoring) Test(org.junit.Test)

Example 4 with DefaultRegistry

use of com.netflix.spectator.api.DefaultRegistry in project iep by Netflix.

the class AwsMetricsModuleTest method withRegistryBinding.

@Test
public void withRegistryBinding() {
    AwsSdkMetrics.setMetricCollector(null);
    Assert.assertFalse(AwsSdkMetrics.getMetricCollector() instanceof SpectatorMetricCollector);
    final Registry registry = new DefaultRegistry();
    Guice.createInjector(new AwsMetricsModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Registry.class).toInstance(registry);
        }
    });
    Assert.assertTrue(AwsSdkMetrics.getMetricCollector() instanceof SpectatorMetricCollector);
}
Also used : SpectatorMetricCollector(com.netflix.spectator.aws.SpectatorMetricCollector) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Registry(com.netflix.spectator.api.Registry) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 5 with DefaultRegistry

use of com.netflix.spectator.api.DefaultRegistry 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)

Aggregations

DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)8 Test (org.junit.Test)6 Monitoring (com.google.api.services.monitoring.v3.Monitoring)2 AbstractModule (com.google.inject.AbstractModule)2 Measurement (com.netflix.spectator.api.Measurement)2 Meter (com.netflix.spectator.api.Meter)2 Registry (com.netflix.spectator.api.Registry)2 EventBus (com.google.common.eventbus.EventBus)1 Injector (com.google.inject.Injector)1 AdminServer (com.netflix.iep.admin.AdminServer)1 CompositeRegistry (com.netflix.spectator.api.CompositeRegistry)1 Counter (com.netflix.spectator.api.Counter)1 ManualClock (com.netflix.spectator.api.ManualClock)1 Timer (com.netflix.spectator.api.Timer)1 SpectatorMetricCollector (com.netflix.spectator.aws.SpectatorMetricCollector)1 ArrayList (java.util.ArrayList)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