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

[TSDB] Metric fields in the field caps API #88695

Merged
merged 19 commits into from
Aug 4, 2022
Merged
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
5 changes: 5 additions & 0 deletions docs/changelog/88695.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 88695
summary: "[TSDB] Metric fields in the field caps API"
area: TSDB
type: enhancement
issues: []
10 changes: 6 additions & 4 deletions docs/reference/search/field-caps.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ field types are all described as the `keyword` type family.

`time_series_dimension`::
preview:[]
Whether this field is used as a time series dimension.
Whether this field is used as a time series dimension on all indices.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kilfoyle Maybe you have a better take on the doc changes here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good now! 👍

For non-time-series indices this field is not present.

`time_series_metric`::
preview:[]
Contains metric type if this fields is used as a time series metrics, absent if the field is not used as metric.
Contains the metric type if the field is used as a time series metric on all indices, absent if the field is
not used as a metric. For non-time-series indices this field is not included.

`indices`::
The list of indices where this field has the same type family, or null if all indices
Expand All @@ -157,12 +159,12 @@ field types are all described as the `keyword` type family.

`non_dimension_indices`::
experimental:[]
If this list is present in response then some indices have the field marked as a dimension and other indices, the
If this list is present in the response, some indices have the field marked as a dimension and other indices, the
ones in this list, do not.

`metric_conflicts_indices`::
experimental:[]
The list of indices where this field is present if these indices don't have the same `time_series_metric` value for
The list of indices where this field is present, if these indices don't have the same `time_series_metric` value for
this field.

`meta`::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ setup:
index:
number_of_replicas: 0
number_of_shards: 2
mode: time_series
routing_path: [ metricset, k8s.pod.uid ]
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mappings:
properties:
"@timestamp":
Expand Down Expand Up @@ -59,6 +64,11 @@ setup:
index:
number_of_replicas: 0
number_of_shards: 2
mode: time_series
routing_path: [ k8s.pod.uid ]
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mappings:
properties:
"@timestamp":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ can't shadow metrics:
# Test that _tsid field is not added if an index is not a time-series index
no _tsid in standard indices:
- skip:
version: " - 8.0.99"
reason: _tsid support introduced in 8.1.0
version: " - 8.4.99"
reason: time series params only on time series indices introduced in 8.5.0

- do:
indices.create:
Expand All @@ -209,11 +209,11 @@ no _tsid in standard indices:

- match: {fields.metricset.keyword.searchable: true}
- match: {fields.metricset.keyword.aggregatable: true}
- match: {fields.metricset.keyword.time_series_dimension: true}
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices
- is_false: fields._tsid # _tsid metadata field must not exist in non-time-series indices
- is_false: fields.metricset.keyword.time_series_dimension # time_series_dimension param is ignored in non-time-series indices

---
no nested dimensions:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
setup:
- skip:
version: " - 8.4.99"
reason: metric params only on time series indexes introduced in 8.5.0

- do:
indices.create:
index: test_time_series
body:
settings:
index:
number_of_replicas: 0
number_of_shards: 2
mode: time_series
routing_path: [ metricset, k8s.pod.uid ]
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true
k8s:
properties:
pod:
properties:
availability_zone:
type: short
time_series_dimension: true
uid:
type: keyword
time_series_dimension: true
name:
type: keyword
ip:
type: ip
time_series_dimension: true
network:
properties:
tx:
type: long
time_series_metric: counter
rx:
type: long
time_series_metric: gauge

- do:
indices.create:
index: test_non_time_series
body:
settings:
index:
number_of_replicas: 0
number_of_shards: 2
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true
k8s:
properties:
pod:
properties:
availability_zone:
type: short
time_series_dimension: true
uid:
type: keyword
time_series_dimension: true
name:
type: keyword
ip:
type: ip
time_series_dimension: true
network:
properties:
tx:
type: long
time_series_metric: counter
rx:
type: long
time_series_metric: gauge

---
field caps on time_series indices:
- skip:
version: " - 8.3.99"
reason: metric params only on time series indexes introduced in 8.4.0

- do:
field_caps:
index: test_time_series
fields: [ k8s.pod.uid, k8s.pod.network.rx, k8s.pod.network.tx, k8s.pod.ip, metricset, _tsid ]

- match: { fields.k8s\.pod\.uid.keyword.type: keyword }
- match: { fields.k8s\.pod\.uid.keyword.searchable: true }
- match: { fields.k8s\.pod\.uid.keyword.aggregatable: true }
- match: { fields.k8s\.pod\.uid.keyword.time_series_dimension: true }
- is_false: fields.k8s\.pod\.uid.keyword.indices
- is_false: fields.k8s\.pod\.uid.keyword.non_searchable_indices
- is_false: fields.k8s\.pod\.uid.keyword.non_aggregatable_indices

