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);
}
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));
}
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);
}
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);
}
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;
}
Aggregations