Skip to content

Mongodb cluster nodes#24990

Open
todvora wants to merge 70 commits intomasterfrom
feature/mongodb-nodes
Open

Mongodb cluster nodes#24990
todvora wants to merge 70 commits intomasterfrom
feature/mongodb-nodes

Conversation

@todvora
Copy link
Contributor

@todvora todvora commented Feb 12, 2026

/nocl yet
fixes: https://github.com/Graylog2/graylog-plugin-enterprise/issues/13215

Description

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Screenshot 2026-03-12 at 11 36 30

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@tellistone
Copy link

Two bits it would be sweet to get in

  1. a Connections % column
    https://graylog.slack.com/archives/C04K42RQ21W/p1772192589035949

  2. a button to enable/disable the slow query stats for MongoDB
    https://graylog.slack.com/archives/C04K42RQ21W/p1772192728793009

This could copy the form of the enable stats button on the Index Sets page;

image

Could read

Enable MongoDB Slow Logging. Note that Slow Logging has modest ongoing performance cost whilst enabled.

Copy link
Contributor

@moesterheld moesterheld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I really like the InMemorySearchEngine.
I have some comments though and I think we should implement some kind of caching.

Document query = new Document("ts", new Document("$gte", cutoffTime))
.append("millis", new Document("$gte", 100)); // Queries taking more than 100ms

return mongoConnection.getDatabase("admin")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this use graylog's database instead of admin, the doc says this is database specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed

@gally47 gally47 requested a review from a team March 11, 2026 09:19
@gally47 gally47 marked this pull request as ready for review March 11, 2026 09:19
@todvora todvora requested a review from moesterheld March 12, 2026 08:48
Copy link
Contributor Author

@todvora todvora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested frontend and everything seems to be working as expected. Thanks @gally47!

@todvora todvora changed the title WIP: Mongodb cluster nodes Mongodb cluster nodes Mar 12, 2026
Copy link
Contributor

@moesterheld moesterheld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, but I have some comments

public class DefaultMongodbConnectionResolver implements MongodbConnectionResolver {
@Override
public MongoClient resolve(String nodeName) {
return new MongoClient("mongodb://" + nodeName + "/?directConnection=true");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to consider authentication here? would this break if we need credentials for the connection?

.collect(Collectors.toMap(host -> host, host -> runCommand(host, call))))
.orElseGet(() -> {
final String host = connection.getClusterDescription().getServerDescriptions().getFirst().getAddress().toString();
return Collections.singletonMap(host, runCommand(host, (h, c) -> call.apply(h, connection)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be runCommand(host, call) otherwise the call.apply could create a resource leak on error

final Sort sort = createSort(sortField, order);

final int start = page * perPage;
final int end = start + perPage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be offset+page? If page is 1 and perPage is 10, this would retrieve 20 results and then limit that again to perPage using offset?

} else if (operator == SearchQueryOperators.EQUALS) {
return new TermQuery(new Term(fieldName, stringValue));
} else if (operator == SearchQueryOperators.GREATER) {
return TermRangeQuery.newStringRange(fieldName, stringValue, null, false, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TermRangeQuery won't produce correct results for >(=) and <(=) because it does string comparison. should we check if the value is a number first and then do a numeric comparison?

}

public LuceneDocBuilder boolVal(String key, Boolean value) {
return intVal(key, value ? 1 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only method without a null check

return pointsConfig;
}

private static String wrapEmptyQuery(String queryString) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

}

@Nonnull
private StandardQueryParser createQueryParser(Analyzer analyzer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

}

@Nonnull
private Map<String, PointsConfig> getStringPointsConfigMap() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only used in createQueryParser, can be removed

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

return 100.0d * fsUsedSize / fsTotalSize;
}
} catch (Exception e) {
// Stats may not be available or accessible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we log this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants