use of io.mantisrx.common.metrics.spectator.MetricGroupId in project mantis by Netflix.
the class SseWorkerConnectionTest method testStreamContentDrops.
@Test
public void testStreamContentDrops() throws Exception {
SpectatorRegistryFactory.setRegistry(new DefaultRegistry());
String metricGroupString = "testmetric";
MetricGroupId metricGroupId = new MetricGroupId(metricGroupString);
SseWorkerConnection workerConnection = new SseWorkerConnection("connection_type", "hostname", 80, b -> {
}, b -> {
}, t -> {
}, 600, false, new CopyOnWriteArraySet<>(), 1, null, true, metricGroupId);
HttpClientResponse<ServerSentEvent> response = mock(HttpClientResponse.class);
TestScheduler testScheduler = Schedulers.test();
// Events are just "0", "1", "2", ...
Observable<ServerSentEvent> contentObs = Observable.interval(1, TimeUnit.SECONDS, testScheduler).map(t -> new ServerSentEvent(Unpooled.copiedBuffer(Long.toString(t), Charset.defaultCharset())));
when(response.getContent()).thenReturn(contentObs);
TestSubscriber<MantisServerSentEvent> subscriber = new TestSubscriber<>(1);
workerConnection.streamContent(response, b -> {
}, 600, "delimiter").subscribeOn(testScheduler).subscribe(subscriber);
testScheduler.advanceTimeBy(100, TimeUnit.SECONDS);
subscriber.assertValueCount(1);
List<MantisServerSentEvent> events = subscriber.getOnNextEvents();
assertEquals("0", events.get(0).getEventAsString());
Metrics metrics = MetricsRegistry.getInstance().getMetric(metricGroupId);
Counter onNextCounter = metrics.getCounter(DropOperator.Counters.onNext.toString());
Counter droppedCounter = metrics.getCounter(DropOperator.Counters.dropped.toString());
logger.info("next: {}", onNextCounter.value());
logger.info("drop: {}", droppedCounter.value());
assertTrue(onNextCounter.value() < 10);
assertTrue(droppedCounter.value() > 90);
}
use of io.mantisrx.common.metrics.spectator.MetricGroupId in project mantis by Netflix.
the class DataDroppedPayloadSetterTest method testAggregateDropOperatorMetrics.
@Test
public void testAggregateDropOperatorMetrics() throws Exception {
SpectatorRegistryFactory.setRegistry(new DefaultRegistry());
Heartbeat heartbeat = new Heartbeat("job-1", 1, 1, 1);
DataDroppedPayloadSetter payloadSetter = new DataDroppedPayloadSetter(heartbeat);
Metrics m = new Metrics.Builder().id(METRIC_GROUP + "_" + INCOMING + "_metric1").addCounter(DropOperator.Counters.dropped.toString()).addCounter(DropOperator.Counters.onNext.toString()).build();
m = MetricsRegistry.getInstance().registerAndGet(m);
m.getCounter(DropOperator.Counters.dropped.toString()).increment(1);
m.getCounter(DropOperator.Counters.onNext.toString()).increment(10);
m = new Metrics.Builder().id(METRIC_GROUP + "_" + INCOMING + "_metric2").addCounter(DropOperator.Counters.dropped.toString()).addCounter(DropOperator.Counters.onNext.toString()).build();
m = MetricsRegistry.getInstance().registerAndGet(m);
m.getCounter(DropOperator.Counters.dropped.toString()).increment(100);
m.getCounter(DropOperator.Counters.onNext.toString()).increment(1000);
payloadSetter.setPayload(30);
m = MetricsRegistry.getInstance().getMetric(new MetricGroupId(DATA_DROP_METRIC_GROUP));
assertEquals(101L, m.getGauge(DROP_COUNT).value());
assertEquals(1010, m.getGauge(ON_NEXT_COUNT).value());
}
use of io.mantisrx.common.metrics.spectator.MetricGroupId in project mantis by Netflix.
the class TaggingStage method tagData.
private List<TaggedData> tagData(Map<String, Object> d, Context context) {
List<TaggedData> taggedDataList = new ArrayList<>();
Metrics metrics = context.getMetricsRegistry().getMetric(new MetricGroupId("mql"));
Collection<Query> queries = MQLQueryManager.getInstance().getRegisteredQueries();
Iterator<Query> it = queries.iterator();
while (it.hasNext()) {
Query query = it.next();
try {
if (query.matches(d)) {
Map<String, Object> projected = query.project(d);
projected.put(MANTIS_META_SOURCE_NAME, SYNTHETIC_REQUEST_SOURCE);
projected.put(MANTIS_META_SOURCE_TIMESTAMP, System.currentTimeMillis());
TaggedData tg = new TaggedData(projected);
tg.addMatchedClient(query.getSubscriptionId());
taggedDataList.add(tg);
}
} catch (Exception ex) {
if (ex instanceof ClassNotFoundException) {
log.error("Error loading MQL: " + ex.getMessage());
ex.printStackTrace();
metrics.getCounter(MQL_CLASSLOADER_ERROR).increment();
} else {
ex.printStackTrace();
metrics.getCounter(MQL_FAILURE).increment();
log.error("MQL Error: " + ex.getMessage());
log.error("MQL Query: " + query.getRawQuery());
log.error("MQL Datum: " + d);
}
} catch (Error e) {
metrics.getCounter(MQL_FAILURE).increment();
if (!errorLogged.get()) {
log.error("caught Error when processing MQL {} on {}", query.getRawQuery(), d.toString(), e);
errorLogged.set(true);
}
}
}
return taggedDataList;
}
Aggregations