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

Fix error when creating a view with invalid mappings or settings #4365

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ plugins.elasticsearch {
# username= "elastic_user"
# password= "password"
# }
# configuration of the Elasticsearch client
client = ${app.defaults.http-client-compression}
# the elasticsearch event log configuration
event-log = ${app.defaults.event-log}
# the elasticsearch pagination config
Expand All @@ -20,8 +18,6 @@ plugins.elasticsearch {
prefix = ${app.defaults.indexing.prefix}
# configuration of the maximum number of view references allowed on an aggregated view
max-view-refs = 20
# the maximum idle duration in between events on the indexing stream after which the stream will be stopped (min. 10 minutes).
idle-timeout = 30 minutes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused

# In order to disable this feature, set an infinite time ('Inf')
# idle-timeout = Inf
#the maximum duration allowed so that synchronous indexing can complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.deletion.ProjectDeletionTask
import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaSchemeDirectives
import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig
import ch.epfl.bluebrain.nexus.delta.sdk.http.HttpClient
import ch.epfl.bluebrain.nexus.delta.sdk.http.{HttpClient, HttpClientConfig}
import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.ServiceAccount
import ch.epfl.bluebrain.nexus.delta.sdk.model._
Expand Down Expand Up @@ -53,8 +53,8 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef {
make[ElasticSearchViewsConfig].from { ElasticSearchViewsConfig.load(_) }

make[HttpClient].named("elasticsearch-client").from {
(cfg: ElasticSearchViewsConfig, as: ActorSystem[Nothing], sc: Scheduler) =>
HttpClient()(cfg.client, as.classicSystem, sc)
val httpConfig = HttpClientConfig.noRetry(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The retry strategy was responsible for timeouts.
We don't need retries when interacting with Elasticsearch so it is better to let things fail when it returns an error

(as: ActorSystem[Nothing], sc: Scheduler) => HttpClient()(httpConfig, as.classicSystem, sc)
}

make[ElasticSearchClient].from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import akka.http.scaladsl.model.headers.BasicHttpCredentials
import ch.epfl.bluebrain.nexus.delta.sdk.instances._
import ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch.client.ElasticSearchClient.Refresh
import ch.epfl.bluebrain.nexus.delta.sdk.Defaults
import ch.epfl.bluebrain.nexus.delta.sdk.http.HttpClientConfig
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.PaginationConfig
import ch.epfl.bluebrain.nexus.delta.sourcing.config.{BatchConfig, EventLogConfig, QueryConfig}
import com.typesafe.config.Config
import pureconfig.error.{CannotConvert, FailureReason}
import pureconfig.error.CannotConvert
import pureconfig.generic.semiauto.deriveReader
import pureconfig.{ConfigReader, ConfigSource}

Expand All @@ -23,8 +22,6 @@ import scala.concurrent.duration._
* the base uri to the Elasticsearch HTTP endpoint
* @param credentials
* the credentials to authenticate to the Elasticsearch endpoint
* @param client
* configuration of the Elasticsearch client
* @param eventLog
* configuration of the event log
* @param pagination
Expand All @@ -35,8 +32,6 @@ import scala.concurrent.duration._
* prefix for indices
* @param maxViewRefs
* configuration of the maximum number of view references allowed on an aggregated view
* @param idleTimeout
* the maximum idle duration in between events on the indexing stream after which the stream will be stopped
* @param syncIndexingTimeout
* the maximum duration for synchronous indexing to complete
* @param syncIndexingRefresh
Expand All @@ -55,13 +50,11 @@ import scala.concurrent.duration._
final case class ElasticSearchViewsConfig(
base: Uri,
credentials: Option[BasicHttpCredentials],
client: HttpClientConfig,
eventLog: EventLogConfig,
pagination: PaginationConfig,
batch: BatchConfig,
prefix: String,
maxViewRefs: Int,
idleTimeout: Duration,
syncIndexingTimeout: FiniteDuration,
syncIndexingRefresh: Refresh,
maxIndexPathLength: Int,
Expand Down Expand Up @@ -98,11 +91,5 @@ object ElasticSearchViewsConfig {
}

implicit final val elasticSearchViewsConfigReader: ConfigReader[ElasticSearchViewsConfig] =
deriveReader[ElasticSearchViewsConfig].emap { c =>
Either.cond(
c.idleTimeout.gteq(10.minutes),
c,
new FailureReason { override def description: String = "'idle-timeout' must be greater than 10 minutes" }
)
}
deriveReader[ElasticSearchViewsConfig]
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ class ElasticSearchViewsSpec extends BaseSpec with EitherValuable with CirceEq {
}
}

"fail to create a view with an invalid mapping" in {
val invalidMapping =
json"""{"mapping": "fail"}"""
val payload = json"""{ "@type": "ElasticSearchView", "mapping": $invalidMapping }"""
deltaClient.put[Json](s"/views/$fullId/invalid", payload, ScoobyDoo) { expectBadRequest }
Copy link
Contributor

Choose a reason for hiding this comment

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

The invalid segment reads as if the view id is invalid, when the issue is the payload. The payload could be called payloadWithInvalidMapping, and the view id something else than invalid. Similar comment on the other test

}

"fail to create a view with invalid settings" in {
val invalidSettings =
json"""{"analysis": "fail"}"""
val payload = json"""{ "@type": "ElasticSearchView", "mapping": { }, "settings": $invalidSettings }"""
deltaClient.put[Json](s"/views/$fullId/invalid", payload, ScoobyDoo) { expectBadRequest }
}
olivergrabinski marked this conversation as resolved.
Show resolved Hide resolved

"create people view in project 2" in {
deltaClient.put[Json](
s"/views/$fullId2/test-resource:people",
Expand Down