Search in sources :

Example 6 with JsonProcessingException

use of io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException in project mantis by Netflix.

the class MetricsServer method start.

public void start() {
    final Observable<Measurements> measurements = measurements(publishRateInSeconds);
    logger.info("Starting metrics server on port: " + port);
    server = RxNetty.createHttpServer(port, new RequestHandler<ByteBuf, ServerSentEvent>() {

        @Override
        public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ServerSentEvent> response) {
            final Map<String, List<String>> queryParameters = request.getQueryParameters();
            final List<String> namesToFilter = new LinkedList<>();
            logger.info("got query params {}", queryParameters);
            if (queryParameters != null && queryParameters.containsKey("name")) {
                namesToFilter.addAll(queryParameters.get("name"));
            }
            Observable<Measurements> filteredObservable = measurements.filter(new Func1<Measurements, Boolean>() {

                @Override
                public Boolean call(Measurements measurements) {
                    if (!namesToFilter.isEmpty()) {
                        // check filters
                        for (String name : namesToFilter) {
                            if (name.indexOf('*') != -1) {
                                // check for ends with
                                if (name.indexOf('*') == 0 && measurements.getName().endsWith(name.substring(1)))
                                    return true;
                                // check for starts with
                                if (name.indexOf('*') > 0 && measurements.getName().startsWith(name.substring(0, name.indexOf('*')))) {
                                    return true;
                                }
                            }
                            if (measurements.getName().equals(name)) {
                                // filter match
                                return true;
                            }
                        }
                        // not found in filters
                        return false;
                    } else {
                        // no filters provided
                        return true;
                    }
                }
            });
            return filteredObservable.flatMap(new Func1<Measurements, Observable<Void>>() {

                @Override
                public Observable<Void> call(Measurements metrics) {
                    response.getHeaders().set("Access-Control-Allow-Origin", "*");
                    response.getHeaders().set("content-type", "text/event-stream");
                    ServerSentEvent event = null;
                    try {
                        ByteBuf data = response.getAllocator().buffer().writeBytes((mapper.writeValueAsString(metrics)).getBytes());
                        event = new ServerSentEvent(data);
                    // event = new ServerSentEvent(null, "data", mapper.writeValueAsString(metrics));
                    } catch (JsonProcessingException e) {
                        logger.error("Failed to map metrics to JSON", e);
                    }
                    if (event != null) {
                        response.write(event);
                        return response.writeStringAndFlush("\n");
                    }
                    return null;
                }
            });
        }
    }, PipelineConfigurators.<ByteBuf>serveSseConfigurator()).start();
}
Also used : Measurements(io.mantisrx.common.metrics.measurement.Measurements) ServerSentEvent(mantis.io.reactivex.netty.protocol.http.sse.ServerSentEvent) ByteBuf(io.netty.buffer.ByteBuf) Observable(rx.Observable) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Func1(rx.functions.Func1) Map(java.util.Map) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with JsonProcessingException

use of io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException in project mantis by Netflix.

the class MantisEnvelopeTest method deserTest.

@Test
public void deserTest() {
    String data = "{\"ts\":1571174446676,\"originServer\":\"origin\",\"eventList\":[{\"id\":1,\"data\":\"{\\\"mantisStream\\\":\\\"defaultStream\\\",\\\"matched-clients\\\":[\\\"MantisPushRequestEvents_PushRequestEventSourceJobLocal-1_nj3\\\"],\\\"id\\\":44,\\\"type\\\":\\\"EVENT\\\"}\"}]}";
    final ObjectMapper mapper = new ObjectMapper();
    ObjectReader mantisEventEnvelopeReader = mapper.readerFor(MantisEventEnvelope.class);
    try {
        MantisEventEnvelope envelope = mantisEventEnvelopeReader.readValue(data);
        System.out.println("Envelope=>" + envelope);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ObjectReader(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectReader) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 8 with JsonProcessingException

use of io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException in project mantis by Netflix.

the class DataDroppedPayloadSetter method setPayload.

protected void setPayload(final long intervalSecs) {
    final Collection<Metrics> metrics = MetricsRegistry.getInstance().getMetrics(metricNamePrefix);
    long totalDropped = 0L;
    long totalOnNext = 0L;
    try {
        if (metrics != null && !metrics.isEmpty()) {
            // logger.info("Got " + metrics.size() + " metrics for DropOperator");
            for (Metrics m : metrics) {
                final Counter dropped = m.getCounter("" + DropOperator.Counters.dropped);
                final Counter onNext = m.getCounter("" + DropOperator.Counters.onNext);
                if (dropped != null)
                    totalDropped += dropped.value();
                else
                    logger.warn("Unexpected to get null dropped counter for metric " + m.getMetricGroupId().id());
                if (onNext != null)
                    totalOnNext += onNext.value();
                else
                    logger.warn("Unexpected to get null onNext counter for metric " + m.getMetricGroupId().id());
            }
            final StatusPayloads.DataDropCounts dataDrop = new StatusPayloads.DataDropCounts(totalOnNext, totalDropped);
            try {
                heartbeat.addSingleUsePayload("" + StatusPayloads.Type.IncomingDataDrop, objectMapper.writeValueAsString(dataDrop));
            } catch (JsonProcessingException e) {
                logger.warn("Error writing json for dataDrop payload: " + e.getMessage());
            }
            dropCountGauge.set(dataDrop.getDroppedCount());
            onNextCountGauge.set(dataDrop.getOnNextCount());
        } else
            logger.debug("Got no metrics from DropOperator");
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : Metrics(io.mantisrx.common.metrics.Metrics) Counter(io.mantisrx.common.metrics.Counter) StatusPayloads(io.mantisrx.server.core.StatusPayloads) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)8 ObjectMapper (io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3 List (java.util.List)3 Measurements (io.mantisrx.common.metrics.measurement.Measurements)2 MachineDefinition (io.mantisrx.runtime.MachineDefinition)2 Map (java.util.Map)2 ActorRef (akka.actor.ActorRef)1 ActorSystem (akka.actor.ActorSystem)1 TestKit (akka.testkit.javadsl.TestKit)1 ByteString (com.google.protobuf.ByteString)1 TestHelpers (com.netflix.mantis.master.scheduler.TestHelpers)1 Label (io.mantisrx.common.Label)1 Counter (io.mantisrx.common.metrics.Counter)1 Metrics (io.mantisrx.common.metrics.Metrics)1 GaugeMeasurement (io.mantisrx.common.metrics.measurement.GaugeMeasurement)1 AuditEventSubscriberLoggingImpl (io.mantisrx.master.events.AuditEventSubscriberLoggingImpl)1 LifecycleEventPublisher (io.mantisrx.master.events.LifecycleEventPublisher)1 LifecycleEventPublisherImpl (io.mantisrx.master.events.LifecycleEventPublisherImpl)1 StatusEventSubscriberLoggingImpl (io.mantisrx.master.events.StatusEventSubscriberLoggingImpl)1