diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2020-01-09 09:26:53 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-11-05 20:06:21 +0000 |
commit | f4751bd13509f8d325d17cb4cf4ed9d85025f65f (patch) | |
tree | 369137df20a5df287bf77cdb7dcf49888f282f31 /server/sonar-webserver-webapi | |
parent | 8cdee7d30f96e87b8bb7ec55fdfd8101ab717dfd (diff) | |
download | sonarqube-f4751bd13509f8d325d17cb4cf4ed9d85025f65f.tar.gz sonarqube-f4751bd13509f8d325d17cb4cf4ed9d85025f65f.zip |
SONAR-12686 upgrade es client to 7.9.3 and move to HTTP
- add should minimum match eq 1 to user index queries
ES 7.X changed behaviour in case filter query with bool it defaults to '0'
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/breaking-changes-7.0.html#_the_filter_context_has_been_removed
- fix issue index routing param
ES 7.X helped discover this bug as new setting has been auto configured which is 'index.number_of_routing_shards'.
This has changed how documents are distributed across shards depending on how many shards the index has.
Without that change issues docs has been incorrectly routed to the same shard hash as projects and it worked no matter what routing key you used projectUuid or auth_projectUuid.
- update ngram and edge_ngram names to match with es 7.x
nGram and edgeNgram has been deprecated in favour of ngram and edge_ngram
https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#deprecated-ngram-edgengram-token-filter-cannot-be-used
- remove `_all : enabled` usage from UT
This field was already deprecated in 6.X, now it has been removed.
https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#all-meta-field-removed
- add Elasticsearch High Level REST client dependency
- use sonar.search.port for ES HTTP
- main process use ES Rest client to check ES status
- sonar.cluster.search.hosts has HTTP ports on APP nodes
also sonar.search.port and sonar.search.host MUST be configured on each Search node with the host and HTTP port of the current node
- use Elasticsearch high level rest client
- use in EsTester
- use as primary es client
- use indices api to get all indices name instead of cluster api
- use cluster health api to check cluster state
- support raw requests for 'nodes/_stats' and '_cluster/stats'
- support raw requests for 'indices/_stats'
- leave netty4plugin as testCompile dependency it is used in UTs
- all ES non-test calls go through EsClient class
- add rest client ES profiling
Diffstat (limited to 'server/sonar-webserver-webapi')
7 files changed, 30 insertions, 19 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/health/EsStatusCheck.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/health/EsStatusCheck.java index e2e7c0e7770..b1407678103 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/health/EsStatusCheck.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/health/EsStatusCheck.java @@ -19,6 +19,7 @@ */ package org.sonar.server.health; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -50,7 +51,7 @@ abstract class EsStatusCheck { Health checkEsStatus() { try { - ClusterHealthStatus esStatus = esClient.prepareClusterStats().get().getStatus(); + ClusterHealthStatus esStatus = esClient.clusterHealth(new ClusterHealthRequest()).getStatus(); if (esStatus == null) { return RED_HEALTH_UNAVAILABLE; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index 41a6b9c46aa..71394bc9a0f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -293,7 +293,7 @@ public class SearchAction implements HotspotsWsAction { List<IssueDto> hotspots = toIssueDtos(dbSession, issueKeys); - Paging paging = forPageIndex(wsRequest.getPage()).withPageSize(wsRequest.getIndex()).andTotal((int) result.getHits().getTotalHits()); + Paging paging = forPageIndex(wsRequest.getPage()).withPageSize(wsRequest.getIndex()).andTotal((int) result.getHits().getTotalHits().value); return new SearchResponseData(paging, hotspots); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java index ead3f8bdfee..2ea5eb36b18 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -426,7 +426,7 @@ public class SearchAction implements IssuesWsAction { SearchResponseData data = searchResponseLoader.load(preloadedData, collector, additionalFields, facets); // FIXME allow long in Paging - Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) result.getHits().getTotalHits()); + Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) result.getHits().getTotalHits().value); return searchResponseFormat.formatSearch(additionalFields, data, paging, facets); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusClusterCheckTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusClusterCheckTest.java index 58668ff407f..53e83883583 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusClusterCheckTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusClusterCheckTest.java @@ -31,6 +31,7 @@ import org.sonar.server.es.EsClient; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.when; @@ -43,7 +44,7 @@ public class EsStatusClusterCheckTest { @Test public void check_ignores_NodeHealth_arg_and_returns_RED_with_cause_if_an_exception_occurs_checking_ES_cluster_status() { Set<NodeHealth> nodeHealths = ImmutableSet.of(newNodeHealth(NodeHealth.Status.GREEN)); - when(esClient.prepareClusterStats()).thenThrow(new RuntimeException("Faking an exception occurring while using the EsClient")); + when(esClient.clusterHealth(any())).thenThrow(new RuntimeException("Faking an exception occurring while using the EsClient")); Health health = new EsStatusClusterCheck(esClient).check(nodeHealths); @@ -54,7 +55,7 @@ public class EsStatusClusterCheckTest { @Test public void check_ignores_NodeHealth_arg_and_returns_GREEN_without_cause_if_ES_cluster_status_is_GREEN() { Set<NodeHealth> nodeHealths = ImmutableSet.of(newNodeHealth(NodeHealth.Status.YELLOW)); - when(esClient.prepareClusterStats().get().getStatus()).thenReturn(ClusterHealthStatus.GREEN); + when(esClient.clusterHealth(any()).getStatus()).thenReturn(ClusterHealthStatus.GREEN); Health health = underTest.check(nodeHealths); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusNodeCheckTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusNodeCheckTest.java index 7786ffaab69..3d7b2641ab7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusNodeCheckTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/EsStatusNodeCheckTest.java @@ -25,6 +25,7 @@ import org.mockito.Mockito; import org.sonar.server.es.EsClient; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -36,7 +37,7 @@ public class EsStatusNodeCheckTest { @Test public void check_ignores_NodeHealth_arg_and_returns_RED_with_cause_if_an_exception_occurs_checking_ES_cluster_status() { EsClient esClient = mock(EsClient.class); - when(esClient.prepareClusterStats()).thenThrow(new RuntimeException("Faking an exception occurring while using the EsClient")); + when(esClient.clusterHealth(any())).thenThrow(new RuntimeException("Faking an exception occurring while using the EsClient")); Health health = new EsStatusNodeCheck(esClient).check(); @@ -46,7 +47,7 @@ public class EsStatusNodeCheckTest { @Test public void check_returns_GREEN_without_cause_if_ES_cluster_status_is_GREEN() { - when(esClient.prepareClusterStats().get().getStatus()).thenReturn(ClusterHealthStatus.GREEN); + when(esClient.clusterHealth(any()).getStatus()).thenReturn(ClusterHealthStatus.GREEN); Health health = underTest.check(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index 3d5a67462aa..cf16f7afe1a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -21,6 +21,8 @@ package org.sonar.server.user.ws; import java.util.HashSet; import java.util.Optional; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.search.builder.SearchSourceBuilder; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -34,6 +36,7 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.authentication.CredentialsLocalAuthentication; +import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.organization.DefaultOrganizationProvider; @@ -109,13 +112,14 @@ public class CreateActionTest { .containsOnly("john", "John", "john@email.com", singletonList("jn"), true); // exists in index - assertThat(es.client().prepareSearch(UserIndexDefinition.TYPE_USER) - .setQuery(boolQuery() - .must(termQuery(FIELD_LOGIN, "john")) - .must(termQuery(FIELD_NAME, "John")) - .must(termQuery(FIELD_EMAIL, "john@email.com")) - .must(termQuery(FIELD_SCM_ACCOUNTS, "jn"))) - .get().getHits().getHits()).hasSize(1); + assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER) + .source(new SearchSourceBuilder() + .query(boolQuery() + .must(termQuery(FIELD_LOGIN, "john")) + .must(termQuery(FIELD_NAME, "John")) + .must(termQuery(FIELD_EMAIL, "john@email.com")) + .must(termQuery(FIELD_SCM_ACCOUNTS, "jn"))))) + .getHits().getHits()).hasSize(1); // exists in db Optional<UserDto> dbUser = db.users().selectUserByLogin("john"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 760f99b1adb..ae1e40c7577 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -21,6 +21,8 @@ package org.sonar.server.user.ws; import java.util.Optional; import javax.annotation.Nullable; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.search.builder.SearchSourceBuilder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -43,6 +45,7 @@ import org.sonar.db.user.GroupDto; import org.sonar.db.user.SessionTokenDto; import org.sonar.db.user.UserDismissedMessageDto; import org.sonar.db.user.UserDto; +import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; @@ -100,11 +103,12 @@ public class DeactivateActionTest { deactivate(user.getLogin()); verifyThatUserIsDeactivated(user.getLogin()); - assertThat(es.client().prepareSearch(UserIndexDefinition.TYPE_USER) - .setQuery(boolQuery() - .must(termQuery(FIELD_UUID, user.getUuid())) - .must(termQuery(FIELD_ACTIVE, "false"))) - .get().getHits().getHits()).hasSize(1); + assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER) + .source(new SearchSourceBuilder() + .query(boolQuery() + .must(termQuery(FIELD_UUID, user.getUuid())) + .must(termQuery(FIELD_ACTIVE, "false"))))) + .getHits().getHits()).hasSize(1); } @Test |