فهرست منبع

Fix cat recovery display of bytes fields (#40379)

The cat APIs support the ?bytes parameter to format bytes value. The cat
recovery API does not follow this because the fields were not using
ByteSizeValue. This commit addresses this.
Jason Tedor 6 سال پیش
والد
کامیت
ac5cc15308

+ 4 - 4
docs/reference/cat/recovery.asciidoc

@@ -24,11 +24,11 @@ The response of this request will be something like:
 [source,txt]
 ---------------------------------------------------------------------------
 index   shard time type  stage source_host source_node target_host target_node repository snapshot files files_recovered files_percent files_total bytes bytes_recovered bytes_percent bytes_total translog_ops translog_ops_recovered translog_ops_percent
-twitter 0     13ms store done  n/a         n/a         127.0.0.1   node-0      n/a        n/a      0     0               100%          13          0     0               100%          9928        0            0                      100.0%
+twitter 0     13ms store done  n/a         n/a         127.0.0.1   node-0      n/a        n/a      0     0               100%          13          0b    0b              100%          9928b       0            0                      100.0%
 ---------------------------------------------------------------------------
 // TESTRESPONSE[s/store/empty_store/]
 // TESTRESPONSE[s/100%/0.0%/]
-// TESTRESPONSE[s/9928/0/]
+// TESTRESPONSE[s/9928b/0b/]
 // TESTRESPONSE[s/13ms/\\d+m?s/]
 // TESTRESPONSE[s/13/\\d+/ non_json]
 
@@ -50,8 +50,8 @@ This will return a line like:
 
 [source,txt]
 ----------------------------------------------------------------------------
-i       s t      ty   st    shost       thost       f     fp      b bp
-twitter 0 1252ms peer done  192.168.1.1 192.168.1.2 0     100.0%  0 100.0%
+i       s t      ty   st    shost       thost       f     fp      b  bp
+twitter 0 1252ms peer done  192.168.1.1 192.168.1.2 0     100.0%  0b 100.0%
 ----------------------------------------------------------------------------
 // TESTRESPONSE[s/peer/empty_store/]
 // TESTRESPONSE[s/192.168.1.2/127.0.0.1/]

+ 13 - 10
rest-api-spec/src/main/resources/rest-api-spec/test/cat.recovery/10_basic.yml

@@ -1,5 +1,8 @@
 ---
 "Test cat recovery output":
+  - skip:
+      version: " - 7.99.99"
+      reason: format of bytes output changed in 8.0.0
 
   - do:
       cat.recovery: {}
@@ -35,10 +38,10 @@
                 \d+         \s+                                 # files_recovered
                 \d+\.\d+%   \s+                                 # files_percent
                 \d+         \s+                                 # files_total
-                \d+         \s+                                 # bytes
-                \d+         \s+                                 # bytes_recovered
+                \d+(b|kb|mb|gb|tb|pb) \s+                       # bytes
+                \d+(b|kb|mb|gb|tb|pb) \s+                       # bytes_recovered
                 \d+\.\d+%   \s+                                 # bytes_percent
-                \d+         \s+                                 # bytes_total
+                \d+(b|kb|mb|gb|tb|pb) \s+                       # bytes_total
                 -?\d+       \s+                                 # translog_ops
                 \d+         \s+                                 # translog_ops_recovered
                 -?\d+\.\d+%                                     # translog_ops_percent
@@ -56,7 +59,7 @@
               (
                 \d          \s+                                 # shard
                 ((\S+\s?){1,10})\s+                             # source_node
-                \d+                                             # bytes
+                \d+(b|kb|mb|gb|tb|pb)                           # bytes
                 \n
               )+
               $/
@@ -71,7 +74,7 @@
               (
                 \d          \s+                                 # shard
                 ((\S+\s?){1,10})\s+                             # target_node
-                \d+                                             # bytes
+                \d+(b|kb|mb|gb|tb|pb)                           # bytes
                 \n
               )+
               $/
@@ -79,8 +82,8 @@
 ---
 "Test cat recovery output for closed index":
   - skip:
-      version: " - 7.1.99"
-      reason: closed indices are replicated starting version 7.2.0
+      version: " - 7.9.99"
+      reason: format of bytes output changed in 8.0.0
 
   - do:
       indices.create:
@@ -122,10 +125,10 @@
           \d+         \s+                                 # files_recovered
           \d+\.\d+%   \s+                                 # files_percent
           \d+         \s+                                 # files_total
-          \d+         \s+                                 # bytes
-          \d+         \s+                                 # bytes_recovered
+          \d+(b|kb|mb|gb|tb|pb) \s+                       # bytes
+          \d+(b|kb|mb|gb|tb|pb) \s+                       # bytes_recovered
           \d+\.\d+%   \s+                                 # bytes_percent
-          \d+         \s+                                 # bytes_total
+          \d+(b|kb|mb|gb|tb|pb) \s+                       # bytes_total
           0          \s+                                  # translog_ops (always 0 for closed indices)
           0           \s+                                 # translog_ops_recovered (always 0 for closed indices)
           100\.0%                                         # translog_ops_percent (always 100.0% for closed indices)

+ 4 - 3
server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java

@@ -29,6 +29,7 @@ import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.Table;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.unit.ByteSizeValue;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.XContentElasticsearchExtension;
 import org.elasticsearch.indices.recovery.RecoveryState;
@@ -173,10 +174,10 @@ public class RestCatRecoveryAction extends AbstractCatAction {
                 t.addCell(state.getIndex().recoveredFileCount());
                 t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getIndex().recoveredFilesPercent()));
                 t.addCell(state.getIndex().totalFileCount());