- match: { fields.k8s\.pod\.network\.rx.long.type: long }
- match: { fields.k8s\.pod\.network\.rx.long.searchable: true }
- match: { fields.k8s\.pod\.network\.rx.long.aggregatable: true }
- match: { fields.k8s\.pod\.network\.rx.long.time_series_metric: gauge }
- is_false: fields.k8s\.pod\.network\.tx.long.metric_conflicts_indices
- is_false: fields.k8s\.pod\.network\.rx.long.indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_aggregatable_indices


- match: { fields.k8s\.pod\.network\.tx.long.type: long }
- match: { fields.k8s\.pod\.network\.tx.long.searchable: true }
- match: { fields.k8s\.pod\.network\.tx.long.aggregatable: true }
- match: { fields.k8s\.pod\.network\.tx.long.time_series_metric: counter }
- is_false: fields.k8s\.pod\.network\.tx.long.metric_conflicts_indices
- is_false: fields.k8s\.pod\.network\.tx.long.indices
- is_false: fields.k8s\.pod\.network\.tx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.tx.long.non_aggregatable_indices

- match: { fields.k8s\.pod\.ip.ip.type: ip }
- match: { fields.k8s\.pod\.ip.ip.searchable: true }
- match: { fields.k8s\.pod\.ip.ip.aggregatable: true }
- is_false: fields.k8s\.pod\.ip.ip.indices
- is_false: fields.k8s\.pod\.ip.ip.non_searchable_indices
- is_false: fields.k8s\.pod\.ip.ip.non_aggregatable_indices

- match: { fields.metricset.keyword.type: keyword }
- match: { fields.metricset.keyword.searchable: true }
- match: { fields.metricset.keyword.aggregatable: true }
- match: { fields.metricset.keyword.time_series_dimension: true }
- is_false: fields.metricset.keyword.non_dimension_indices
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices

- match: { fields._tsid._tsid.metadata_field: true }
- match: { fields._tsid._tsid.searchable: false }
- match: { fields._tsid._tsid.aggregatable: true }
- is_false: fields._tsid._tsid.indices
- is_false: fields._tsid._tsid.non_searchable_indices
- is_false: fields._tsid._tsid.non_aggregatable_indices


---
field caps on standard indices:
- skip:
version: " - 8.3.99"
reason: metric params only on time series indexes introduced in 8.4.0

- do:
field_caps:
index: test_non_time_series
fields: [ _tsid, metricset, k8s.pod.network.rx, k8s.pod.network.tx, k8s.pod.network.rx ]

- match: { fields.metricset.keyword.type: keyword }
- match: { fields.metricset.keyword.searchable: true }
- match: { fields.metricset.keyword.aggregatable: true }
- is_false: fields.metricset.keyword.time_series_dimension
- is_false: fields.metricset.keyword.non_dimension_indices
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices

- is_false: fields._tsid # _tsid metadata field must not exist in non-time-series indices

- match: { fields.k8s\.pod\.network\.rx.long.type: long }
- match: { fields.k8s\.pod\.network\.rx.long.searchable: true }
- match: { fields.k8s\.pod\.network\.rx.long.aggregatable: true }
- is_false: fields.k8s\.pod\.network\.rx.long.time_series_metric
- is_false: fields.k8s\.pod\.network\.rx.long.metric_conflicts_indices
- is_false: fields.k8s\.pod\.network\.rx.long.indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_aggregatable_indices
- is_false: fields.k8s\.pod\.network\.rx.gauge

- match: { fields.k8s\.pod\.network\.tx.long.type: long }
- match: { fields.k8s\.pod\.network\.tx.long.searchable: true }
- match: { fields.k8s\.pod\.network\.tx.long.aggregatable: true }
- is_false: fields.k8s\.pod\.network\.tx.long.time_series_metric
- is_false: fields.k8s\.pod\.network\.tx.long.metric_conflicts_indices
- is_false: fields.k8s\.pod\.network\.tx.long.indices
- is_false: fields.k8s\.pod\.network\.tx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.tx.long.non_aggregatable_indices
- is_false: fields.k8s\.pod\.network\.tx.counter


---
field caps on mixed indices:
- skip:
version: " - 8.3.99"
reason: metric params only on time series indexes introduced in 8.4.0

- do:
field_caps:
index: test_*
fields: [ metricset, k8s.pod.availability_zone, k8s.pod.network.tx, k8s.pod.network.rx ]

