Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IndexSetValidator #3197

Merged
merged 1 commit into from Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,9 +39,10 @@ public Optional<Violation> validate(IndexSetConfig newConfig) {

// Check if an existing index set has a more generic index prefix.
// Example: new=graylog_foo existing=graylog => graylog is more generic so this is an error
// Example: new=gray existing=graylog => gray is more generic so this is an error
// This avoids problems with wildcard matching like "graylog_*".
for (final IndexSet indexSet : indexSetRegistry) {
if (newConfig.indexPrefix().startsWith(indexSet.getIndexPrefix())) {
if (newConfig.indexPrefix().startsWith(indexSet.getIndexPrefix()) || indexSet.getIndexPrefix().startsWith(newConfig.indexPrefix())) {
return Optional.of(Violation.create("Index prefix \"" + newConfig.indexPrefix() + "\" would conflict with existing index set prefix \"" + indexSet.getIndexPrefix() + "\""));
}
}
Expand Down
Expand Up @@ -81,13 +81,30 @@ public void validateWhenAlreadyManaged() throws Exception {

@Test
public void validateWithConflict() throws Exception {
final String prefix = "graylog_index";
final IndexSetConfig newConfig = mock(IndexSetConfig.class);
final IndexSet indexSet = mock(IndexSet.class);

when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());

// New index prefix starts with existing index prefix
when(indexSet.getIndexPrefix()).thenReturn("graylog");
when(newConfig.indexPrefix()).thenReturn("graylog_index");

final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);

assertThat(violation).isPresent();
}

@Test
public void validateWithConflict2() throws Exception {
final IndexSetConfig newConfig = mock(IndexSetConfig.class);
final IndexSet indexSet = mock(IndexSet.class);

when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
when(newConfig.indexPrefix()).thenReturn(prefix);

// Existing index prefix starts with new index prefix
when(indexSet.getIndexPrefix()).thenReturn("graylog");
when(newConfig.indexPrefix()).thenReturn("gray");

final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);

Expand Down