From 2717cda7a8702019261637cdbf1eb0c026a4b4e7 Mon Sep 17 00:00:00 2001 From: Simon Dumas Date: Wed, 13 Mar 2024 17:41:07 +0100 Subject: [PATCH] Don't start an Elasticsearch container when running MainSuite --- .../ch/epfl/bluebrain/nexus/delta/MainSuite.scala | 11 ++++------- .../elasticsearch/ElasticSearchPluginModule.scala | 3 ++- .../elasticsearch/EventMetricsProjection.scala | 12 ++++++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/MainSuite.scala b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/MainSuite.scala index 26bc4c28c8..33a0b4ddba 100644 --- a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/MainSuite.scala +++ b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/MainSuite.scala @@ -7,7 +7,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.plugin.PluginDef import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.Doobie._ import ch.epfl.bluebrain.nexus.delta.wiring.DeltaModule import ch.epfl.bluebrain.nexus.testkit.config.SystemPropertyOverride -import ch.epfl.bluebrain.nexus.testkit.elasticsearch.ElasticSearchContainer import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite import ch.epfl.bluebrain.nexus.testkit.postgres.PostgresContainer import com.typesafe.config.impl.ConfigImpl @@ -73,7 +72,7 @@ object MainSuite { trait Fixture { self: CatsEffectSuite => // Overload config via system properties - private def initConfig(postgres: PostgresContainer, elastic: ElasticSearchContainer): IO[Map[String, String]] = + private def initConfig(postgres: PostgresContainer): IO[Map[String, String]] = IO.blocking { val resourceTypesFile = Files.createTempFile("resource-types", ".json") Files.writeString(resourceTypesFile, """["https://neuroshapes.org/Entity"]""") @@ -92,12 +91,11 @@ object MainSuite { "app.defaults.database.access.username" -> PostgresUser, "app.default.database.access.password" -> PostgresPassword, "akka.actor.testkit.typed.throw-on-shutdown-timeout" -> "false", - "plugins.elasticsearch.base" -> s"http://${elastic.getHost}:${elastic.getMappedPort(9200)}", - "plugins.elasticsearch.credentials.username" -> "elastic", - "plugins.elasticsearch.credentials.password" -> "password", + "plugins.elasticsearch.indexing-enabled" -> "false", //TODO Investigate how to remove this property from the config "plugins.elasticsearch.disable-metrics-projection" -> "true", "plugins.graph-analytics.enabled" -> "true", + "plugins.graph-analytics.indexing-enabled" -> "false", "plugins.search.enabled" -> "true", "plugins.search.indexing.resource-types" -> resourceTypesFile.toString, "plugins.search.indexing.mapping" -> mappingFile.toString, @@ -109,8 +107,7 @@ object MainSuite { private def resource() = for { postgres <- PostgresContainer.resource(PostgresUser, PostgresPassword) - elastic <- ElasticSearchContainer.resource() - _ <- SystemPropertyOverride(initConfig(postgres, elastic)) + _ <- SystemPropertyOverride(initConfig(postgres)) } yield () val main: IOFixture[Unit] = ResourceSuiteLocalFixture("main", resource()) diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala index 3b105a6696..dfb179a461 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchPluginModule.scala @@ -165,7 +165,8 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef { config.metricsQuery, config.prefix, files.metricsMapping, - files.metricsSettings + files.metricsSettings, + config.indexingEnabled ) } diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/EventMetricsProjection.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/EventMetricsProjection.scala index a9f76d1b03..71c1136189 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/EventMetricsProjection.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/EventMetricsProjection.scala @@ -23,6 +23,9 @@ object EventMetricsProjection { val projectionMetadata: ProjectionMetadata = ProjectionMetadata("system", "event-metrics", None, None) val eventMetricsIndex: String => IndexLabel = prefix => IndexLabel.unsafe(s"${prefix}_project_metrics") + // We need a value to return to Distage + private val dummy = new EventMetricsProjection {} + /** * @param metricEncoders * a set of encoders for all entity @@ -52,8 +55,9 @@ object EventMetricsProjection { queryConfig: QueryConfig, indexPrefix: String, metricMappings: MetricsMapping, - metricsSettings: MetricsSettings - ): IO[EventMetricsProjection] = { + metricsSettings: MetricsSettings, + indexingEnabled: Boolean + ): IO[EventMetricsProjection] = if (indexingEnabled) { val allEntityTypes = metricEncoders.map(_.entityType).toList implicit val multiDecoder: MultiDecoder[ProjectScopedMetric] = @@ -70,7 +74,7 @@ object EventMetricsProjection { val createIndex = client.createIndex(index, Some(metricMappings.value), Some(metricsSettings.value)).void apply(sink, supervisor, metrics, createIndex) - } + } else IO.pure(dummy) /** * Test friendly apply method @@ -98,7 +102,7 @@ object EventMetricsProjection { for { projection <- IO.fromEither(compiledProjection) _ <- supervisor.run(projection, init) - } yield new EventMetricsProjection {} + } yield dummy } }