- match: { fields.metricset.keyword.type: keyword }
- match: { fields.metricset.keyword.searchable: true }
- match: { fields.metricset.keyword.aggregatable: true }
- is_false: fields.metricset.keyword.time_series_dimension
- match: { fields.metricset.keyword.non_dimension_indices: [ "test_non_time_series" ] }
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices

- match: { fields.k8s\.pod\.network\.rx.long.type: long }
- match: { fields.k8s\.pod\.network\.rx.long.searchable: true }
- match: { fields.k8s\.pod\.network\.rx.long.aggregatable: true }
- match: { fields.k8s\.pod\.network\.rx.long.metric_conflicts_indices: [ "test_non_time_series", "test_time_series" ] }
- is_false: fields.k8s\.pod\.network\.rx.long.time_series_metric
- is_false: fields.k8s\.pod\.network\.rx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_aggregatable_indices
- is_false: fields.k8s\.pod\.network\.rx.long.indices

- match: { fields.k8s\.pod\.network\.tx.long.type: long }
- match: { fields.k8s\.pod\.network\.tx.long.searchable: true }
- match: { fields.k8s\.pod\.network\.tx.long.aggregatable: true }
- match: { fields.k8s\.pod\.network\.tx.long.metric_conflicts_indices: [ "test_non_time_series", "test_time_series" ] }
- is_false: fields.k8s\.pod\.network\.tx.long.time_series_metric
- is_false: fields.k8s\.pod\.network\.tx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.tx.long.non_aggregatable_indices
- is_false: fields.k8s\.pod\.network\.tx.long.indices

Original file line number Diff line number Diff line change
Expand Up @@ -304,45 +304,6 @@ aggregate a tag:
term:
_tsid: wont't work

---
field capabilities:
- skip:
version: " - 8.1.99"
reason: tsdb indexing changed in 8.2.0

- do:
field_caps:
index: test
fields: [k8s.pod.uid, k8s.pod.network.rx, k8s.pod.ip, metricset, _tsid]

- match: {fields.k8s\.pod\.uid.keyword.searchable: true}
- match: {fields.k8s\.pod\.uid.keyword.aggregatable: true}
- match: {fields.k8s\.pod\.uid.keyword.time_series_dimension: true}
- is_false: fields.k8s\.pod\.uid.keyword.indices
- is_false: fields.k8s\.pod\.uid.keyword.non_searchable_indices
- is_false: fields.k8s\.pod\.uid.keyword.non_aggregatable_indices
- match: {fields.k8s\.pod\.network\.rx.long.searchable: true}
- match: {fields.k8s\.pod\.network\.rx.long.aggregatable: true}
- is_false: fields.k8s\.pod\.network\.rx.long.indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_searchable_indices
- is_false: fields.k8s\.pod\.network\.rx.long.non_aggregatable_indices
- match: {fields.k8s\.pod\.ip.ip.searchable: true}
- match: {fields.k8s\.pod\.ip.ip.aggregatable: true}
- is_false: fields.k8s\.pod\.ip.ip.indices
- is_false: fields.k8s\.pod\.ip.ip.non_searchable_indices
- is_false: fields.k8s\.pod\.ip.ip.non_aggregatable_indices
- match: {fields.metricset.keyword.searchable: true}
- match: {fields.metricset.keyword.aggregatable: true}
- match: {fields.metricset.keyword.time_series_dimension: true}
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices
- match: {fields._tsid._tsid.metadata_field: true}
- match: {fields._tsid._tsid.searchable: false}
- match: {fields._tsid._tsid.aggregatable: true}
- is_false: fields._tsid._tsid.indices
- is_false: fields._tsid._tsid.non_searchable_indices
- is_false: fields._tsid._tsid.non_aggregatable_indices

---
sort by tsid:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.elasticsearch.common.breaker.CircuitBreakingException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
Expand Down Expand Up @@ -119,7 +121,14 @@ public void setUp() throws Exception {
.endObject()
.endObject()
.endObject();
assertAcked(prepareCreate("old_index").setMapping(oldIndexMapping));

Settings settings = Settings.builder()
.put(IndexSettings.MODE.getKey(), IndexMode.TIME_SERIES)
.putList(IndexMetadata.INDEX_ROUTING_PATH.getKey(), List.of("some_dimension"))
.put(IndexSettings.TIME_SERIES_START_TIME.getKey(), "2006-01-08T23:40:53.384Z")
.put(IndexSettings.TIME_SERIES_END_TIME.getKey(), "2106-01-08T23:40:53.384Z")
.build();
assertAcked(prepareCreate("old_index").setSettings(settings).setMapping(oldIndexMapping));

XContentBuilder newIndexMapping = XContentFactory.jsonBuilder()
.startObject()
Expand Down
Loading