Search in sources :

Example 1 with ReportEvent

use of wavefront.report.ReportEvent in project java by wavefrontHQ.

the class WavefrontPortUnificationHandler method processLine.

/**
 * @param ctx      ChannelHandler context (to retrieve remote client's IP in case of errors)
 * @param message  line being processed
 */
@Override
protected void processLine(final ChannelHandlerContext ctx, @Nonnull String message, @Nullable DataFormat format) {
    DataFormat dataFormat = format == null ? DataFormat.autodetect(message) : format;
    switch(dataFormat) {
        case SOURCE_TAG:
            ReportableEntityHandler<ReportSourceTag, SourceTag> sourceTagHandler = sourceTagHandlerSupplier.get();
            if (sourceTagHandler == null || sourceTagDecoder == null) {
                wavefrontHandler.reject(message, "Port is not configured to accept " + "sourceTag-formatted data!");
                return;
            }
            List<ReportSourceTag> output = new ArrayList<>(1);
            try {
                sourceTagDecoder.decode(message, output, "dummy");
                for (ReportSourceTag tag : output) {
                    sourceTagHandler.report(tag);
                }
            } catch (Exception e) {
                sourceTagHandler.reject(message, formatErrorMessage("WF-300 Cannot parse sourceTag: \"" + message + "\"", e, ctx));
            }
            return;
        case EVENT:
            ReportableEntityHandler<ReportEvent, ReportEvent> eventHandler = eventHandlerSupplier.get();
            if (eventHandler == null || eventDecoder == null) {
                wavefrontHandler.reject(message, "Port is not configured to accept event data!");
                return;
            }
            List<ReportEvent> events = new ArrayList<>(1);
            try {
                eventDecoder.decode(message, events, "dummy");
                for (ReportEvent event : events) {
                    eventHandler.report(event);
                }
            } catch (Exception e) {
                eventHandler.reject(message, formatErrorMessage("WF-300 Cannot parse event: \"" + message + "\"", e, ctx));
            }
            return;
        case SPAN:
            ReportableEntityHandler<Span, String> spanHandler = spanHandlerSupplier.get();
            if (spanHandler == null || spanDecoder == null) {
                wavefrontHandler.reject(message, "Port is not configured to accept " + "tracing data (spans)!");
                return;
            }
            message = annotator == null ? message : annotator.apply(ctx, message);
            receivedSpansTotal.get().inc();
            preprocessAndHandleSpan(message, spanDecoder, spanHandler, spanHandler::report, preprocessorSupplier, ctx, span -> sampler.sample(span, discardedSpansBySampler.get()));
            return;
        case SPAN_LOG:
            if (isFeatureDisabled(spanLogsDisabled, SPANLOGS_DISABLED, discardedSpanLogs.get()))
                return;
            ReportableEntityHandler<SpanLogs, String> spanLogsHandler = spanLogsHandlerSupplier.get();
            if (spanLogsHandler == null || spanLogsDecoder == null || spanDecoder == null) {
                wavefrontHandler.reject(message, "Port is not configured to accept " + "tracing data (span logs)!");
                return;
            }
            handleSpanLogs(message, spanLogsDecoder, spanDecoder, spanLogsHandler, preprocessorSupplier, ctx, span -> sampler.sample(span, discardedSpanLogsBySampler.get()));
            return;
        case HISTOGRAM:
            if (isFeatureDisabled(histogramDisabled, HISTO_DISABLED, discardedHistograms.get()))
                return;
            ReportableEntityHandler<ReportPoint, String> histogramHandler = histogramHandlerSupplier.get();
            if (histogramHandler == null || histogramDecoder == null) {
                wavefrontHandler.reject(message, "Port is not configured to accept " + "histogram-formatted data!");
                return;
            }
            message = annotator == null ? message : annotator.apply(ctx, message);
            preprocessAndHandlePoint(message, histogramDecoder, histogramHandler, preprocessorSupplier, ctx, "histogram");
            return;
        default:
            message = annotator == null ? message : annotator.apply(ctx, message);
            preprocessAndHandlePoint(message, wavefrontDecoder, wavefrontHandler, preprocessorSupplier, ctx, "metric");
    }
}
Also used : ArrayList(java.util.ArrayList) ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) SpanLogs(wavefront.report.SpanLogs) SpanUtils.handleSpanLogs(com.wavefront.agent.listeners.tracing.SpanUtils.handleSpanLogs) SpanUtils.preprocessAndHandleSpan(com.wavefront.agent.listeners.tracing.SpanUtils.preprocessAndHandleSpan) Span(wavefront.report.Span) ReportEvent(wavefront.report.ReportEvent) DataFormat(com.wavefront.agent.formatter.DataFormat) ReportSourceTag(wavefront.report.ReportSourceTag) ReportPoint(wavefront.report.ReportPoint)

Example 2 with ReportEvent

use of wavefront.report.ReportEvent in project java by wavefrontHQ.

the class EventHandlerImpl method reportInternal.

@Override
protected void reportInternal(ReportEvent event) {
    if (!annotationKeysAreValid(event)) {
        throw new IllegalArgumentException("WF-401: Event annotation key has illegal characters.");
    }
    getTask().add(new Event(event));
    getReceivedCounter().inc();
    if (validItemsLogger != null && validItemsLogger.isLoggable(Level.FINEST)) {
        validItemsLogger.info(EVENT_SERIALIZER.apply(event));
    }
}
Also used : Event(com.wavefront.dto.Event) ReportEvent(wavefront.report.ReportEvent)

Aggregations

ReportEvent (wavefront.report.ReportEvent)2 DataFormat (com.wavefront.agent.formatter.DataFormat)1 SpanUtils.handleSpanLogs (com.wavefront.agent.listeners.tracing.SpanUtils.handleSpanLogs)1 SpanUtils.preprocessAndHandleSpan (com.wavefront.agent.listeners.tracing.SpanUtils.preprocessAndHandleSpan)1 Event (com.wavefront.dto.Event)1 SourceTag (com.wavefront.dto.SourceTag)1 ArrayList (java.util.ArrayList)1 ReportPoint (wavefront.report.ReportPoint)1 ReportSourceTag (wavefront.report.ReportSourceTag)1 Span (wavefront.report.Span)1 SpanLogs (wavefront.report.SpanLogs)1