Skip to content

Commit

Permalink
Add time series information to field caps
Browse files Browse the repository at this point in the history
Exposes information about dimensions and metrics via field caps. This
information will be needed for PromQL support.

Relates to elastic#74660
  • Loading branch information
imotov committed Oct 6, 2021
1 parent 69cf679 commit 58bc365
Show file tree
Hide file tree
Showing 20 changed files with 645 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1253,11 +1253,11 @@ public void testFieldCaps() throws IOException {
assertEquals(2, ratingResponse.size());

FieldCapabilities expectedKeywordCapabilities = new FieldCapabilities(
"rating", "keyword", false, true, true, new String[]{"index2"}, null, null, Collections.emptyMap());
"rating", "keyword", false, true, true, false, null, null, null, new String[]{"index2"}, null, Collections.emptyMap());
assertEquals(expectedKeywordCapabilities, ratingResponse.get("keyword"));

FieldCapabilities expectedLongCapabilities = new FieldCapabilities(
"rating", "long", false, true, true, new String[]{"index1"}, null, null, Collections.emptyMap());
"rating", "long", false, true, true, false, null, null, null, new String[]{"index1"}, null, Collections.emptyMap());
assertEquals(expectedLongCapabilities, ratingResponse.get("long"));

// Check the capabilities for the 'field' field.
Expand All @@ -1266,7 +1266,7 @@ public void testFieldCaps() throws IOException {
assertEquals(1, fieldResponse.size());

FieldCapabilities expectedTextCapabilities = new FieldCapabilities(
"field", "text", false, true, false, null, null, null, Collections.emptyMap());
"field", "text", false, true, false, false, null, null, null, null, null, Collections.emptyMap());
assertEquals(expectedTextCapabilities, fieldResponse.get("text"));
}

Expand Down
27 changes: 22 additions & 5 deletions docs/reference/search/field-caps.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ field types are all described as the `keyword` type family.
`aggregatable`::
Whether this field can be aggregated on all indices.

`time_series_dimension`::
Whether this field is used as a time series dimension.

`time_series_metrics`::
Contains metric type if this fields is used as a time series metrics, null if the field is not used as metric.

`indices`::
The list of indices where this field has the same type family, or null if all indices
have the same type family for the field.
Expand All @@ -123,6 +129,10 @@ field types are all described as the `keyword` type family.
The list of indices where this field is not aggregatable, or null if all
indices have the same definition for the field.

`non_dimension_indices`::
The list of indices where this field is not marked as a dimension field, or null if all
indices have the same definition for the field.

