use of io.cdap.cdap.api.metrics.MetricsWriter in project cdap by caskdata.
the class MessagingMetricsProcessorManagerService method startUp.
@Override
protected void startUp() throws Exception {
MetricStoreMetricsWriter metricsWriter = new MetricStoreMetricsWriter(metricStore);
DefaultMetricsWriterContext context = new DefaultMetricsWriterContext(metricsContext, cConf, metricsWriter.getID());
metricsWriter.initialize(context);
this.metricsWriters.add(metricsWriter);
for (Map.Entry<String, MetricsWriter> metricsWriterEntry : metricsWriterProvider.loadMetricsWriters().entrySet()) {
MetricsWriter writer = metricsWriterEntry.getValue();
this.metricsWriters.add(writer);
DefaultMetricsWriterContext metricsWriterContext = new DefaultMetricsWriterContext(metricsContext, cConf, writer.getID());
writer.initialize(metricsWriterContext);
}
String processorKey = String.format("metrics.processor.%s", instanceId);
for (MetricsWriter metricsExtension : this.metricsWriters) {
MetricsMetaKeyProvider topicIdMetricsKeyProvider = getKeyProvider(metricsExtension, cConf);
metricsProcessorServices.add(new MessagingMetricsProcessorService(cConf, metricDatasetFactory, messagingService, schemaGenerator, readerFactory, metricsExtension, topicNumbers, metricsContext, metricsProcessIntervalMillis, instanceId, new DefaultMetadataHandler(processorKey, topicIdMetricsKeyProvider), topicIdMetricsKeyProvider));
}
for (MessagingMetricsProcessorService processorService : metricsProcessorServices) {
processorService.startAndWait();
}
}
use of io.cdap.cdap.api.metrics.MetricsWriter in project cdap by caskdata.
the class MetricsWritersMetricsPublisher method initializeMetricWriters.
private void initializeMetricWriters(Map<String, MetricsWriter> metricsWriters, CConfiguration cConf) {
for (Map.Entry<String, MetricsWriter> entry : metricsWriters.entrySet()) {
MetricsWriter writer = entry.getValue();
// Metrics context used by MetricsStoreMetricsWriter only, which we don't use here
// So we can pass no-op context
DefaultMetricsWriterContext metricsWriterContext = new DefaultMetricsWriterContext(new NoopMetricsContext(), cConf, writer.getID());
writer.initialize(metricsWriterContext);
}
}
use of io.cdap.cdap.api.metrics.MetricsWriter in project cdap by caskdata.
the class MetricsWritersMetricsPublisherTest method testPublishingWithoutInitialization.
@Test(expected = IllegalStateException.class)
public void testPublishingWithoutInitialization() throws Exception {
int numWriters = 1;
Map<String, MetricsWriter> writers = getMockWriters(numWriters);
when(provider.loadMetricsWriters()).thenReturn(writers);
CConfiguration cConf = CConfiguration.create();
MetricsWritersMetricsPublisher publisher = new MetricsWritersMetricsPublisher(provider, cConf);
publisher.publish(getMockMetricArray(2), new TreeMap<>());
}
use of io.cdap.cdap.api.metrics.MetricsWriter in project cdap by caskdata.
the class MetricsWritersMetricsPublisherTest method getMockWriters.
private Map<String, MetricsWriter> getMockWriters(int count) {
Map<String, MetricsWriter> writers = new TreeMap<>();
for (int i = 0; i < count; ++i) {
MetricsWriter writer = mock(MetricsWriter.class);
String name = getWriterName(i);
when(writer.getID()).thenReturn(name);
writers.put(name, writer);
}
return writers;
}
use of io.cdap.cdap.api.metrics.MetricsWriter in project cdap by caskdata.
the class MetricsWritersMetricsPublisherTest method testPublishFlow.
@Test
public void testPublishFlow() throws Exception {
int numWriters = 5;
Map<String, MetricsWriter> writers = getMockWriters(numWriters);
when(provider.loadMetricsWriters()).thenReturn(writers);
CConfiguration cConf = CConfiguration.create();
MetricsWritersMetricsPublisher publisher = new MetricsWritersMetricsPublisher(provider, cConf);
publisher.initialize();
// Ensure all writers are initialized
for (Map.Entry<String, MetricsWriter> entry : writers.entrySet()) {
MetricsWriter writer = entry.getValue();
verify(writer, times(1)).initialize(any());
verify(writer, times(0)).write(any());
}
Collection<MetricValues> metricValues = getMockMetricValuesArray(5);
publisher.publish(metricValues);
// Ensure all writers receive the same metrics
for (Map.Entry<String, MetricsWriter> entry : writers.entrySet()) {
MetricsWriter writer = entry.getValue();
verify(writer, times(1)).write(metricValues);
}
// Ensure if one writer throws exception on write(), rest still get metrics
MetricsWriter faultyWriter = writers.get(getWriterName(2));
doThrow(IOException.class).when(faultyWriter).write(metricValues);
publisher.publish(metricValues);
for (Map.Entry<String, MetricsWriter> entry : writers.entrySet()) {
MetricsWriter writer = entry.getValue();
verify(writer, times(2)).write(metricValues);
}
publisher.close();
// Ensure all writers are closed
for (Map.Entry<String, MetricsWriter> entry : writers.entrySet()) {
MetricsWriter writer = entry.getValue();
verify(writer, times(1)).close();
}
}
Aggregations