Skip to content
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

Ensure SLM stats does not block an in-place upgrade from 7.4 #48361

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class SnapshotLifecycleMetadata implements XPackMetaDataCustom {
throw new IllegalArgumentException("ordered " + POLICIES_FIELD.getPreferredName() + " are not supported");
}, POLICIES_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), OPERATION_MODE_FIELD);
PARSER.declareObject(ConstructingObjectParser.constructorArg(), (v, o) -> SnapshotLifecycleStats.parse(v), STATS_FIELD);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (v, o) -> SnapshotLifecycleStats.parse(v), STATS_FIELD);
}

private final Map<String, SnapshotLifecyclePolicyMetadata> snapshotConfigurations;
Expand All @@ -74,7 +74,7 @@ public SnapshotLifecycleMetadata(Map<String, SnapshotLifecyclePolicyMetadata> sn
SnapshotLifecycleStats slmStats) {
this.snapshotConfigurations = new HashMap<>(snapshotConfigurations);
this.operationMode = operationMode;
this.slmStats = slmStats;
this.slmStats = slmStats != null ? slmStats : new SnapshotLifecycleStats();
}

public SnapshotLifecycleMetadata(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectPath;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.document.RestGetAction;
Expand All @@ -21,6 +25,7 @@
import org.elasticsearch.test.StreamsUtils;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase;
import org.elasticsearch.xpack.slm.SnapshotLifecycleStats;
import org.hamcrest.Matcher;
import org.junit.Before;

Expand Down Expand Up @@ -437,6 +442,21 @@ public void testSqlFailsOnIndexWithTwoTypes() throws IOException {
"[testsqlfailsonindexwithtwotypes] contains more than one type [type1, type2] so it is incompatible with sql"));
}

public void testSlmStats() throws IOException {
//need to stop and start ILM to ensure that SLM metadata is written to cluster state
if (isRunningAgainstOldCluster()) {
client().performRequest(new Request("POST", "_ilm/stop"));
client().performRequest(new Request("POST", "_ilm/start"));
Comment on lines +448 to +449
Copy link
Contributor

@gwbrown gwbrown Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of #47710, we should PUT a policy here rather than starting/stopping.

Here's an example repository/policy you can PUT that will execute every February 31 (i.e. never):

PUT /_snapshot/test-repo
{
  "type": "fs",
  "settings": {
    "location": "test-repo"
  }
}

PUT /_slm/policy/test-policy
{
  "schedule": "* * * 31 FEB ? *", 
  "name": "<test-snap-{now/d}>", 
  "repository": "test-repo", 
  "config": { 
    "indices": ["*"] 
  }
}

} else {
Response response = client().performRequest(new Request("GET", "_slm/stats"));
XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, response.getEntity().getContent())) {
assertEquals(new SnapshotLifecycleStats(), SnapshotLifecycleStats.parse(parser));
}
}
}

private String loadWatch(String watch) throws IOException {
return StreamsUtils.copyToStringFromClasspath("/org/elasticsearch/xpack/restart/" + watch);
}
Expand Down