use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class MemoryAppenderTest method testGetLogMessages.
@Test
public void testGetLogMessages() {
final int bufferSize = 10;
final MemoryAppender appender = MemoryAppender.createAppender(null, null, "memory", String.valueOf(bufferSize), "false");
assertThat(appender).isNotNull();
for (int i = 1; i <= bufferSize; i++) {
final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("test").setLoggerFqcn("com.example.test").setMessage(new SimpleMessage("Message " + i)).build();
appender.append(logEvent);
}
assertThat(appender.getLogMessages(bufferSize * 2)).hasSize(bufferSize);
assertThat(appender.getLogMessages(bufferSize)).hasSize(bufferSize);
assertThat(appender.getLogMessages(bufferSize / 2)).hasSize(bufferSize / 2);
assertThat(appender.getLogMessages(0)).isEmpty();
final List<LogEvent> messages = appender.getLogMessages(5);
for (int i = 0; i < messages.size(); i++) {
assertThat(messages.get(i).getMessage().getFormattedMessage()).isEqualTo("Message " + (bufferSize - i));
}
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class MemoryAppenderTest method appenderCanConsumeMoreMessagesThanBufferSize.
@Test
public void appenderCanConsumeMoreMessagesThanBufferSize() {
final int bufferSize = 10;
final MemoryAppender appender = MemoryAppender.createAppender(null, null, "memory", String.valueOf(bufferSize), "false");
assertThat(appender).isNotNull();
for (int i = 1; i <= bufferSize + 1; i++) {
final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("test").setLoggerFqcn("com.example.test").setMessage(new SimpleMessage("Message " + i)).build();
appender.append(logEvent);
}
final List<LogEvent> messages = appender.getLogMessages(bufferSize);
for (int i = 0; i < messages.size(); i++) {
assertThat(messages.get(i).getMessage().getFormattedMessage()).isEqualTo("Message " + (bufferSize - i + 1));
}
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class V20161116172200_CreateDefaultStreamMigrationTest method upgrade.
@Test
public void upgrade() throws Exception {
final ArgumentCaptor<Stream> streamArgumentCaptor = ArgumentCaptor.forClass(Stream.class);
when(streamService.load("000000000000000000000001")).thenThrow(NotFoundException.class);
when(indexSetRegistry.getDefault()).thenReturn(indexSet);
migration.upgrade();
verify(streamService).save(streamArgumentCaptor.capture());
final Stream stream = streamArgumentCaptor.getValue();
assertThat(stream.getTitle()).isEqualTo("All messages");
assertThat(stream.getDisabled()).isFalse();
assertThat(stream.getMatchingType()).isEqualTo(StreamImpl.MatchingType.DEFAULT);
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class PipelineProcessorMessageDecorator method apply.
@Override
public SearchResponse apply(SearchResponse searchResponse) {
final List<ResultMessageSummary> results = new ArrayList<>();
if (pipelines.isEmpty()) {
return searchResponse;
}
searchResponse.messages().forEach((inMessage) -> {
final Message message = new Message(inMessage.message());
final List<Message> additionalCreatedMessages = pipelineInterpreter.processForPipelines(message, pipelines, new NoopInterpreterListener(), pipelineStateUpdater.getLatestState());
results.add(ResultMessageSummary.create(inMessage.highlightRanges(), message.getFields(), inMessage.index()));
additionalCreatedMessages.forEach((additionalMessage) -> {
// TODO: pass proper highlight ranges. Need to rebuild them for new messages.
results.add(ResultMessageSummary.create(ImmutableMultimap.of(), additionalMessage.getFields(), "[created from decorator]"));
});
});
return searchResponse.toBuilder().messages(results).build();
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class PipelineInterpreter method processForResolvedPipelines.
// Public access is required due to use in the Illuminate processor.
public List<Message> processForResolvedPipelines(Message message, String msgId, Set<Pipeline> pipelines, InterpreterListener interpreterListener, State state) {
final List<Message> result = new ArrayList<>();
// record execution of pipeline in metrics
pipelines.forEach(Pipeline::markExecution);
final StageIterator stages = state.getStageIterator(pipelines);
final Set<Pipeline> pipelinesToSkip = Sets.newHashSet();
// pipeline execution ordering is not guaranteed
while (stages.hasNext()) {
// remaining stages.
if (message.getFilterOut()) {
break;
}
final List<Stage> stageSet = stages.next();
for (final Stage stage : stageSet) {
evaluateStage(stage, message, msgId, result, pipelinesToSkip, interpreterListener);
}
}
// 7. return the processed messages
return result;
}
Aggregations