1616import org .elasticsearch .action .ingest .SimulatePipelineRequest ;
1717import org .elasticsearch .action .ingest .SimulatePipelineResponse ;
1818import org .elasticsearch .client .internal .Client ;
19+ import org .elasticsearch .cluster .metadata .ProjectMetadata ;
1920import org .elasticsearch .cluster .node .DiscoveryNode ;
2021import org .elasticsearch .common .bytes .BytesReference ;
22+ import org .elasticsearch .common .compress .CompressedXContent ;
2123import org .elasticsearch .common .settings .Setting ;
2224import org .elasticsearch .common .settings .Settings ;
2325import org .elasticsearch .core .IOUtils ;
2426import org .elasticsearch .core .SuppressForbidden ;
2527import org .elasticsearch .core .TimeValue ;
2628import org .elasticsearch .env .Environment ;
29+ import org .elasticsearch .index .IndexMode ;
30+ import org .elasticsearch .index .IndexSettingProvider ;
2731import org .elasticsearch .index .IndexSettings ;
32+ import org .elasticsearch .index .IndexVersion ;
2833import org .elasticsearch .index .query .BoolQueryBuilder ;
2934import org .elasticsearch .index .query .MatchQueryBuilder ;
3035import org .elasticsearch .index .query .RangeQueryBuilder ;
36+ import org .elasticsearch .indices .IndicesRequestCache ;
3137import org .elasticsearch .ingest .AbstractProcessor ;
3238import org .elasticsearch .ingest .IngestDocument ;
3339import org .elasticsearch .ingest .Processor ;
5157import java .nio .file .Files ;
5258import java .nio .file .Path ;
5359import java .nio .file .StandardCopyOption ;
60+ import java .time .Instant ;
5461import java .util .ArrayList ;
5562import java .util .Collection ;
5663import java .util .HashMap ;
6976import static org .elasticsearch .ingest .IngestPipelineTestUtils .jsonSimulatePipelineRequest ;
7077import static org .elasticsearch .ingest .geoip .GeoIpTestUtils .copyDefaultDatabases ;
7178import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
79+ import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertNoSearchHits ;
7280import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertResponse ;
7381import static org .hamcrest .Matchers .allOf ;
7482import static org .hamcrest .Matchers .anEmptyMap ;
7886import static org .hamcrest .Matchers .equalTo ;
7987import static org .hamcrest .Matchers .hasEntry ;
8088import static org .hamcrest .Matchers .hasItem ;
81- import static org .hamcrest .Matchers .hasItems ;
8289import static org .hamcrest .Matchers .hasKey ;
8390import static org .hamcrest .Matchers .is ;
8491import 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}
0 commit comments