[TSVB/Markdown] Introduce formatted date field label#75555
[TSVB/Markdown] Introduce formatted date field label#75555stratoula merged 9 commits intoelastic:masterfrom
Conversation
| if (row.labelFormatted) { | ||
| set( | ||
| variables, | ||
| `${_.snakeCase(row.label)}.formatted`, |
There was a problem hiding this comment.
I was thinking of it more like label.formatted but maybe this is my personal opinion.
There was a problem hiding this comment.
Specifying it as:
set(variables, `${_.snakeCase(row.label)}.label.formatted`, value)
will override the previous one since in that case the label would become as object type variable and should have next shape:
set(variables, _.snakeCase(row.label), {
raw: row.label,
foramtted: moment(row.labelFormatted).format(dateFormat)
})
That means existing visualizations could be affected. So I chose this way as a safe one
There was a problem hiding this comment.
Yes you are right, I am fine with it ❤️
| return buckets.map((bucket) => { | ||
| bucket.id = `${series.id}:${bucket.key}`; | ||
| bucket.label = formatKey(bucket.key, series); | ||
| bucket.labelFormatted = bucket.key_as_string || ''; |
There was a problem hiding this comment.
I have made some tests with various types and it seems that you are right, key_as_string is used for dates. @timroes do you have more input on this?
|
@sulemanof thank you for that. I agree dates should be human-readable, I will create an issue for this 🍰 |
|
And here is the issue #75634 |
stratoula
left a comment
There was a problem hiding this comment.
Assuming that key_as_string is used only for dates, I am fine with it! I have tested it on Safari, works perfectly and haven't detected any regressions. 🥇 Code LGTM
|
Pinging @elastic/kibana-app (Team:KibanaApp) |
markov00
left a comment
There was a problem hiding this comment.
@sulemanof @stratoula I think we already have this functionality in TSVB
you can access the formatted version of each bucket with something like:
{{# 1595980800000.data.formatted }}
{{[0]}}
{{/ 1595980800000.data.formatted }}
where [0] is the first element of the bucket, in this case the used label/timestamp.
You can also use this technique to in the each method
The initial request is to have a formatted version of a bucket key, while the data is split by date field and have labels as epoch millis. UPD: Notice the agg config is: |
There was a problem hiding this comment.
Thanks @sulemanof for the explanation on how to reproduce it, I've checked and this works under the standard use case.
The problem is that the key_as_string, use the format provided in the aggregation as a parameter (as described here), if not provided (as in TSVB) it use the first date format specified in the field mapping.
This means that if the user has a [date format] mappings (https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html) that doesn't conform with what moment can digest, this field will be transformed into the following Invalid date string.
PUT my-index-000001
{
"mappings": {
"properties": {
"timestamp": {
"type": "date"
},
"date": {
"type": "date",
"format": "QQ-yyyy-M-D"
},
"value": {
"type": "long"
}
}
}
}
POST my-index-000001/_doc
{
"timestamp": "2020-08-20T13:02:45.111Z",
"date": "01-2020-8-5",
"value": 100
}
GET my-index-000001/_search
{
"aggs": {
"dh": {
"terms": {
"field": "date"
}
}
},
"size": 0
}
We shouldn't probably directly rely on that key_as_string field or at least don't convert it right away, but check the field type used by the terms aggregation and then apply a valid format.
If we know that the key field is a date, we can apply the formatting to the key instead of key_as_string, but we should always check the key field type before doing any conversion
src/plugins/vis_type_timeseries/public/application/components/lib/convert_series_to_vars.js
Outdated
Show resolved
Hide resolved
|
@elasticmachine merge upstream |
💚 Build SucceededBuild metricsasync chunks size
History
To update your PR or re-run it, just comment with: |
Out of office for some time and all requested changes have been addressed
* Introduce formatted date field label * Apply changes * Use default format if can't parse, add comments Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
|
We just upgraded from 8.2.0 to 8.3.2, and it seems this PR was either removed or broken with the update. We are right back to where we were before this PR. There is no longer an option to display human-readable dates or boolean values again. My visualization that worked perfectly after this merge now gives an error: Looking at the options for displaying the markdown, we are exactly back to how I described in Issue 75341 Eric |





Summary
Fixes #75341
This PR introduces a formatted date field label.
It is built on
key_as_stringbucket value, which is only inherent for fields with typedate(as far as I know).Release note
TSVB Mardown now handles the case when a field has
key_as_stringvalue.Common case is the value is a date string (e.x.
2020-08-21T20:36:58.000Z) or a boolean stringified value ("true"/"false").Such a value will be first converted into a moment object and formatted with
dateFormatfrom Kibana UI settings.If the
key_as_stringvalue is not recognized by a known format in Moments.js, a formatted value from elasticsearch will be returned.Checklist
Delete any items that are not applicable to this PR.
For maintainers