use of org.graylog2.plugin.ServerStatus in project graylog2-server by Graylog2.
the class MessageFilterChainProcessorTest method testAllFiltersAreBeingRun.
@Test
public void testAllFiltersAreBeingRun() {
final DummyFilter first = new DummyFilter(10);
final DummyFilter second = new DummyFilter(20);
final DummyFilter third = new DummyFilter(30);
final Set<MessageFilter> filters = ImmutableSet.of(first, second, third);
final MessageFilterChainProcessor processor = new MessageFilterChainProcessor(new MetricRegistry(), filters, acknowledger, serverStatus);
final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
final Message result = Iterables.getFirst(processor.process(message), null);
assertThat(result).isNotNull();
assertThat(result.getFields()).containsKeys("prio-10", "prio-20", "prio-30");
}
use of org.graylog2.plugin.ServerStatus in project graylog2-server by Graylog2.
the class MessageFilterChainProcessorTest method testHandleMessage.
@Test
public void testHandleMessage() {
MessageFilter filterOnlyFirst = new MessageFilter() {
private boolean filterOut = true;
@Override
public boolean filter(Message msg) {
if (filterOut) {
msg.setFilterOut(true);
filterOut = false;
return true;
}
return false;
}
@Override
public String getName() {
return "first filtered out, subsequent pass";
}
@Override
public int getPriority() {
return 0;
}
};
final MessageFilterChainProcessor filterTest = new MessageFilterChainProcessor(new MetricRegistry(), Collections.singleton(filterOnlyFirst), acknowledger, serverStatus);
Message filteredoutMessage = new Message("filtered out", "source", Tools.nowUTC());
filteredoutMessage.setJournalOffset(1);
Message unfilteredMessage = new Message("filtered out", "source", Tools.nowUTC());
final Messages messages1 = filterTest.process(filteredoutMessage);
final Messages messages2 = filterTest.process(unfilteredMessage);
Assert.assertTrue(filteredoutMessage.getFilterOut());
Assert.assertFalse(unfilteredMessage.getFilterOut());
Assert.assertEquals(0, Iterables.size(messages1));
Assert.assertEquals(1, Iterables.size(messages2));
}
use of org.graylog2.plugin.ServerStatus in project graylog2-server by Graylog2.
the class LocalKafkaJournalTest method segmentAgeCleanup.
@Test
public void segmentAgeCleanup() throws Exception {
final InstantMillisProvider clock = new InstantMillisProvider(DateTime.now(DateTimeZone.UTC));
DateTimeUtils.setCurrentMillisProvider(clock);
try {
final Size segmentSize = Size.kilobytes(1L);
final LocalKafkaJournal journal = new LocalKafkaJournal(journalDirectory.toPath(), scheduler, segmentSize, Duration.standardHours(1), Size.kilobytes(10L), Duration.standardMinutes(1), 1_000_000, Duration.standardMinutes(1), 100, new MetricRegistry(), serverStatus);
final File messageJournalDir = new File(journalDirectory, "messagejournal-0");
assertTrue(messageJournalDir.exists());
// we need to fix up the last modified times of the actual files.
long[] lastModifiedTs = new long[2];
// create two chunks, 30 seconds apart
createBulkChunks(journal, segmentSize, 1);
journal.flushDirtyLogs();
lastModifiedTs[0] = clock.getMillis();
clock.tick(Period.seconds(30));
createBulkChunks(journal, segmentSize, 1);
journal.flushDirtyLogs();
lastModifiedTs[1] = clock.getMillis();
int i = 0;
for (final LogSegment segment : journal.getSegments()) {
assertTrue(i < 2);
segment.lastModified_$eq(lastModifiedTs[i]);
i++;
}
int cleanedLogs = journal.cleanupLogs();
assertEquals("no segments should've been cleaned", 0, cleanedLogs);
assertEquals("two segments segment should remain", 2, countSegmentsInDir(messageJournalDir));
// move clock beyond the retention period and clean again
clock.tick(Period.seconds(120));
cleanedLogs = journal.cleanupLogs();
assertEquals("two segments should've been cleaned (only one will actually be removed...)", 2, cleanedLogs);
assertEquals("one segment should remain", 1, countSegmentsInDir(messageJournalDir));
} finally {
DateTimeUtils.setCurrentMillisSystem();
}
}
use of org.graylog2.plugin.ServerStatus in project graylog2-server by Graylog2.
the class LocalKafkaJournalTest method setUp.
@Before
public void setUp() throws IOException {
scheduler = new ScheduledThreadPoolExecutor(1);
scheduler.prestartCoreThread();
journalDirectory = temporaryFolder.newFolder();
final File nodeId = temporaryFolder.newFile("node-id");
Files.write(nodeId.toPath(), UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8));
final Configuration configuration = new Configuration() {
@Override
public String getNodeIdFile() {
return nodeId.getAbsolutePath();
}
};
serverStatus = new ServerStatus(configuration, EnumSet.of(ServerStatus.Capability.SERVER), new EventBus("KafkaJournalTest"), NullAuditEventSender::new);
}
use of org.graylog2.plugin.ServerStatus in project graylog2-server by Graylog2.
the class Server method startNodeRegistration.
@Override
protected void startNodeRegistration(Injector injector) {
// Register this node.
final NodeService nodeService = injector.getInstance(NodeService.class);
final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
final ActivityWriter activityWriter = injector.getInstance(ActivityWriter.class);
final LeaderElectionService leaderElectionService = injector.getInstance(LeaderElectionService.class);
nodeService.registerServer(serverStatus.getNodeId().toString(), leaderElectionService.isLeader(), httpConfiguration.getHttpPublishUri(), Tools.getLocalCanonicalHostname());
serverStatus.setLocalMode(isLocal());
if (leaderElectionService.isLeader() && !nodeService.isOnlyLeader(serverStatus.getNodeId())) {
LOG.warn("Detected another leader in the cluster. Retrying in {} seconds to make sure it is not " + "an old stale instance.", TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleLeaderTimeout()));
try {
Thread.sleep(configuration.getStaleLeaderTimeout());
} catch (InterruptedException e) {
/* nope */
}
if (!nodeService.isOnlyLeader(serverStatus.getNodeId())) {
// All devils here.
String what = "Detected other leader node in the cluster! Starting as non-leader! " + "This is a mis-configuration you should fix.";
LOG.warn(what);
activityWriter.write(new Activity(what, Server.class));
final NotificationService notificationService = injector.getInstance(NotificationService.class);
// remove legacy notification, if present
// noinspection deprecation
notificationService.fixed(notificationService.build().addType(Notification.Type.MULTI_MASTER));
// Write a notification.
Notification notification = notificationService.buildNow().addType(Notification.Type.MULTI_LEADER).addSeverity(Notification.Severity.URGENT);
notificationService.publishIfFirst(notification);
configuration.setIsLeader(false);
} else {
LOG.warn("Stale leader has gone. Starting as leader.");
}
}
}
Aggregations