Skip to content

Commit

Permalink
feat: moved healthCheck.enabled property to Elasticsearch/OpensearchP…
Browse files Browse the repository at this point in the history
…roperties

to better reflect that health check is turned off for ES/OS, not Operate itself

(cherry picked from commit 1555c02)

# Conflicts:
#	operate/common/src/main/java/io/camunda/operate/connect/OpensearchConnector.java
  • Loading branch information
kristinkomschow committed Oct 11, 2024
1 parent d682132 commit 2bb9995
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public ElasticsearchClient elasticsearchClient() {
// And create the API client
elasticsearchClient = new ElasticsearchClient(transport);

if (operateProperties.isHealthCheckEnabled()) {
if (operateProperties.getElasticsearch().isHealthCheckEnabled()) {
if (!checkHealth(elasticsearchClient)) {
LOGGER.warn("Elasticsearch cluster is not accessible");
} else {
Expand Down Expand Up @@ -193,7 +193,7 @@ public RestHighLevelClient createEsClient(final ElasticsearchProperties elsConfi
new RestHighLevelClientBuilder(restClientBuilder.build())
.setApiCompatibilityMode(true)
.build();
if (operateProperties.isHealthCheckEnabled()) {
if (operateProperties.getElasticsearch().isHealthCheckEnabled()) {
if (!checkHealth(esClient)) {
LOGGER.warn("Elasticsearch cluster is not accessible");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public OpensearchConnector(
@Primary
public OpenSearchClient openSearchClient() {
final OpenSearchClient openSearchClient = createOsClient(operateProperties.getOpensearch());
if (operateProperties.isHealthCheckEnabled()) {
if (operateProperties.getOpensearch().isHealthCheckEnabled()) {
try {
final HealthResponse response = openSearchClient.cluster().health();
LOGGER.info("OpenSearch cluster health: {}", response.status());
Expand All @@ -116,7 +116,7 @@ public OpenSearchClient openSearchClient() {
public OpenSearchAsyncClient openSearchAsyncClient() {
final OpenSearchAsyncClient openSearchClient =
createAsyncOsClient(operateProperties.getOpensearch());
if (operateProperties.isHealthCheckEnabled()) {
if (operateProperties.getOpensearch().isHealthCheckEnabled()) {
final CompletableFuture<HealthResponse> healthResponse;
try {
healthResponse = openSearchClient.cluster().health();
Expand Down Expand Up @@ -172,7 +172,7 @@ public OpenSearchAsyncClient createAsyncOsClient(final OpensearchProperties osCo
final OpenSearchTransport transport = builder.build();
final OpenSearchAsyncClient openSearchAsyncClient = new OpenSearchAsyncClient(transport);

if (operateProperties.isHealthCheckEnabled()) {
if (operateProperties.getOpensearch().isHealthCheckEnabled()) {
final CompletableFuture<HealthResponse> healthResponse;
try {
healthResponse = openSearchAsyncClient.cluster().health();
Expand Down Expand Up @@ -240,7 +240,7 @@ public OpenSearchClient createOsClient(final OpensearchProperties osConfig) {

final OpenSearchTransport transport = builder.build();
final OpenSearchClient openSearchClient = new ExtendedOpenSearchClient(transport);
if (operateProperties.isHealthCheckEnabled()) {
if (operateProperties.getOpensearch().isHealthCheckEnabled()) {
try {
final HealthResponse response = openSearchClient.cluster().health();
LOGGER.info("OpenSearch cluster health: {}", response.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class ElasticsearchProperties {

private boolean createSchema = true;

/** Indicates whether operate does a proper health check for ES clusters. */
private boolean healthCheckEnabled = true;

private String url;
private String username;
private String password;
Expand Down Expand Up @@ -125,6 +128,14 @@ public void setCreateSchema(final boolean createSchema) {
this.createSchema = createSchema;
}

public boolean isHealthCheckEnabled() {
return healthCheckEnabled;
}

public void setHealthCheckEnabled(final boolean healthCheckEnabled) {
this.healthCheckEnabled = healthCheckEnabled;
}

public String getPassword() {
return password;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class OpensearchProperties {

private boolean createSchema = true;

/** Indicates whether operate does a proper health check for ES/OS clusters. */
private boolean healthCheckEnabled = true;

private String url;
private String username;
private String password;
Expand Down Expand Up @@ -127,6 +130,14 @@ public void setCreateSchema(final boolean createSchema) {
this.createSchema = createSchema;
}

public boolean isHealthCheckEnabled() {
return healthCheckEnabled;
}

public void setHealthCheckEnabled(final boolean healthCheckEnabled) {
this.healthCheckEnabled = healthCheckEnabled;
}

public String getPassword() {
return password;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public class OperateProperties {
/** Indicates, whether CSRF prevention is enabled. */
private boolean csrfPreventionEnabled = true;

/** Indicates whether operate does a proper health check for ES/OS clusters. */
private boolean healthCheckEnabled = true;

/** Standard user data */
private String userId = "demo";

Expand Down Expand Up @@ -155,14 +152,6 @@ public void setCsrfPreventionEnabled(final boolean csrfPreventionEnabled) {
this.csrfPreventionEnabled = csrfPreventionEnabled;
}

public boolean isHealthCheckEnabled() {
return healthCheckEnabled;
}

public void setHealthCheckEnabled(final boolean healthCheckEnabled) {
this.healthCheckEnabled = healthCheckEnabled;
}

public OperateElasticsearchProperties getElasticsearch() {
return elasticsearch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ElasticsearchConnectorTest {
public void shouldNotDoClusterHealthCheckWhenDisabled() {
final OperateProperties operateProperties = new OperateProperties();
final OperateElasticsearchProperties esProperties = new OperateElasticsearchProperties();
operateProperties.setHealthCheckEnabled(false);
esProperties.setHealthCheckEnabled(false);
operateProperties.setElasticsearch(esProperties);
final ElasticsearchConnector connector = spy(new ElasticsearchConnector(operateProperties));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void asyncHasAwsCredentialsButShouldUseBasicAuth() {
@Test
public void shouldNotDoClusterHealthCheckWhenDisabled() {
final OperateProperties operateProperties = new OperateProperties();
operateProperties.setHealthCheckEnabled(false);
final OperateOpensearchProperties osProperties = new OperateOpensearchProperties();
osProperties.setHealthCheckEnabled(false);
operateProperties.setOpensearch(osProperties);
final OpensearchConnector connector = spy(new OpensearchConnector(operateProperties, mock()));
doReturn(mock(HttpAsyncClientBuilder.class)).when(connector).configureHttpClient(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,10 @@ public Health getHealth(final boolean includeDetails) {
@Override
public Health health() {
LOGGER.debug("Indices check is called");
if (isClusterHealthy() && indicesCheck.indicesArePresent()) {
if (indicesCheck.isHealthy() && indicesCheck.indicesArePresent()) {
return Health.up().build();
} else {
return Health.down().build();
}
}

private boolean isClusterHealthy() {
if (!properties.isHealthCheckEnabled()) {
LOGGER.warn("Cluster health check is disabled.");
return true;
}
return indicesCheck.isHealthy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ public void refresh(final String indexPattern) {

@Override
public boolean isHealthy() {
return retryElasticsearchClient.isHealthy();
if (operateProperties.getElasticsearch().isHealthCheckEnabled()) {
return retryElasticsearchClient.isHealthy();
} else {
LOGGER.warn("OpenSearch cluster health check is disabled.");
return true;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ public void refresh(final String indexPattern) {

@Override
public boolean isHealthy() {
return richOpenSearchClient.cluster().isHealthy();
if (operateProperties.getOpensearch().isHealthCheckEnabled()) {
return richOpenSearchClient.cluster().isHealthy();
} else {
LOGGER.warn("OpenSearch cluster health check is disabled.");
return true;
}
}

@Override
Expand Down

0 comments on commit 2bb9995

Please sign in to comment.