`meta`::
Merged metadata across all indices as a map of string keys to arrays of values.
A value length of 1 indicates that all indices had the same value for this key,
Expand Down Expand Up @@ -163,13 +173,15 @@ The API returns the following response:
"metadata_field": false,
"searchable": true,
"aggregatable": false,
"time_series_dimension": false,
"indices": [ "index1", "index2" ],
"non_aggregatable_indices": [ "index1" ] <2>
},
"keyword": {
"metadata_field": false,
"searchable": false,
"aggregatable": true,
"time_series_dimension": false,
"indices": [ "index3", "index4" ],
"non_searchable_indices": [ "index4" ] <3>
}
Expand All @@ -178,8 +190,8 @@ The API returns the following response:
"text": {
"metadata_field": false,
"searchable": true,
"aggregatable": false
"aggregatable": false,
"time_series_dimension": false
}
}
}
Expand Down Expand Up @@ -215,35 +227,40 @@ in some indices but not all:
"metadata_field": false,
"searchable": true,
"aggregatable": false,
"time_series_dimension": false,
"indices": [ "index1", "index2" ],
"non_aggregatable_indices": [ "index1" ]
},
"keyword": {
"metadata_field": false,
"searchable": false,
"aggregatable": true,
"time_series_dimension": false,
"indices": [ "index3", "index4" ],
"non_searchable_indices": [ "index4" ]
},
"unmapped": { <1>
"metadata_field": false,
"indices": [ "index5" ],
"searchable": false,
"aggregatable": false
"aggregatable": false,
"time_series_dimension": false
}
},
"title": {
"text": {
"metadata_field": false,
"indices": [ "index1", "index2", "index3", "index4" ],
"searchable": true,
"aggregatable": false
"aggregatable": false,
"time_series_dimension": false
},
"unmapped": { <2>
"metadata_field": false,
"indices": [ "index5" ],
"searchable": false,
"aggregatable": false
"aggregatable": false,
"time_series_dimension": false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
---
setup:
- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0

- do:
indices.create:
index: tsdb_index1
body:
settings:
index:
number_of_replicas: 0
number_of_shards: 2
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true
non_tsdb_field:
type: keyword
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: integer
time_series_metric: gauge
packets_dropped:
type: long
time_series_metric: gauge
latency:
type: double
time_series_metric: gauge

- do:
indices.create:
index: tsdb_index2
body:
settings:
index:
number_of_replicas: 0
number_of_shards: 2
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
non_tsdb_field:
type: keyword
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: gauge
rx:
type: integer
packets_dropped:
type: long
time_series_metric: gauge
latency:
type: double
time_series_metric: gauge

---
"Get simple time series field caps":

- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0

- do:
field_caps:
index: 'tsdb_index1'
fields: [ "metricset", "non_tsdb_field", "k8s.pod.*" ]

- 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.time_series_metric
- 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.metricset.keyword.non_dimension_indices

- match: {fields.non_tsdb_field.keyword.searchable: true}
- match: {fields.non_tsdb_field.keyword.aggregatable: true}
- match: {fields.non_tsdb_field.keyword.time_series_dimension: false}
- is_false: fields.non_tsdb_field.keyword.time_series_metric
- is_false: fields.non_tsdb_field.keyword.indices
- is_false: fields.non_tsdb_field.keyword.non_searchable_indices
- is_false: fields.non_tsdb_field.keyword.non_aggregatable_indices
- is_false: fields.non_tsdb_field.keyword.non_dimension_indices

- match: {fields.k8s\.pod\.availability_zone.short.time_series_dimension: true}
- is_false: fields.k8s\.pod\.availability_zone.short.time_series_metric
- is_false: fields.k8s\.pod\.availability_zone.short.non_dimension_indices

- match: {fields.k8s\.pod\.uid.keyword.time_series_dimension: true}
- is_false: fields.k8s\.pod\.uid.keyword.time_series_metric
- is_false: fields.k8s\.pod\.uid.keyword.non_dimension_indices

- match: {fields.k8s\.pod\.name.keyword.time_series_dimension: false}
- is_false: fields.k8s\.pod\.name.keyword.time_series_metric
- is_false: fields.k8s\.pod\.name.keyword.non_dimension_indices

- match: {fields.k8s\.pod\.ip.ip.time_series_dimension: true}
- is_false: fields.k8s\.pod\.ip.ip.time_series_metric
- is_false: fields.k8s\.pod\.ip.ip.non_dimension_indices

- match: {fields.k8s\.pod\.network\.tx.long.time_series_dimension: false}
- match: {fields.k8s\.pod\.network\.tx.long.time_series_metric: counter}
- is_false: fields.k8s\.pod\.network\.tx.long.non_dimension_indices

- match: {fields.k8s\.pod\.network\.rx.integer.time_series_dimension: false}
- match: {fields.k8s\.pod\.network\.rx.integer.time_series_metric: gauge}
- is_false: fields.k8s\.pod\.network\.rx.integer.non_dimension_indices

- match: {fields.k8s\.pod\.network\.packets_dropped.long.time_series_dimension: false}
- match: {fields.k8s\.pod\.network\.packets_dropped.long.time_series_metric: gauge}
- is_false: fields.k8s\.pod\.network\.packets_dropped.long.non_dimension_indices

- match: {fields.k8s\.pod\.network\.latency.double.time_series_dimension: false}
- match: {fields.k8s\.pod\.network\.latency.double.time_series_metric: gauge}
- is_false: fields.k8s\.pod\.network\.latency.double.non_dimension_indices

---
"Get time series field caps with conflicts":

- skip:
version: " - 7.99.99"
reason: introduced in 8.0.0

- do:
field_caps:
index: tsdb_index1,tsdb_index2
fields: [ "metricset", "non_tsdb_field", "k8s.pod.*" ]

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

- match: {fields.non_tsdb_field.keyword.searchable: true}
- match: {fields.non_tsdb_field.keyword.aggregatable: true}
- match: {fields.non_tsdb_field.keyword.time_series_dimension: false}
- is_false: fields.non_tsdb_field.keyword.time_series_metric
- is_false: fields.non_tsdb_field.keyword.indices
- is_false: fields.non_tsdb_field.keyword.non_searchable_indices
- is_false: fields.non_tsdb_field.keyword.non_aggregatable_indices
- is_false: fields.non_tsdb_field.keyword.non_dimension_indices

- match: {fields.k8s\.pod\.availability_zone.short.time_series_dimension: true}
- is_false: fields.k8s\.pod\.availability_zone.short.time_series_metric
- is_false: fields.k8s\.pod\.availability_zone.short.non_dimension_indices

- match: {fields.k8s\.pod\.uid.keyword.time_series_dimension: true}
- is_false: fields.k8s\.pod\.uid.keyword.time_series_metric
- is_false: fields.k8s\.pod\.uid.keyword.non_dimension_indices

- match: {fields.k8s\.pod\.name.keyword.time_series_dimension: false}
- is_false: fields.k8s\.pod\.name.keyword.time_series_metric
- is_false: fields.k8s\.pod\.name.keyword.non_dimension_indices

- match: {fields.k8s\.pod\.ip.ip.time_series_dimension: true}
- is_false: fields.k8s\.pod\.ip.ip.time_series_metric
- is_false: fields.k8s\.pod\.ip.ip.non_dimension_indices

- match: {fields.k8s\.pod\.network\.tx.long.time_series_dimension: false}
- is_false: fields.k8s\.pod\.network\.tx.long.time_series_metric
- is_false: fields.k8s\.pod\.network\.tx.long.non_dimension_indices

- match: {fields.k8s\.pod\.network\.rx.integer.time_series_dimension: false}
- is_false: fields.k8s\.pod\.network\.rx.integer.time_series_metric
- is_false: fields.k8s\.pod\.network\.rx.integer.non_dimension_indices

- match: {fields.k8s\.pod\.network\.packets_dropped.long.time_series_dimension: false}
- match: {fields.k8s\.pod\.network\.packets_dropped.long.time_series_metric: gauge}
- is_false: fields.k8s\.pod\.network\.packets_dropped.long.non_dimension_indices

- match: {fields.k8s\.pod\.network\.latency.double.time_series_dimension: false}
- match: {fields.k8s\.pod\.network\.latency.double.time_series_metric: gauge}
- is_false: fields.k8s\.pod\.network\.latency.double.non_dimension_indices
Loading

0 comments on commit 58bc365

Please sign in to comment.