-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
ESQL: Mark counter fields as unsupported #99054
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c2b417a
ESQL: Mark counter fields as unsupported
nik9000 b7e2a13
Update docs/changelog/99054.yaml
nik9000 e9da7d7
Merge branch 'main' into tsbd_counter
nik9000 6542f37
Merge branch 'main' into tsbd_counter
nik9000 e662516
WIP
nik9000 2f33d55
test
nik9000 48cc72b
Merge remote-tracking branch 'refs/remotes/nik9000/tsbd_counter' into…
nik9000 3e11cae
Merge branch 'main' into tsbd_counter
nik9000 cb26e0f
Format
nik9000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 99054 | ||
summary: "ESQL: Mark counter fields as unsupported" | ||
area: ES|QL | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
.../server/single-node/src/yamlRestTest/resources/rest-api-spec/test/45_non_tsdb_counter.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
index: | ||
mode: standard | ||
mappings: | ||
properties: | ||
"@timestamp": | ||
type: date | ||
metricset: | ||
type: keyword | ||
time_series_dimension: true | ||
k8s: | ||
properties: | ||
pod: | ||
properties: | ||
uid: | ||
type: keyword | ||
time_series_dimension: true | ||
name: | ||
type: keyword | ||
ip: | ||
type: ip | ||
network: | ||
properties: | ||
tx: | ||
type: long | ||
time_series_metric: counter | ||
rx: | ||
type: long | ||
time_series_metric: counter | ||
- do: | ||
bulk: | ||
refresh: true | ||
index: test | ||
body: | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2001818691, "rx": 802133794}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:50:24.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2005177954, "rx": 801479970}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:50:44.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2006223737, "rx": 802337279}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:51:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.2", "network": {"tx": 2012916202, "rx": 803685721}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:50:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434521831, "rx": 530575198}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:50:23.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434577921, "rx": 530600088}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:50:53.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434587694, "rx": 530604797}}}}' | ||
- '{"index": {}}' | ||
- '{"@timestamp": "2021-04-28T18:51:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}' | ||
|
||
--- | ||
load everything: | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'from test' | ||
|
||
- match: {columns.0.name: "@timestamp"} | ||
- match: {columns.0.type: "date"} | ||
- match: {columns.1.name: "k8s.pod.ip"} | ||
- match: {columns.1.type: "ip"} | ||
- match: {columns.2.name: "k8s.pod.name"} | ||
- match: {columns.2.type: "keyword"} | ||
- match: {columns.3.name: "k8s.pod.network.rx"} | ||
- match: {columns.3.type: "long"} | ||
- match: {columns.4.name: "k8s.pod.network.tx"} | ||
- match: {columns.4.type: "long"} | ||
- match: {columns.5.name: "k8s.pod.uid"} | ||
- match: {columns.5.type: "keyword"} | ||
- match: {columns.6.name: "metricset"} | ||
- match: {columns.6.type: "keyword"} | ||
- length: {values: 8} | ||
|
||
--- | ||
load a document: | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'from test | where @timestamp == "2021-04-28T18:50:23.142Z"' | ||
|
||
- length: {values: 1} | ||
- length: {values.0: 7} | ||
- match: {values.0.0: "2021-04-28T18:50:23.142Z"} | ||
- match: {values.0.1: "10.10.55.3"} | ||
- match: {values.0.2: "dog"} | ||
- match: {values.0.3: 530600088} | ||
- match: {values.0.4: 1434577921} | ||
- match: {values.0.5: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"} | ||
- match: {values.0.6: "pod"} | ||
|
||
--- | ||
filter on counter: | ||
- do: | ||
esql.query: | ||
body: | ||
query: 'from test | where k8s.pod.network.tx == 1434577921' | ||
|
||
- length: {values: 1} | ||
- length: {values.0: 7} | ||
- match: {values.0.0: "2021-04-28T18:50:23.142Z"} | ||
- match: {values.0.1: "10.10.55.3"} | ||
- match: {values.0.2: "dog"} | ||
- match: {values.0.3: 530600088} | ||
- match: {values.0.4: 1434577921} | ||
- match: {values.0.5: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"} | ||
- match: {values.0.6: "pod"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...lugin/esql/src/test/java/org/elasticsearch/xpack/esql/type/EsqlDataTypeRegistryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.esql.type; | ||
|
||
import org.elasticsearch.action.fieldcaps.FieldCapabilities; | ||
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; | ||
import org.elasticsearch.index.mapper.TimeSeriesParams; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.ql.index.IndexResolution; | ||
import org.elasticsearch.xpack.ql.index.IndexResolver; | ||
import org.elasticsearch.xpack.ql.type.DataType; | ||
import org.elasticsearch.xpack.ql.type.DataTypes; | ||
import org.elasticsearch.xpack.ql.type.EsField; | ||
|
||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class EsqlDataTypeRegistryTests extends ESTestCase { | ||
public void testCounter() { | ||
resolve("long", TimeSeriesParams.MetricType.COUNTER, DataTypes.UNSUPPORTED); | ||
} | ||
|
||
public void testGauge() { | ||
resolve("long", TimeSeriesParams.MetricType.GAUGE, DataTypes.LONG); | ||
} | ||
|
||
public void testLong() { | ||
resolve("long", null, DataTypes.LONG); | ||
} | ||
|
||
private void resolve(String esTypeName, TimeSeriesParams.MetricType metricType, DataType expected) { | ||
String[] indices = new String[] { "idx-" + randomAlphaOfLength(5) }; | ||
FieldCapabilities fieldCap = new FieldCapabilities( | ||
randomAlphaOfLength(3), | ||
esTypeName, | ||
false, | ||
true, | ||
true, | ||
false, | ||
metricType, | ||
indices, | ||
null, | ||
null, | ||
null, | ||
null, | ||
Map.of() | ||
); | ||
FieldCapabilitiesResponse caps = new FieldCapabilitiesResponse(indices, Map.of(fieldCap.getName(), Map.of(esTypeName, fieldCap))); | ||
IndexResolution resolution = IndexResolver.mergedMappings(EsqlDataTypeRegistry.INSTANCE, "idx-*", caps); | ||
|
||
EsField f = resolution.get().mapping().get(fieldCap.getName()); | ||
assertThat(f.getDataType(), equalTo(expected)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try to make this a bit more generic, ie instead of specifically looking at
TimeSeriesParams.MetricType
I'd try to use the FieldCapabilities instance itself from where I could extract whatever information necessary to decide the supportability of a data type. Another suggestion is to look into defining a secondfromEs
method that receives thisFieldCapabilities
parameter and keep the original one unchanged.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the
IndexResolver
has been created the field_caps API didn't return such additional information and I am not seeing any less intrusive way to support this other than what you suggested.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be worried about keeping the original one unchanged because it's kind of dangerous, at least in ESQL it is. But I'm happy to move the whole field caps response there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm stumbling over the same issue - how about encoding the TIME_SERIES_METRIC_PARAM inside the name along with its value, as a suffix for example?
This convention avoids having to extend the static method and can handle in the future more parameter or special types outside the metric ones without having to extend the method yet again.
For example when dealing with a timeseries metric type, append that to the typeName itself and then check in EsqlDataType if the typeName ends up
TIME_SERIES_METRIC_PARAM-COUNTER
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it to the string feels easy to break. It'd be even more likely for folks to accidentally not use the metric param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at taking the whole
FieldCapabilities
object but there is a place we don't have it - in the mapping walking code. I'm not sure it's worth trying to get it there when adding the smaller parameter works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a generic object as field context instead of typing it to TimeSeriesParams.MetricType and doing an instanceof check?
It is not OOP-ish but in this case we're looking at a bag properties for fields vs just the name.
For example how about
DataType fromEs(String typeName, Object typeContext)
and then in ESQL do:
I'd like to avoid us to add a new param for each special type on the method signature and instead use a "bucket" type approach.
If you're on the fence, we can merge the PR and revisit this in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get where your coming from. My preference would be to merge as is and then, when we got to add the next "funny" parameter, we do something like:
If it feels sensible then. I don't feel like we need something so fancy for two fields. But three or our we really may.