Skip to content

Commit

Permalink
Create GET _cat/transforms API Issue (elastic#53643)
Browse files Browse the repository at this point in the history
Adds new` _cat/transform` and `_cat/transform/{transform_id}` endpoints.
  • Loading branch information
zacharymorn authored and benwtrent committed Mar 18, 2020
1 parent e5aa090 commit ab2a3be
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* 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.ml.rest.cat;

package org.elasticsearch.xpack.core.common.table;

import org.elasticsearch.common.Strings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.xpack.core.common.table.TableColumnAttributeBuilder;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestActionListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.xpack.core.common.table.TableColumnAttributeBuilder;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.xpack.core.common.table.TableColumnAttributeBuilder;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.rest.RestRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.xpack.core.common.table.TableColumnAttributeBuilder;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.rest.RestRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"transform.cat_transform":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-transform.html"
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_cat/transform",
"methods":[
"GET"
]
},
{
"path":"/_cat/transform/{transform_id}",
"methods":[
"GET"
],
"parts":{
"transform_id":{
"type":"string",
"description":"The id of the transform for which to get stats. '_all' or '*' implies all transforms"
}
}
}
]
},
"params":{
"from":{
"type":"int",
"required":false,
"description":"skips a number of transform configs, defaults to 0"
},
"size":{
"type":"int",
"required":false,
"description":"specifies a max number of transforms to get, defaults to 100"
},
"allow_no_match":{
"type":"boolean",
"required":false,
"description":"Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)"
},
"format":{
"type":"string",
"description":"a short version of the Accept header, e.g. json, yaml"
},
"h":{
"type":"list",
"description":"Comma-separated list of column names to display"
},
"help":{
"type":"boolean",
"description":"Return help information",
"default":false
},
"s":{
"type":"list",
"description":"Comma-separated list of column names or column aliases to sort by"
},
"time":{
"type":"enum",
"description":"The unit in which to display time values",
"options":[
"d (Days)",
"h (Hours)",
"m (Minutes)",
"s (Seconds)",
"ms (Milliseconds)",
"micros (Microseconds)",
"nanos (Nanoseconds)"
]
},
"v":{
"type":"boolean",
"description":"Verbose mode. Display column headers",
"default":false
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
setup:
- skip:
features: headers
- do:
indices.create:
index: airline-data
body:
mappings:
properties:
time:
type: date
airline:
type: keyword
responsetime:
type: float
event_rate:
type: integer
- do:
indices.create:
index: airline-data-other
body:
mappings:
properties:
time:
type: date
airline:
type: keyword
responsetime:
type: float
event_rate:
type: integer
- do:
transform.put_transform:
transform_id: "airline-transform-stats"
body: >
{
"source": { "index": "airline-data" },
"dest": { "index": "airline-data-by-airline" },
"pivot": {
"group_by": { "airline": {"terms": {"field": "airline"}}},
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
}
}
---
teardown:
- do:
transform.delete_transform:
transform_id: "airline-transform-stats"

---
"Test cat transform stats hiding headers":
- do:
transform.cat_transform:
transform_id: "airline-transform-stats"
- match:
$body: |
/^ #id \s+ create_time \s+ version \s+ source_index \s+ dest_index \s+ pipeline \s+ transform_type \s+ frequency \s+ max_page_search_size \s+ state \n
(airline\-transform\-stats \s+ [^\s]+ \s+ [^\s]+ \s+ airline-data \s+ airline-data-by-airline \s+ \s+ batch \s+ 1m \s+ 500 \s+ STOPPED \n)+ $/
---
"Test cat transform stats with column selection":
- do:
transform.cat_transform:
transform_id: "airline-transform-stats"
v: true
h: id,version,source_index,dest_index,search_total,index_total,dt,cdtea,indexed_documents_exp_avg
- match:
$body: |
/^ id \s+ version \s+ source_index \s+ dest_index \s+ search_total \s+ index_total \s+ dt \s+ cdtea \s+ indexed_documents_exp_avg \n
(airline\-transform-stats \s+ [^\s]+ \s+ airline-data \s+ airline-data-by-airline \s+ 0 \s+ 0 \s+ 0 \s+ 0.0 \s+ 0.0 \n)+ $/
---
"Test cat transform stats with batch transform":
- do:
transform.put_transform:
transform_id: "airline-transform-batch"
body: >
{
"source": {
"index": ["airline-data", "airline-data-other"],
"query": {"bool":{"filter":{"term":{"airline":"foo"}}}}
},
"dest": { "index": "airline-data-by-airline-batch" },
"pivot": {
"group_by": { "airline": {"terms": {"field": "airline"}}},
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
},
"description": "description"
}
- do:
transform.cat_transform:
transform_id: "airline-transform-batch"
v: true
- match:
$body: |
/^ id \s+ create_time \s+ version \s+ source_index \s+ dest_index \s+ pipeline \s+ description \s+ transform_type \s+ frequency \s+ max_page_search_size \s+ state \n
(airline\-transform\-batch \s+ [^\s]+ \s+ [^\s]+ \s+ airline-data,airline-data-other \s+ airline-data-by-airline-batch \s+ \s+ description \s+ batch \s+ 1m \s+ 500 \s+ STOPPED \n)+ $/
- do:
transform.delete_transform:
transform_id: "airline-transform-batch"

---
"Test cat transform stats with continuous transform":
- do:
transform.put_transform:
transform_id: "airline-transform-continuous"
body: >
{
"source": {
"index": ["airline-data", "airline-data-other"],
"query": {"bool":{"filter":{"term":{"airline":"foo"}}}}
},
"dest": { "index": "airline-data-by-airline-continuous" },
"frequency": "10s",
"pivot": {
"group_by": { "airline": {"terms": {"field": "airline"}}},
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
},
"description": "description",
"sync": {
"time": {
"field": "time"
}
}
}
- do:
transform.cat_transform:
transform_id: "airline-transform-continuous"
v: true
- match:
$body: |
/^ id \s+ create_time \s+ version \s+ source_index \s+ dest_index \s+ pipeline \s+ description \s+ transform_type \s+ frequency \s+ max_page_search_size \s+ state \n
(airline\-transform\-continuous \s+ [^\s]+ \s+ [^\s]+ \s+ airline-data,airline-data-other \s+ airline-data-by-airline-continuous \s+ \s+ description \s+ continuous \s+ 10s \s+ 500 \s+ STOPPED \n)+ $/
- do:
transform.delete_transform:
transform_id: "airline-transform-continuous"
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.elasticsearch.xpack.transform.persistence.IndexBasedTransformConfigManager;
import org.elasticsearch.xpack.transform.persistence.TransformConfigManager;
import org.elasticsearch.xpack.transform.persistence.TransformInternalIndex;
import org.elasticsearch.xpack.transform.rest.action.RestCatTransformAction;
import org.elasticsearch.xpack.transform.rest.action.RestDeleteTransformAction;
import org.elasticsearch.xpack.transform.rest.action.RestGetTransformAction;
import org.elasticsearch.xpack.transform.rest.action.RestGetTransformStatsAction;
Expand Down Expand Up @@ -215,6 +216,7 @@ public List<RestHandler> getRestHandlers(
new RestGetTransformStatsAction(),
new RestPreviewTransformAction(),
new RestUpdateTransformAction(),
new RestCatTransformAction(),

// deprecated endpoints, to be removed for 8.0.0
new RestPutTransformActionDeprecated(),
Expand Down
Loading

0 comments on commit ab2a3be

Please sign in to comment.