Search in sources :

Example 1 with MetricGroupId

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);
}
Also used : ServerSentEvent(mantis.io.reactivex.netty.protocol.http.sse.ServerSentEvent) MantisServerSentEvent(io.mantisrx.common.MantisServerSentEvent) Metrics(io.mantisrx.common.metrics.Metrics) Counter(io.mantisrx.common.metrics.Counter) MantisServerSentEvent(io.mantisrx.common.MantisServerSentEvent) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) TestSubscriber(rx.observers.TestSubscriber) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId) TestScheduler(rx.schedulers.TestScheduler) Test(org.junit.Test)

Example 2 with MetricGroupId

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());
}
Also used : Metrics(io.mantisrx.common.metrics.Metrics) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId) Test(org.junit.Test)

Example 3 with MetricGroupId

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;
}
Also used : Query(io.mantisrx.mql.jvm.core.Query) ArrayList(java.util.ArrayList) TaggedData(io.mantisrx.sourcejob.synthetic.core.TaggedData) Metrics(io.mantisrx.common.metrics.Metrics) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId)

Aggregations

Metrics (io.mantisrx.common.metrics.Metrics)3 MetricGroupId (io.mantisrx.common.metrics.spectator.MetricGroupId)3 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 Test (org.junit.Test)2 MantisServerSentEvent (io.mantisrx.common.MantisServerSentEvent)1 Counter (io.mantisrx.common.metrics.Counter)1 Query (io.mantisrx.mql.jvm.core.Query)1 TaggedData (io.mantisrx.sourcejob.synthetic.core.TaggedData)1 ArrayList (java.util.ArrayList)1 ServerSentEvent (mantis.io.reactivex.netty.protocol.http.sse.ServerSentEvent)1 TestSubscriber (rx.observers.TestSubscriber)1 TestScheduler (rx.schedulers.TestScheduler)1