From f7cae910f1a2cb70d8798023cf31e784f1ec11b6 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Fri, 20 Oct 2023 16:23:14 +0000 Subject: [PATCH] Create new test class for validation of tracing features Signed-off-by: Peter Nied --- .../security/SearchOperationTest.java | 12 --- .../org/opensearch/security/TracingTests.java | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 src/integrationTest/java/org/opensearch/security/TracingTests.java diff --git a/src/integrationTest/java/org/opensearch/security/SearchOperationTest.java b/src/integrationTest/java/org/opensearch/security/SearchOperationTest.java index 692ac57a2a..a38d26800a 100644 --- a/src/integrationTest/java/org/opensearch/security/SearchOperationTest.java +++ b/src/integrationTest/java/org/opensearch/security/SearchOperationTest.java @@ -86,7 +86,6 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexTemplateMetadata; import org.opensearch.common.settings.Settings; -import org.opensearch.common.util.FeatureFlags; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.index.query.QueryBuilders; @@ -95,7 +94,6 @@ import org.opensearch.repositories.RepositoryMissingException; import org.opensearch.core.rest.RestStatus; import org.opensearch.search.builder.SearchSourceBuilder; -import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.test.framework.AuditCompliance; import org.opensearch.test.framework.AuditConfiguration; import org.opensearch.test.framework.AuditFilters; @@ -373,16 +371,6 @@ public class SearchOperationTest { USER_ALLOWED_TO_PERFORM_INDEX_OPERATIONS_ON_SELECTED_INDICES, USER_ALLOWED_TO_CREATE_INDEX ) - .nodeSettings( - Map.of( - FeatureFlags.TELEMETRY_SETTING.getKey(), - true, - TelemetrySettings.TRACER_FEATURE_ENABLED_SETTING.getKey(), - true, - TelemetrySettings.METRICS_FEATURE_ENABLED_SETTING.getKey(), - true - ) - ) .audit( new AuditConfiguration(true).compliance(new AuditCompliance().enabled(true)) .filters(new AuditFilters().enabledRest(true).enabledTransport(true)) diff --git a/src/integrationTest/java/org/opensearch/security/TracingTests.java b/src/integrationTest/java/org/opensearch/security/TracingTests.java new file mode 100644 index 0000000000..b26433c333 --- /dev/null +++ b/src/integrationTest/java/org/opensearch/security/TracingTests.java @@ -0,0 +1,79 @@ +/* +* Copyright OpenSearch Contributors +* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +* +*/ +package org.opensearch.security; + +import java.io.IOException; +import java.util.Map; + +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.opensearch.action.search.SearchRequest; +import org.opensearch.action.search.SearchResponse; +import org.opensearch.client.Client; +import org.opensearch.client.RestHighLevelClient; +import org.opensearch.common.util.FeatureFlags; +import org.opensearch.telemetry.TelemetrySettings; +import org.opensearch.test.framework.AuditCompliance; +import org.opensearch.test.framework.AuditConfiguration; +import org.opensearch.test.framework.AuditFilters; +import org.opensearch.test.framework.TestSecurityConfig.User; +import org.opensearch.test.framework.audit.AuditLogsRule; +import org.opensearch.test.framework.cluster.ClusterManager; +import org.opensearch.test.framework.cluster.LocalCluster; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; +import static org.opensearch.client.RequestOptions.DEFAULT; +import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; +import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS; + +@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) +@ThreadLeakScope(ThreadLeakScope.Scope.NONE) +public class TracingTests { + + private static final User ADMIN_USER = new User("admin").roles(ALL_ACCESS); + + @ClassRule + public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS) + .authc(AUTHC_HTTPBASIC_INTERNAL) + .users(ADMIN_USER) + .nodeSettings( + Map.of( + FeatureFlags.TELEMETRY_SETTING.getKey(), + true, + TelemetrySettings.TRACER_FEATURE_ENABLED_SETTING.getKey(), + true, + TelemetrySettings.METRICS_FEATURE_ENABLED_SETTING.getKey(), + true + ) + ) + .build(); + + @Rule + public AuditLogsRule auditLogsRule = new AuditLogsRule(); + + @Test + public void indexDocumentAndSearch() throws IOException { + try (Client internalClient = cluster.getInternalNodeClient()) { + // Create a document to search + internalClient.prepareIndex("index-1").setRefreshPolicy(IMMEDIATE).setSource(Map.of("foo", "bar")).get(); + } + + try (final RestHighLevelClient restClient = cluster.getRestHighLevelClient(ADMIN_USER)) { + final SearchResponse response = restClient.search(new SearchRequest(), DEFAULT); + assertThat(response.getHits().getTotalHits().value, equalTo(1L)); + } + } +}