-
Notifications
You must be signed in to change notification settings - Fork 165
[RORDEV-1453] Ubuntu apt-get based installation of ES in tests #1127
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
Merged
mgoworko
merged 27 commits into
sscarduzio:develop
from
mgoworko:rordev-1453-integration-tests-for-apt-based-es
Jul 8, 2025
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0bcb4e7
qsss
mgoworko 3e4c4ec
qs
mgoworko 672879d
qs
mgoworko cd4a0bd
use ubuntu with apt installed ES
mgoworko 8797bea
Merge remote-tracking branch 'origin/develop' into rordev-1453-integr…
mgoworko e421eb4
use ubuntu with apt installed ES
mgoworko 3089727
qs
mgoworko 9a04589
Merge remote-tracking branch 'origin/develop' into rordev-1453-integr…
mgoworko 9ba4907
adjust tests for ES versions and clean docker images after test
mgoworko 39977c2
try to prune Docker images to free up some space
mgoworko ead059b
try to prune Docker images to free up some space
mgoworko 561eab4
qs
mgoworko feb5b3e
qs
mgoworko 8bc3561
Merge remote-tracking branch 'origin/develop' into rordev-1453-integr…
mgoworko 13ca95b
test different approach
mgoworko ec891c7
test different approach
mgoworko d53ab7d
qs
mgoworko 08a8ada
qs
mgoworko d85a620
qs
mgoworko 45711d2
Merge remote-tracking branch 'origin/develop' into rordev-1453-integr…
mgoworko a0522a9
test a few things that could cause OOM
mgoworko c31e5cc
test a few things that could cause OOM
mgoworko a040672
test run pipeline
mgoworko 07c7b98
another test
mgoworko 372911a
cleaning
mgoworko a1bff76
qs
mgoworko 6a90fc7
review changes
mgoworko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
ror-tools/src/test/scala/tech/beshu/ror/tools/PatchingOfAptBasedEsInstallationSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* This file is part of ReadonlyREST. | ||
* | ||
* ReadonlyREST is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ReadonlyREST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ | ||
*/ | ||
package tech.beshu.ror.tools | ||
|
||
import cats.data.NonEmptyList | ||
import com.github.dockerjava.api.DockerClient | ||
import monix.eval.Task | ||
import monix.execution.Scheduler | ||
import monix.execution.atomic.AtomicInt | ||
import org.scalatest.matchers.must.Matchers.include | ||
import org.scalatest.matchers.should.Matchers.{should, shouldNot} | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import org.testcontainers.DockerClientFactory | ||
import tech.beshu.ror.integration.utils.ESVersionSupportForAnyWordSpecLike | ||
import tech.beshu.ror.utils.containers.* | ||
import tech.beshu.ror.utils.containers.EsContainerCreator.EsNodeSettings | ||
import tech.beshu.ror.utils.containers.images.Elasticsearch.EsInstallationType | ||
import tech.beshu.ror.utils.containers.images.ReadonlyRestWithEnabledXpackSecurityPlugin | ||
import tech.beshu.ror.utils.containers.logs.DockerLogsToStringConsumer | ||
import tech.beshu.ror.utils.elasticsearch.BaseManager.JSON | ||
import tech.beshu.ror.utils.elasticsearch.SearchManager | ||
import tech.beshu.ror.utils.httpclient.RestClient | ||
import tech.beshu.ror.utils.misc.EsModulePatterns | ||
|
||
import scala.concurrent.duration.* | ||
import scala.language.postfixOps | ||
import scala.util.Try | ||
|
||
// There is a change introduced in Elasticsearch since versions 9.0.1 and 8.18.1 (older ES versions are not affected) | ||
// The change: https://github.com/elastic/elasticsearch/pull/126852 ("With this PR we restrict the paths we allow access to, forbidding plugins to specify/request entitlements for reading or writing to specific protected directories.") | ||
// In our use case it causes problems with apt-based installations of ES and patching: | ||
// - ROR cannot check (on startup) whether the ES is patched | ||
// - that is because after the aforementioned change in ES, the ROR plugin cannot access the /usr/share/elasticsearch directory | ||
// - we bypass this problem (ROR plugin cannot check the patch status, so it just allows to continue starting ES, with warning in logs) | ||
// This test suite verifies, that both official ES image and apt-based ES installation with ROR can start. Logs are also asserted to detect the warning. | ||
class PatchingOfAptBasedEsInstallationSuite extends AnyWordSpec with ESVersionSupportForAnyWordSpecLike { | ||
|
||
import PatchingOfAptBasedEsInstallationSuite.* | ||
|
||
implicit val scheduler: Scheduler = Scheduler.computation(10) | ||
|
||
private val validRorConfigFile = "/basic/readonlyrest.yml" | ||
|
||
"ES" when { | ||
"using official ES image" should { | ||
"successfully load ROR plugin and start (patch verification without warning)" in { | ||
val dockerLogs = withTestEsContainerManager(EsInstallationType.EsDockerImage) { esContainer => | ||
testRorStartup(usingManager = esContainer) | ||
} | ||
dockerLogs should include("ReadonlyREST is waiting for full Elasticsearch init") | ||
dockerLogs should include("Elasticsearch fully initiated. ReadonlyREST can continue ...") | ||
dockerLogs should include("Loading Elasticsearch settings from file: /usr/share/elasticsearch/config/elasticsearch.yml") | ||
dockerLogs shouldNot include("Cannot verify if the ES was patched") | ||
dockerLogs should include("ReadonlyREST was loaded") | ||
} | ||
} | ||
"installed on Ubuntu using apt" should { | ||
// ES 6.x is not available as apt package, so we do not test it | ||
"ES {7.x, 8.0.x - 8.17.x} successfully load ROR plugin and start (without warning about not being able to verify patch)" excludeES(allEs6x, allEs9x, allEs818x) in { | ||
val dockerLogs = withTestEsContainerManager(EsInstallationType.UbuntuDockerImageWithEsFromApt) { esContainer => | ||
testRorStartup(usingManager = esContainer) | ||
} | ||
dockerLogs should include("ReadonlyREST is waiting for full Elasticsearch init") | ||
dockerLogs should include("Elasticsearch fully initiated. ReadonlyREST can continue ...") | ||
dockerLogs should include("Loading Elasticsearch settings from file: /etc/elasticsearch/elasticsearch.yml") | ||
dockerLogs shouldNot include("Cannot verify if the ES was patched") | ||
dockerLogs should include("ReadonlyREST was loaded") | ||
} | ||
"ES {8.18.x, 9.x} successfully load ROR plugin and start (with warning about not being able to verify patch)" excludeES(allEs6x, allEs7x, allEs8xBelowEs818x) in { | ||
val dockerLogs = withTestEsContainerManager(EsInstallationType.UbuntuDockerImageWithEsFromApt) { esContainer => | ||
testRorStartup(usingManager = esContainer) | ||
} | ||
dockerLogs should include("ReadonlyREST is waiting for full Elasticsearch init") | ||
dockerLogs should include("Elasticsearch fully initiated. ReadonlyREST can continue ...") | ||
dockerLogs should include("Loading Elasticsearch settings from file: /etc/elasticsearch/elasticsearch.yml") | ||
dockerLogs should include("Cannot verify if the ES was patched. component [readonlyrest], module [ALL-UNNAMED], class [class tech.beshu.ror.tools.core.utils.EsDirectory$], entitlement [file], operation [read], path [/usr/share/elasticsearch]") | ||
dockerLogs should include("ReadonlyREST was loaded") | ||
} | ||
} | ||
} | ||
|
||
private def withTestEsContainerManager(esInstallationType: EsInstallationType) | ||
(testCode: TestEsContainerManager => Task[Unit]): String = { | ||
val esContainer = new TestEsContainerManager(validRorConfigFile, esInstallationType) | ||
try { | ||
(for { | ||
_ <- esContainer.start() | ||
_ <- testCode(esContainer) | ||
} yield ()).runSyncUnsafe(5 minutes) | ||
esContainer.getLogs | ||
} finally { | ||
esContainer.stop().runSyncUnsafe() | ||
} | ||
} | ||
mgoworko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private def testRorStartup(usingManager: TestEsContainerManager): Task[Unit] = { | ||
for { | ||
restClient <- usingManager.createRestClient | ||
searchTestResults <- searchTest(restClient) | ||
result <- handleResult(searchTestResults) | ||
} yield result | ||
} | ||
|
||
private def searchTest(client: RestClient): Task[TestResponse] = Task.delay { | ||
val manager = new SearchManager(client, esVersionUsed) | ||
val response = manager.searchAll("*") | ||
TestResponse(response.responseCode, response.responseJson) | ||
} | ||
|
||
private def handleResult(result: TestResponse): Task[Unit] = { | ||
val hasEsRespondedWithSuccess = result.responseCode == 200 | ||
if (hasEsRespondedWithSuccess) { | ||
Task.unit | ||
} else { | ||
Task.raiseError(new IllegalStateException(s"Test failed. Expected success response but was: [$result]")) | ||
} | ||
} | ||
} | ||
|
||
private object PatchingOfAptBasedEsInstallationSuite extends EsModulePatterns { | ||
final case class TestResponse(responseCode: Int, responseJson: JSON) | ||
|
||
private val uniqueClusterId: AtomicInt = AtomicInt(1) | ||
|
||
final class TestEsContainerManager(rorConfigFile: String, esInstallationType: EsInstallationType) extends EsContainerCreator { | ||
|
||
private val dockerClient: DockerClient = DockerClientFactory.instance().client() | ||
|
||
private val dockerLogsCollector = new DockerLogsToStringConsumer | ||
|
||
private val esContainer = createEsContainer | ||
|
||
def start(): Task[Unit] = Task.delay(esContainer.start()) | ||
|
||
def stop(): Task[Unit] = for { | ||
_ <- Task.delay(esContainer.stop()) | ||
_ <- Task.delay(dockerClient.removeImageCmd(esContainer.imageFromDockerfile.get()).withForce(true).exec()) | ||
} yield () | ||
|
||
mgoworko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def getLogs: String = dockerLogsCollector.getLogs | ||
|
||
def createRestClient: Task[RestClient] = { | ||
Task.tailRecM(()) { _ => | ||
Task.delay(createAdminClient) | ||
} | ||
} | ||
mgoworko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private def createAdminClient = { | ||
Try(esContainer.adminClient) | ||
.toEither | ||
.left.map(_ => ()) | ||
} | ||
|
||
private def createEsContainer: EsContainer = { | ||
val clusterName = s"ROR_${uniqueClusterId.getAndIncrement()}" | ||
val nodeName = s"${clusterName}_1" | ||
create( | ||
nodeSettings = EsNodeSettings( | ||
nodeName = nodeName, | ||
clusterName = clusterName, | ||
securityType = SecurityType.RorWithXpackSecurity( | ||
ReadonlyRestWithEnabledXpackSecurityPlugin.Config.Attributes.default.copy( | ||
rorConfigFileName = rorConfigFile | ||
) | ||
), | ||
containerSpecification = ContainerSpecification.empty, | ||
esVersion = EsVersion.DeclaredInProject | ||
), | ||
allNodeNames = NonEmptyList.of(nodeName), | ||
nodeDataInitializer = NoOpElasticsearchNodeDataInitializer, | ||
startedClusterDependencies = StartedClusterDependencies(List.empty), | ||
esInstallationType = esInstallationType, | ||
additionalLogConsumer = Some(dockerLogsCollector) | ||
) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.