Skip to content

Commit 2774bf4

Browse files
authored
Fix GeoIpDownloaderIT.testInvalidTimestamp (#137663)
The GeoIP expiration logic assumes that the md5 hashes of the databases change over time, as it deletes all database chunks from the .geoip_databases index. If the hashes do not change, no new database chunks are indexed and so the ingest nodes fail to download the databases as there are no chunks to download. In this test suite, we don't have a way to change the database files served by the fixture, and thus change their md5 hashes. Since we assume that in a real-world scenario the database files change over time, we are ok with skipping this part of the test. See #128284 (comment) for a detailed investigation. Closes #128284
1 parent 18968ba commit 2774bf4

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderIT.java

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@
1616
import org.elasticsearch.action.ingest.SimulatePipelineRequest;
1717
import org.elasticsearch.action.ingest.SimulatePipelineResponse;
1818
import org.elasticsearch.client.internal.Client;
19+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1920
import org.elasticsearch.cluster.node.DiscoveryNode;
2021
import org.elasticsearch.common.bytes.BytesReference;
22+
import org.elasticsearch.common.compress.CompressedXContent;
2123
import org.elasticsearch.common.settings.Setting;
2224
import org.elasticsearch.common.settings.Settings;
2325
import org.elasticsearch.core.IOUtils;
2426
import org.elasticsearch.core.SuppressForbidden;
2527
import org.elasticsearch.core.TimeValue;
2628
import org.elasticsearch.env.Environment;
29+
import org.elasticsearch.index.IndexMode;
30+
import org.elasticsearch.index.IndexSettingProvider;
2731
import org.elasticsearch.index.IndexSettings;
32+
import org.elasticsearch.index.IndexVersion;
2833
import org.elasticsearch.index.query.BoolQueryBuilder;
2934
import org.elasticsearch.index.query.MatchQueryBuilder;
3035
import org.elasticsearch.index.query.RangeQueryBuilder;
36+
import org.elasticsearch.indices.IndicesRequestCache;
3137
import org.elasticsearch.ingest.AbstractProcessor;
3238
import org.elasticsearch.ingest.IngestDocument;
3339
import org.elasticsearch.ingest.Processor;
@@ -51,6 +57,7 @@
5157
import java.nio.file.Files;
5258
import java.nio.file.Path;
5359
import java.nio.file.StandardCopyOption;
60+
import java.time.Instant;
5461
import java.util.ArrayList;
5562
import java.util.Collection;
5663
import java.util.HashMap;
@@ -69,6 +76,7 @@
6976
import static org.elasticsearch.ingest.IngestPipelineTestUtils.jsonSimulatePipelineRequest;
7077
import static org.elasticsearch.ingest.geoip.GeoIpTestUtils.copyDefaultDatabases;
7178
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
79+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoSearchHits;
7280
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
7381
import static org.hamcrest.Matchers.allOf;
7482
import static org.hamcrest.Matchers.anEmptyMap;
@@ -78,7 +86,6 @@
7886
import static org.hamcrest.Matchers.equalTo;
7987
import static org.hamcrest.Matchers.hasEntry;
8088
import static org.hamcrest.Matchers.hasItem;
81-
import static org.hamcrest.Matchers.hasItems;
8289
import static org.hamcrest.Matchers.hasKey;
8390
import static org.hamcrest.Matchers.is;
8491
import static org.hamcrest.Matchers.not;
@@ -93,7 +100,8 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
93100
ReindexPlugin.class,
94101
IngestGeoIpPlugin.class,
95102
GeoIpProcessorNonIngestNodeIT.IngestGeoIpSettingsPlugin.class,
96-
NonGeoProcessorsPlugin.class
103+
NonGeoProcessorsPlugin.class,
104+
GeoIpIndexSettingProviderPlugin.class
97105
);
98106
}
99107

