Skip to content

Commit

Permalink
Create new test class for validation of tracing features
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <petern@amazon.com>
  • Loading branch information
peternied committed Oct 20, 2023
1 parent 2842688 commit f7cae91
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
79 changes: 79 additions & 0 deletions src/integrationTest/java/org/opensearch/security/TracingTests.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
}

0 comments on commit f7cae91

Please sign in to comment.