-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Added ccr to xpack usage infrastructure #37256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6d4eaa8
Added ccr to xpack usage infrastructure
martijnvg 17aa34e
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg 5e316d7
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg 89cf60a
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg f1c43be
fixed docs test
martijnvg 4f00d67
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg 7ff8d7a
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg ca86d02
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg b60c15c
iter
martijnvg 6363a4d
replace `last_follower_index_creation_date` with `time_since_last_ind…
martijnvg 15cc84c
rename and do not report last_follow_time_in_millis if there are no f…
martijnvg 908f783
Merge remote-tracking branch 'es/master' into ccr_usage_feature_set
martijnvg 476ce0e
fixed test, take into account other tests that leave state behind
martijnvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...k/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/XPackUsageIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ccr; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.RestClient; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
public class XPackUsageIT extends ESCCRRestTestCase { | ||
|
||
public void testXPackCcrUsage() throws Exception { | ||
if ("follow".equals(targetCluster) == false) { | ||
logger.info("skipping test, waiting for target cluster [follow]" ); | ||
return; | ||
} | ||
|
||
Map<?, ?> previousUsage = getCcrUsage(); | ||
putAutoFollowPattern("my_pattern", "leader_cluster", "messages-*"); | ||
|
||
// This index should be auto followed: | ||
createLeaderIndex("messages-20200101"); | ||
// This index will be followed manually | ||
createLeaderIndex("my_index"); | ||
followIndex("my_index", "my_index"); | ||
|
||
int previousFollowerIndicesCount = (Integer) previousUsage.get("follower_indices_count"); | ||
int previousAutoFollowPatternsCount = (Integer) previousUsage.get("auto_follow_patterns_count"); | ||
assertBusy(() -> { | ||
Map<?, ?> ccrUsage = getCcrUsage(); | ||
assertThat(ccrUsage.get("follower_indices_count"), equalTo(previousFollowerIndicesCount + 2)); | ||
assertThat(ccrUsage.get("auto_follow_patterns_count"), equalTo(previousAutoFollowPatternsCount + 1)); | ||
assertThat((Integer) ccrUsage.get("last_follow_time_in_millis"), greaterThanOrEqualTo(0)); | ||
}); | ||
|
||
deleteAutoFollowPattern("my_pattern"); | ||
pauseFollow("messages-20200101"); | ||
closeIndex("messages-20200101"); | ||
unfollow("messages-20200101"); | ||
|
||
pauseFollow("my_index"); | ||
closeIndex("my_index"); | ||
unfollow("my_index"); | ||
|
||
assertBusy(() -> { | ||
Map<?, ?> ccrUsage = getCcrUsage(); | ||
assertThat(ccrUsage.get("follower_indices_count"), equalTo(previousFollowerIndicesCount)); | ||
assertThat(ccrUsage.get("auto_follow_patterns_count"), equalTo(previousAutoFollowPatternsCount)); | ||
if (previousFollowerIndicesCount == 0) { | ||
assertThat(ccrUsage.get("last_follow_time_in_millis"), nullValue()); | ||
} else { | ||
assertThat((Integer) ccrUsage.get("last_follow_time_in_millis"), greaterThanOrEqualTo(0)); | ||
} | ||
}); | ||
} | ||
|
||
private void createLeaderIndex(String indexName) throws IOException { | ||
try (RestClient leaderClient = buildLeaderClient()) { | ||
Settings settings = Settings.builder() | ||
.put("index.soft_deletes.enabled", true) | ||
.build(); | ||
Request request = new Request("PUT", "/" + indexName); | ||
request.setJsonEntity("{\"settings\": " + Strings.toString(settings) + "}"); | ||
assertOK(leaderClient.performRequest(request)); | ||
} | ||
} | ||
|
||
private Map<?, ?> getCcrUsage() throws IOException { | ||
Request request = new Request("GET", "/_xpack/usage"); | ||
Map<String, ?> response = toMap(client().performRequest(request)); | ||
logger.info("xpack usage response={}", response); | ||
return (Map<?, ?>) response.get("ccr"); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRFeatureSetTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ccr; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.support.PlainActionFuture; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata; | ||
import org.elasticsearch.xpack.core.ccr.CCRFeatureSet; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class CCRFeatureSetTests extends ESTestCase { | ||
|
||
private XPackLicenseState licenseState; | ||
private ClusterService clusterService; | ||
|
||
@Before | ||
public void init() throws Exception { | ||
licenseState = mock(XPackLicenseState.class); | ||
clusterService = mock(ClusterService.class); | ||
} | ||
|
||
public void testAvailable() { | ||
CCRFeatureSet featureSet = new CCRFeatureSet(Settings.EMPTY, licenseState, clusterService); | ||
|
||
when(licenseState.isCcrAllowed()).thenReturn(false); | ||
assertThat(featureSet.available(), equalTo(false)); | ||
|
||
when(licenseState.isCcrAllowed()).thenReturn(true); | ||
assertThat(featureSet.available(), equalTo(true)); | ||
|
||
featureSet = new CCRFeatureSet(Settings.EMPTY, null, clusterService); | ||
assertThat(featureSet.available(), equalTo(false)); | ||
} | ||
|
||
public void testEnabled() { | ||
Settings.Builder settings = Settings.builder().put("xpack.ccr.enabled", false); | ||
CCRFeatureSet featureSet = new CCRFeatureSet(settings.build(), licenseState, clusterService); | ||
assertThat(featureSet.enabled(), equalTo(false)); | ||
|
||
settings = Settings.builder().put("xpack.ccr.enabled", true); | ||
featureSet = new CCRFeatureSet(settings.build(), licenseState, clusterService); | ||
assertThat(featureSet.enabled(), equalTo(true)); | ||
} | ||
|
||
public void testName() { | ||
CCRFeatureSet featureSet = new CCRFeatureSet(Settings.EMPTY, licenseState, clusterService); | ||
assertThat(featureSet.name(), equalTo("ccr")); | ||
} | ||
|
||
public void testNativeCodeInfo() { | ||
CCRFeatureSet featureSet = new CCRFeatureSet (Settings.EMPTY, licenseState, clusterService); | ||
assertNull(featureSet.nativeCodeInfo()); | ||
} | ||
|
||
public void testUsageStats() throws Exception { | ||
MetaData.Builder metaData = MetaData.builder(); | ||
|
||
int numFollowerIndices = randomIntBetween(0, 32); | ||
for (int i = 0; i < numFollowerIndices; i++) { | ||
IndexMetaData.Builder followerIndex = IndexMetaData.builder("follow_index" + i) | ||
.settings(settings(Version.CURRENT).put(CcrSettings.CCR_FOLLOWING_INDEX_SETTING.getKey(), true)) | ||
.numberOfShards(1) | ||
.numberOfReplicas(0) | ||
.creationDate(i) | ||
.putCustom(Ccr.CCR_CUSTOM_METADATA_KEY, new HashMap<>()); | ||
metaData.put(followerIndex); | ||
} | ||
|
||
// Add a regular index, to check that we do not take that one into account: | ||
IndexMetaData.Builder regularIndex = IndexMetaData.builder("my_index") | ||
.settings(settings(Version.CURRENT)) | ||
.numberOfShards(1) | ||
.numberOfReplicas(0) | ||
.creationDate(numFollowerIndices); | ||
metaData.put(regularIndex); | ||
|
||
int numAutoFollowPatterns = randomIntBetween(0, 32); | ||
Map<String, AutoFollowMetadata.AutoFollowPattern> patterns = new HashMap<>(numAutoFollowPatterns); | ||
for (int i = 0; i < numAutoFollowPatterns; i++) { | ||
AutoFollowMetadata.AutoFollowPattern pattern = new AutoFollowMetadata.AutoFollowPattern("remote_cluser", | ||
Collections.singletonList("logs" + i + "*"), null, null, null, null, null, null, null, null, null, null, null); | ||
patterns.put("pattern" + i, pattern); | ||
} | ||
metaData.putCustom(AutoFollowMetadata.TYPE, new AutoFollowMetadata(patterns, Collections.emptyMap(), Collections.emptyMap())); | ||
|
||
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).metaData(metaData).build(); | ||
Mockito.when(clusterService.state()).thenReturn(clusterState); | ||
|
||
PlainActionFuture<XPackFeatureSet.Usage> future = new PlainActionFuture<>(); | ||
CCRFeatureSet ccrFeatureSet = new CCRFeatureSet(Settings.EMPTY, licenseState, clusterService); | ||
ccrFeatureSet.usage(future); | ||
CCRFeatureSet.Usage ccrUsage = (CCRFeatureSet.Usage) future.get(); | ||
assertThat(ccrUsage.enabled(), equalTo(ccrFeatureSet.enabled())); | ||
assertThat(ccrUsage.available(), equalTo(ccrFeatureSet.available())); | ||
|
||
assertThat(ccrUsage.getNumberOfFollowerIndices(), equalTo(numFollowerIndices)); | ||
assertThat(ccrUsage.getLastFollowTimeInMillis(), greaterThanOrEqualTo(0L)); | ||
assertThat(ccrUsage.getNumberOfAutoFollowPatterns(), equalTo(numAutoFollowPatterns)); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRFeatureSetUsageTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.ccr; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
import org.elasticsearch.xpack.core.ccr.CCRFeatureSet; | ||
|
||
public class CCRFeatureSetUsageTests extends AbstractWireSerializingTestCase<CCRFeatureSet.Usage> { | ||
|
||
@Override | ||
protected CCRFeatureSet.Usage createTestInstance() { | ||
return new CCRFeatureSet.Usage(randomBoolean(), randomBoolean(), randomIntBetween(0, Integer.MAX_VALUE), | ||
randomIntBetween(0, Integer.MAX_VALUE), randomNonNegativeLong()); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<CCRFeatureSet.Usage> instanceReader() { | ||
return CCRFeatureSet.Usage::new; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.