Skip to content

Commit

Permalink
Add support for documented byte/size units and for micros as a time u…
Browse files Browse the repository at this point in the history
…nit in _cat API

We advertise in our documentation that byte units are like `kb`, `mb`... But we actually only support the simple notation `k` or `m`.
This commit adds support for the documented form and keeps the non documented options to avoid any breaking change.

It also adds support for `micros`, `nanos` and `d` as a time unit in `_cat` API.

Remove the support for `b` as a SizeValue unit. Actually, for numbers, when using raw numbers without unit, there is no text to add/parse after the number. For example, you don't write `10` as `10b`. We support option like `size=` in `_cat` API which means that we want to display raw data without unit (singles).

Documentation updated accordingly.

Add test for the empty size option.

Fix missing TimeValues options for some cat APIs
  • Loading branch information
dadoonet committed Apr 15, 2016
1 parent 65803f8 commit 5e1f26c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ public static SizeValue parseSizeValue(String sValue, SizeValue defaultValue) th
}
long singles;
try {
if (sValue.endsWith("b")) {
singles = Long.parseLong(sValue.substring(0, sValue.length() - 1));
} else if (sValue.endsWith("k") || sValue.endsWith("K")) {
if (sValue.endsWith("k") || sValue.endsWith("K")) {
singles = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * SizeUnit.C1);
} else if (sValue.endsWith("m") || sValue.endsWith("M")) {
singles = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * SizeUnit.C2);
Expand Down Expand Up @@ -232,4 +230,4 @@ public int hashCode() {
result = 31 * result + (sizeUnit != null ? sizeUnit.hashCode() : 0);
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ private static String renderValue(RestRequest request, Object value) {
String resolution = request.param("bytes");
if ("b".equals(resolution)) {
return Long.toString(v.bytes());
} else if ("k".equals(resolution)) {
} else if ("k".equals(resolution) || "kb".equals(resolution)) {
return Long.toString(v.kb());
} else if ("m".equals(resolution)) {
} else if ("m".equals(resolution) || "mb".equals(resolution)) {
return Long.toString(v.mb());
} else if ("g".equals(resolution)) {
} else if ("g".equals(resolution) || "gb".equals(resolution)) {
return Long.toString(v.gb());
} else if ("t".equals(resolution)) {
} else if ("t".equals(resolution) || "tb".equals(resolution)) {
return Long.toString(v.tb());
} else if ("p".equals(resolution)) {
} else if ("p".equals(resolution) || "pb".equals(resolution)) {
return Long.toString(v.pb());
} else {
return v.toString();
Expand All @@ -320,7 +320,7 @@ private static String renderValue(RestRequest request, Object value) {
if (value instanceof SizeValue) {
SizeValue v = (SizeValue) value;
String resolution = request.param("size");
if ("b".equals(resolution)) {
if ("".equals(resolution)) {
return Long.toString(v.singles());
} else if ("k".equals(resolution)) {
return Long.toString(v.kilo());
Expand All @@ -339,14 +339,20 @@ private static String renderValue(RestRequest request, Object value) {
if (value instanceof TimeValue) {
TimeValue v = (TimeValue) value;
String resolution = request.param("time");
if ("ms".equals(resolution)) {
if ("nanos".equals(resolution)) {
return Long.toString(v.nanos());
} else if ("micros".equals(resolution)) {
return Long.toString(v.micros());
} else if ("ms".equals(resolution)) {
return Long.toString(v.millis());
} else if ("s".equals(resolution)) {
return Long.toString(v.seconds());
} else if ("m".equals(resolution)) {
return Long.toString(v.minutes());
} else if ("h".equals(resolution)) {
return Long.toString(v.hours());
} else if ("d".equals(resolution)) {
return Long.toString(v.days());
} else {
return v.toString();
}
Expand Down
25 changes: 22 additions & 3 deletions docs/reference/api-conventions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,14 @@ are:
`m`:: Minute
`s`:: Second
`ms`:: Milli-second
`micros`:: Micro-second
`nanos`:: Nano-second

[[size-units]]
[[byte-units]]
[float]
=== Data size units
=== Byte size units

Whenever the size of data needs to be specified, eg when setting a buffer size
Whenever the byte size of data needs to be specified, eg when setting a buffer size
parameter, the value must specify the unit, like `10kb` for 10 kilobytes. The
supported units are:

Expand All @@ -378,6 +380,23 @@ supported units are:
`tb`:: Terabytes
`pb`:: Petabytes

[[size-units]]
[float]
=== Unit-less quantities

Unit-less quantities means that they don't have a "unit" like "bytes" or "Hertz" or "meter" or "long tonne".

If one of these quantities is large we'll print it out like 10m for 10,000,000 or 7k for 7,000. We'll still print 87
when we mean 87 though. These are the supported multipliers:

[horizontal]
``:: Single
`k`:: Kilo
`m`:: Mega
`g`:: Giga
`t`:: Tera
`p`:: Peta

[[distance-units]]
[float]
=== Distance Units
Expand Down
10 changes: 8 additions & 2 deletions docs/reference/cat.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ with `bulk.`.
[[numeric-formats]]
=== Numeric formats

Many commands provide a few types of numeric output, either a byte
value or a time value. By default, these types are human-formatted,
Many commands provide a few types of numeric output, either a byte, size
or a time value. By default, these types are human-formatted,
for example, `3.5mb` instead of `3763212`. The human values are not
sortable numerically, so in order to operate on these values where
order is important, you can change it.
Expand All @@ -95,6 +95,12 @@ green wiki1 3 0 10000 413 103776272 103776272
green foo 1 0 227 0 2065131 2065131
--------------------------------------------------

If you want to change the <<time-units,time units>>, use `time` parameter.

If you want to change the <<size-units,size units>>, use `size` parameter.

If you want to change the <<byte-units,byte units>>, use `bytes` parameter.

[float]
=== Response as text, json, smile, yaml or cbor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"bytes": {
"type": "enum",
"description" : "The unit in which to display byte values",
"options": [ "b", "k", "m", "g" ]
"options": [ "b", "k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb" ]
},
"local": {
"type" : "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"bytes": {
"type": "enum",
"description" : "The unit in which to display byte values",
"options": [ "b", "k", "m", "g" ]
"options": [ "b", "k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb" ]
},
"local": {
"type" : "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"bytes": {
"type": "enum",
"description" : "The unit in which to display byte values",
"options": [ "b", "k", "m", "g" ]
"options": [ "b", "k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb" ]
},
"master_timeout": {
"type" : "time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"type" : "string",
"description" : "a short version of the Accept header, e.g. json, yaml"
},
"size": {
"type": "enum",
"description" : "The multiplier in which to display values",
"options": [ "", "k", "m", "g", "t", "p" ]
},
"local": {
"type" : "boolean",
"description" : "Return local information, do not retrieve the state from master node (default: false)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

- do:
cat.allocation:
bytes: g
bytes: gb

- match:
$body: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@
$body: |
/^ id \s+ warmer.type \s+ warmer.active \s+ warmer.size \s+ warmer.queue \s+ warmer.queueSize \s+ warmer.rejected \s+ warmer.largest \s+ warmer.completed \s+ warmer.min \s+ warmer.max \s+ warmer.keepAlive \n
(\S+ \s+ (cached|fixed|scaling)? \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d* \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d* \s+ \d* \s+ \S* \n)+ $/
- do:
cat.thread_pool:
size: ""

- match:
$body: |
/ #host ip bulk.active bulk.queue bulk.rejected index.active index.queue index.rejected search.active search.queue search.rejected
^ (\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \n)+ $/

0 comments on commit 5e1f26c

Please sign in to comment.