@@ -186,6 +194,11 @@ public void testInvalidTimestamp() throws Exception {
186194
}
187195
}
188196
});
197+
// We wait for the deletion of the database chunks in the .geoip_databases index. Since the search request cache is disabled by
198+
// GeoIpIndexSettingProvider, we can be sure that all nodes are unable to fetch the deleted chunks from the cache.
199+
logger.info("---> waiting for database chunks to be deleted");
200+
assertBusy(() -> assertNoSearchHits(prepareSearch(GeoIpDownloader.DATABASES_INDEX).setRequestCache(false)));
201+
logger.info("---> database chunks deleted");
189202
putGeoIpPipeline();
190203
assertBusy(() -> {
191204
SimulateDocumentBaseResult result = simulatePipeline();
@@ -204,19 +217,12 @@ public void testInvalidTimestamp() throws Exception {
204217
assertFalse(result.getIngestDocument().hasField("ip-asn"));
205218
assertFalse(result.getIngestDocument().hasField("ip-country"));
206219
});
207-
updateClusterSettings(Settings.builder().putNull("ingest.geoip.database_validity"));
208-
assertBusy(() -> {
209-
for (Path geoIpTmpDir : geoIpTmpDirs) {
210-
try (Stream<Path> files = Files.list(geoIpTmpDir)) {
211-
Set<String> names = files.map(f -> f.getFileName().toString()).collect(Collectors.toSet());
212-
assertThat(
213-
names,
214-
hasItems("GeoLite2-ASN.mmdb", "GeoLite2-City.mmdb", "GeoLite2-Country.mmdb", "MyCustomGeoLite2-City.mmdb")
215-
);
216-
}
217-
}
218-
});
219-
awaitAllNodesDownloadedDatabases();
220+
// Ideally, we would reset the validity setting to its default value (30d) here and verify that the databases are downloaded again.
221+
// However, this expiration logic assumes that the md5 hashes of the databases change over time, as it deletes all database chunks
222+
// from the .geoip_databases index. If the hashes do not change, no new database chunks are indexed and so the ingest nodes fail
223+
// to download the databases as there are no chunks to download.
224+
// In this test suite, we don't have a way to change the database files served by the fixture, and thus change their md5 hashes.
225+
// Since we assume that in a real world scenario the database files change over time, we are ok with skipping this part of the test.
220226
}
221227

222228
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/92888")
@@ -855,4 +861,37 @@ public String getType() {
855861
return procMap;
856862
}
857863
}
864+
865+
/**
866+
* A simple plugin that provides the {@link GeoIpIndexSettingProvider}.
867+
*/
868+
public static final class GeoIpIndexSettingProviderPlugin extends Plugin {
869+
@Override
870+
public Collection<IndexSettingProvider> getAdditionalIndexSettingProviders(IndexSettingProvider.Parameters parameters) {
871+
return List.of(new GeoIpIndexSettingProvider());
872+
}
873+
}
874+
875+
/**
876+
* An index setting provider that disables the request cache for the `.geoip_databases` index.
877+
* Since `.geoip_databases` is a system index, we can't configure this setting using the API or index templates.
878+
*/
879+
public static final class GeoIpIndexSettingProvider implements IndexSettingProvider {
880+
@Override
881+
public void provideAdditionalSettings(
882+
String indexName,
883+
String dataStreamName,
884+
IndexMode templateIndexMode,
885+
ProjectMetadata projectMetadata,
886+
Instant resolvedAt,
887+
Settings indexTemplateAndCreateRequestSettings,
888+
List<CompressedXContent> combinedTemplateMappings,
889+
IndexVersion indexVersion,
890+
Settings.Builder additionalSettings
891+
) {
892+
if (GeoIpDownloader.GEOIP_DOWNLOADER.equals(indexName)) {
893+
additionalSettings.put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), false);
894+
}
895+
}
896+
}
858897
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ tests:
197197
- class: org.elasticsearch.packaging.test.EnrollmentProcessTests
198198
method: test20DockerAutoFormCluster
199199
issue: https://github.com/elastic/elasticsearch/issues/128113
200-
- class: org.elasticsearch.ingest.geoip.GeoIpDownloaderCliIT
201-
method: testInvalidTimestamp
202-
issue: https://github.com/elastic/elasticsearch/issues/128284
203200
- class: org.elasticsearch.packaging.test.TemporaryDirectoryConfigTests
204201
method: test21AcceptsCustomPathInDocker
205202
issue: https://github.com/elastic/elasticsearch/issues/128114

0 commit comments

Comments
 (0)