Search in sources :

Example 16 with ReportSourceTag

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

the class PostSourceTagTimedTask method run.

@Override
public void run() {
    try {
        List<ReportSourceTag> current = createAgentPostBatch();
        batchesSent.inc();
        if (current.size() != 0) {
            TimerContext timerContext = this.batchSendTime.time();
            Response response = null;
            try {
                boolean forceToQueue = false;
                for (ReportSourceTag sourceTag : current) {
                    switch(sourceTag.getSourceTagLiteral()) {
                        case "SourceDescription":
                            if (sourceTag.getAction().equals("delete")) {
                                response = agentAPI.removeDescription(sourceTag.getSource(), token, forceToQueue);
                            } else {
                                response = agentAPI.setDescription(sourceTag.getSource(), token, sourceTag.getDescription(), forceToQueue);
                            }
                            break;
                        case "SourceTag":
                            if (sourceTag.getAction().equals("delete")) {
                                // call the api, if we receive a 406 message then we add them to the queue
                                // TODO: right now it only deletes the first tag (because that server-side api
                                // only handles one tag at a time. Once the server-side api is updated we
                                // should update this code to remove multiple tags at a time.
                                response = agentAPI.removeTag(sourceTag.getSource(), token, sourceTag.getAnnotations().get(0), forceToQueue);
                            } else {
                                // 
                                // call the api, if we receive a 406 message then we add them to the queue
                                response = agentAPI.setTags(sourceTag.getSource(), token, sourceTag.getAnnotations(), forceToQueue);
                            }
                            break;
                        default:
                            logger.warning("None of the literals matched. Expected SourceTag or " + "SourceDescription. Input = " + sourceTag);
                    }
                    this.sourceTagsAttempted.inc();
                    if (response.getStatus() == Response.Status.NOT_ACCEPTABLE.getStatusCode()) {
                        this.sourceTagsQueued.inc();
                        forceToQueue = true;
                    }
                    numApiCalls++;
                }
            } finally {
                timerContext.stop();
                if (response != null)
                    response.close();
            }
            if (sourceTags.size() > getQueuedPointLimit()) {
                if (warningMessageRateLimiter.tryAcquire()) {
                    logger.warning("WF-3 Too many pending points (" + sourceTags.size() + "), block " + "size: " + pointsPerBatch + ". flushing to retry queue");
                }
                drainBuffersToQueue();
            }
        }
    } catch (Throwable t) {
        logger.log(Level.SEVERE, "Unexpected error in flush loop", t);
    } finally {
        scheduler.schedule(this, this.pushFlushInterval, TimeUnit.MILLISECONDS);
    }
}
Also used : Response(javax.ws.rs.core.Response) TimerContext(com.yammer.metrics.core.TimerContext) ReportSourceTag(wavefront.report.ReportSourceTag)

Example 17 with ReportSourceTag

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

the class SourceTagHandlerImpl method reportSourceTags.

/**
 * This method will call the server-side APIs to set/remove the sourceTag/description.
 */
@Override
public void reportSourceTags(List<ReportSourceTag> sourceTags) {
    for (ReportSourceTag reportSourceTag : sourceTags) {
        if (!annotationKeysAreValid(reportSourceTag)) {
            String errorMessage = "WF-600 : SourceTag annotation key has illegal characters.";
            throw new IllegalArgumentException(errorMessage);
        }
        // TODO: validate the sourceTag and call server API: Currently log it
        // TODO: Delete the log lines before checking it in
        logger.info(String.format("Message Type = %s", reportSourceTag.getSourceTagLiteral()));
        logger.info(String.format("Description = %s", reportSourceTag.getDescription()));
        logger.info(String.format("Source = %s", reportSourceTag.getSource()));
        logger.info(String.format("Action = %s", reportSourceTag.getAction()));
        int count = 0;
        if (reportSourceTag.getAnnotations() != null) {
            for (String sourceTag : reportSourceTag.getAnnotations()) {
                logger.info(String.format("Tag[%d] = %s", count++, sourceTag));
            }
        }
        reportSourceTag(reportSourceTag);
    }
}
Also used : ReportSourceTag(wavefront.report.ReportSourceTag)

Example 18 with ReportSourceTag

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

the class ReportSourceTagHandlerTest method testSourceTagsSetting.

/**
 * This test will add 3 source tags and verify that the server side api is called properly.
 */
@Test
public void testSourceTagsSetting() {
    String[] annotations = new String[] { "tag1", "tag2", "tag3" };
    ReportSourceTag sourceTag = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.SAVE, "dummy", Arrays.asList(annotations));
    EasyMock.expect(mockAgentAPI.setTags("dummy", Arrays.asList(annotations))).andReturn(Response.ok().build()).once();
    EasyMock.replay(mockAgentAPI);
    sourceTagHandler.report(sourceTag);
    ((SenderTaskFactoryImpl) senderTaskFactory).flushNow(handlerKey);
    EasyMock.verify(mockAgentAPI);
}
Also used : ReportSourceTag(wavefront.report.ReportSourceTag) Test(org.junit.Test)

Example 19 with ReportSourceTag

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

the class ReportSourceTagHandlerImpl method reportInternal.

@Override
protected void reportInternal(ReportSourceTag sourceTag) {
    if (!annotationsAreValid(sourceTag)) {
        throw new IllegalArgumentException("WF-401: SourceTag annotation key has illegal characters.");
    }
    getTask(sourceTag).add(new SourceTag(sourceTag));
    getReceivedCounter().inc();
}
Also used : SourceTag(com.wavefront.dto.SourceTag) ReportSourceTag(wavefront.report.ReportSourceTag)

Aggregations

ReportSourceTag (wavefront.report.ReportSourceTag)19 Test (org.junit.Test)12 SourceTag (com.wavefront.dto.SourceTag)6 ArrayList (java.util.ArrayList)4 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 TimerContext (com.yammer.metrics.core.TimerContext)1 Response (javax.ws.rs.core.Response)1 Token (org.antlr.v4.runtime.Token)1 ReportEvent (wavefront.report.ReportEvent)1 ReportPoint (wavefront.report.ReportPoint)1 Span (wavefront.report.Span)1 SpanLogs (wavefront.report.SpanLogs)1