Skip to content

Commit 9501233

Browse files
author
Ali Beyad
committed
Output all empty snapshot info fields if in verbose mode (#25455)
In #24477, a less verbose option was added to retrieve snapshot info via GET /_snapshot/{repo}/{snapshots}. The point of adding this less verbose option was so that if the repository is a cloud based one, and there are many snapshots for which the snapshot info needed to be retrieved, then each snapshot would require reading a separate snapshot metadata file to pull out the necessary information. This can be costly (performance and cost) on cloud based repositories, so a less verbose option was added that only retrieves very basic information about each snapshot that is all available in the index-N blob - requiring only one read! In order to display this less verbose snapshot info appropriately, logic was added to not display those fields which could not be populated. However, this broke integrators (e.g. ECE) that required these fields to be present, even if empty. This commit is to return these fields in the response, even if empty, if the verbose option is set.
1 parent 5573f83 commit 9501233

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ public class GetSnapshotsRequest extends MasterNodeRequest<GetSnapshotsRequest>
3737

3838
public static final String ALL_SNAPSHOTS = "_all";
3939
public static final String CURRENT_SNAPSHOT = "_current";
40+
public static final boolean DEFAULT_VERBOSE_MODE = true;
4041

4142
private String repository;
4243

4344
private String[] snapshots = Strings.EMPTY_ARRAY;
4445

4546
private boolean ignoreUnavailable;
4647

47-
private boolean verbose = true;
48+
private boolean verbose = DEFAULT_VERBOSE_MODE;
4849

4950
public GetSnapshotsRequest() {
5051
}

core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.ElasticsearchParseException;
2222
import org.elasticsearch.Version;
2323
import org.elasticsearch.action.ShardOperationFailedException;
24+
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
2425
import org.elasticsearch.common.Nullable;
2526
import org.elasticsearch.common.io.stream.StreamInput;
2627
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -346,6 +347,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
346347
return toXContentSnapshot(builder, params);
347348
}
348349

350+
final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE);
349351
// write snapshot info for the API and any other situations
350352
builder.startObject();
351353
builder.field(SNAPSHOT, snapshotId.getName());
@@ -359,22 +361,22 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
359361
builder.value(index);
360362
}
361363
builder.endArray();
362-
if (state != null) {
364+
if (verbose || state != null) {
363365
builder.field(STATE, state);
364366
}
365367
if (reason != null) {
366368
builder.field(REASON, reason);
367369
}
368-
if (startTime != 0) {
370+
if (verbose || startTime != 0) {
369371
builder.field(START_TIME, DATE_TIME_FORMATTER.printer().print(startTime));
370372
builder.field(START_TIME_IN_MILLIS, startTime);
371373
}
372-
if (endTime != 0) {
374+
if (verbose || endTime != 0) {
373375
builder.field(END_TIME, DATE_TIME_FORMATTER.printer().print(endTime));
374376
builder.field(END_TIME_IN_MILLIS, endTime);
375377
builder.timeValueField(DURATION_IN_MILLIS, DURATION, endTime - startTime);
376378
}
377-
if (!shardFailures.isEmpty()) {
379+
if (verbose || !shardFailures.isEmpty()) {
378380
builder.startArray(FAILURES);
379381
for (SnapshotShardFailure shardFailure : shardFailures) {
380382
builder.startObject();
@@ -383,7 +385,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
383385
}
384386
builder.endArray();
385387
}
386-
if (totalShards != 0) {
388+
if (verbose || totalShards != 0) {
387389
builder.startObject(SHARDS);
388390
builder.field(TOTAL, totalShards);
389391
builder.field(FAILED, failedShards());

rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ setup:
3232
snapshot: test_snapshot
3333

3434
- is_true: snapshots
35+
- is_true: snapshots.0.failures
3536

3637
- do:
3738
snapshot.delete:
@@ -87,6 +88,8 @@ setup:
8788
- is_true: snapshots
8889
- match: { snapshots.0.snapshot: test_snapshot }
8990
- match: { snapshots.0.state: SUCCESS }
91+
- is_false: snapshots.0.failures
92+
- is_false: snapshots.0.shards
9093
- is_false: snapshots.0.version
9194

9295
- do:

0 commit comments

Comments
 (0)