-                t.addCell(state.getIndex().totalRecoverBytes());
-                t.addCell(state.getIndex().recoveredBytes());
+                t.addCell(new ByteSizeValue(state.getIndex().totalRecoverBytes()));
+                t.addCell(new ByteSizeValue(state.getIndex().recoveredBytes()));
                 t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getIndex().recoveredBytesPercent()));
-                t.addCell(state.getIndex().totalBytes());
+                t.addCell(new ByteSizeValue(state.getIndex().totalBytes()));
                 t.addCell(state.getTranslog().totalOperations());
                 t.addCell(state.getTranslog().recoveredOperations());
                 t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getTranslog().recoveredPercent()));

+ 5 - 4
server/src/test/java/org/elasticsearch/rest/action/cat/RestRecoveryActionTests.java → server/src/test/java/org/elasticsearch/rest/action/cat/RestCatRecoveryActionTests.java

@@ -28,6 +28,7 @@ import org.elasticsearch.cluster.routing.TestShardRouting;
 import org.elasticsearch.common.Randomness;
 import org.elasticsearch.common.Table;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.unit.ByteSizeValue;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.XContentElasticsearchExtension;
 import org.elasticsearch.index.Index;
@@ -50,7 +51,7 @@ import static org.elasticsearch.mock.orig.Mockito.when;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.mockito.Mockito.mock;
 
-public class RestRecoveryActionTests extends ESTestCase {
+public class RestCatRecoveryActionTests extends ESTestCase {
 
     public void testRestRecoveryAction() {
         final Settings settings = Settings.EMPTY;
@@ -189,10 +190,10 @@ public class RestRecoveryActionTests extends ESTestCase {
                     state.getIndex().recoveredFileCount(),
                     percent(state.getIndex().recoveredFilesPercent()),
                     state.getIndex().totalFileCount(),
-                    state.getIndex().totalRecoverBytes(),
-                    state.getIndex().recoveredBytes(),
+                    new ByteSizeValue(state.getIndex().totalRecoverBytes()),
+                    new ByteSizeValue(state.getIndex().recoveredBytes()),
                     percent(state.getIndex().recoveredBytesPercent()),
-                    state.getIndex().totalBytes(),
+                    new ByteSizeValue(state.getIndex().totalBytes()),
                     state.getTranslog().totalOperations(),
                     state.getTranslog().recoveredOperations(),
                     percent(state.getTranslog().recoveredPercent()));