Skip to content

Commit df4ec00

Browse files
author
Volchkov Andrey
committed
feat: switch off stop-writes-sys-memory-pct metric for aerosspike enterprise
1 parent 5f0a88b commit df4ec00

File tree

6 files changed

+92
-19
lines changed

6 files changed

+92
-19
lines changed

embedded-aerospike-enterprise/src/main/java/com/playtika/testcontainers/aerospike/enterprise/AerospikeEnterpriseConfigurer.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.playtika.test.aerospike.AerospikeProperties;
44
import lombok.RequiredArgsConstructor;
55
import lombok.extern.slf4j.Slf4j;
6-
import org.testcontainers.containers.Container;
76
import org.testcontainers.containers.GenericContainer;
87

98
import java.io.IOException;
@@ -15,26 +14,29 @@ public class AerospikeEnterpriseConfigurer {
1514
private final AerospikeProperties aerospikeProperties;
1615
private final AerospikeEnterpriseProperties enterpriseProperties;
1716

18-
public void configure(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
17+
public void configure(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
1918
if (aerospikeProperties.getFeatureKey() == null || aerospikeProperties.getFeatureKey().isEmpty()) {
2019
log.warn("Evaluation feature key file not provided by 'embedded.aerospike.featureKey' property. " +
2120
"Pay attention to license details: https://github.com/aerospike/aerospike-server.docker/blob/master/enterprise/ENTERPRISE_LICENSE");
2221
}
2322

24-
setupDisallowExpunge(aerospikeContainer);
25-
}
26-
27-
private void setupDisallowExpunge(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
28-
if (!enterpriseProperties.isDurableDeletes()) {
29-
return;
30-
}
31-
log.info("Setting up 'disallow-expunge' to true...");
3223
String namespace = aerospikeProperties.getNamespace();
33-
Container.ExecResult result = aerospikeContainer.execInContainer("asadm", "-e",
34-
String.format("enable; manage config namespace %s param disallow-expunge to true", namespace));
35-
if (result.getStderr().length() > 0) {
36-
throw new IllegalStateException("Failed to set up 'disallow-expunge' to true: " + result.getStderr());
24+
AsadmCommandExecutor asadmCommandExecutor = new AsadmCommandExecutor(aerospikeContainer);
25+
26+
/*
27+
By default, the value of this metric is 90%, we set it to 100% to prevent stopping writes for the Aerospike
28+
Enterprise container during high consumption of system memory. For the Aerospike Community Edition, this metric is not used.
29+
Documentation: https://aerospike.com/docs/server/reference/configuration#stop-writes-sys-memory-pct
30+
*/
31+
log.info("Switching off 'stop-writes-sys-memory-pct'... ");
32+
asadmCommandExecutor.execute(String.format("manage config namespace %s param stop-writes-sys-memory-pct to 100", namespace));
33+
log.info("Success switching off 'stop-writes-sys-memory-pct'");
34+
35+
if (enterpriseProperties.isDurableDeletes()) {
36+
log.info("Setting up 'disallow-expunge' to true...");
37+
asadmCommandExecutor.execute(String.format("manage config namespace %s param disallow-expunge to true", namespace));
38+
log.info("Success setting up 'disallow-expunge' to true");
3739
}
38-
log.info("Set up 'disallow-expunge' to true: {}", result.getStdout());
3940
}
41+
4042
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.playtika.testcontainers.aerospike.enterprise;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.testcontainers.containers.Container;
6+
import org.testcontainers.containers.GenericContainer;
7+
8+
import java.io.IOException;
9+
10+
@RequiredArgsConstructor
11+
@Slf4j
12+
public class AsadmCommandExecutor {
13+
14+
private final GenericContainer<?> aerospikeContainer;
15+
16+
public void execute(String command) throws IOException, InterruptedException {
17+
Container.ExecResult result = aerospikeContainer.execInContainer("asadm", "--enable", "-e", command);
18+
logStdout(result);
19+
if (result.getExitCode() != 0 || isBadResponse(result)) {
20+
throw new IllegalStateException(String.format("Failed to execute \"asadm --enable -e '%s'\": \nstdout:\n%s\nstderr:\n%s",
21+
command, result.getStdout(), result.getStderr()));
22+
}
23+
}
24+
25+
private boolean isBadResponse(Container.ExecResult execResult) {
26+
String stdout = execResult.getStdout();
27+
/*
28+
Example of the stdout without error:
29+
~Set Namespace Param stop-writes-sys-memory-pct to 100~
30+
Node|Response
31+
728bb242e58c:3000|ok
32+
Number of rows: 1
33+
*/
34+
return !stdout.contains("|ok");
35+
}
36+
37+
private static void logStdout(Container.ExecResult result) {
38+
log.debug("Aerospike asadm util stdout: \n{}\n{}", result.getStdout(), result.getStderr());
39+
}
40+
}

embedded-aerospike-enterprise/src/main/java/com/playtika/testcontainers/aerospike/enterprise/EnterpriseAerospikeTestOperationsAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public class EnterpriseAerospikeTestOperationsAutoConfiguration {
2121
@Bean
2222
@ConditionalOnProperty(value = "embedded.aerospike.time-travel.enabled", havingValue = "true", matchIfMissing = true)
2323
public ExpiredDocumentsCleaner expiredDocumentsCleaner(AerospikeClient client,
24+
AerospikeEnterpriseProperties aerospikeEnterpriseProperties,
2425
AerospikeProperties properties) {
25-
return new AerospikeExpiredDocumentsCleaner(client, properties.getNamespace(), true);
26+
return new AerospikeExpiredDocumentsCleaner(client, properties.getNamespace(), aerospikeEnterpriseProperties.isDurableDeletes());
2627
}
2728

2829
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.playtika.testcontainers.aerospike.enterprise;
2+
3+
import com.playtika.test.aerospike.AerospikeProperties;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Qualifier;
7+
import org.testcontainers.containers.GenericContainer;
8+
9+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
10+
11+
public class AsadmCommandExecutorTest extends BaseEnterpriseAerospikeTest {
12+
13+
@Autowired
14+
@Qualifier(AerospikeProperties.AEROSPIKE_BEAN_NAME)
15+
private GenericContainer<?> aerospikeContainer;
16+
17+
@Test
18+
public void shouldFailCommandExecutionWithBadOption() {
19+
AsadmCommandExecutor commandExecutor = new AsadmCommandExecutor(aerospikeContainer);
20+
assertThatExceptionOfType(IllegalStateException.class)
21+
.isThrownBy(() -> commandExecutor.execute("-tttttt"));
22+
}
23+
24+
@Test
25+
public void shouldFailCommandExecutionWithBadCommand() {
26+
AsadmCommandExecutor commandExecutor = new AsadmCommandExecutor(aerospikeContainer);
27+
assertThatExceptionOfType(IllegalStateException.class)
28+
.isThrownBy(() -> commandExecutor.execute("manage config namespace NAMESPACE_NOT_EXISTS param disallow-expunge to true"));
29+
}
30+
}

embedded-aerospike-enterprise/src/test/java/com/playtika/testcontainers/aerospike/enterprise/ValidateEnterpriseAerospikeBootstrapConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ void failOnNonEnterpriseImage() {
2020

2121
@Test
2222
void failOnUnsuitableEnterpriseImageVersion() {
23-
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike/aerospike-server-enterprise:6.1.0.16_1")
23+
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike/aerospike-server-enterprise:6.1.0.16")
2424
.run(context -> assertThat(context).hasFailed());
2525
}
2626

2727
@Test
2828
void skipValidation() {
29-
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike-server:6.1.0.16_1",
29+
contextRunner.withPropertyValues("embedded.aerospike.dockerImage=aerospike-server:6.1.0.16",
3030
"embedded.aerospike.enabled=false")
3131
.run(context -> assertThat(context).hasNotFailed());
3232

embedded-aerospike-enterprise/src/test/resources/log4j2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</Console>
77
</Appenders>
88
<Loggers>
9-
<Logger name="com.playtika.testcontainer" level="info"/>
9+
<Logger name="com.playtika.testcontainers" level="info"/>
1010
<Logger name="org.springframework" level="error"/>
1111
<Root level="error">
1212
<AppenderRef ref="Console"/>

0 commit comments

Comments
 (0)