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

Fix label on scripted field date histograms #8638

Merged
merged 1 commit into from
Oct 12, 2016

Conversation

Bargs
Copy link
Contributor

@Bargs Bargs commented Oct 12, 2016

Now that we support Painless scripted fields users can create scripted
date fields, and thus scripted date histograms. The label making method
for the date histogram agg was getting the field name in a way that was
incompatible with scripted fields, so I've added some fallback code for
that scenario. I looked through the rest of the makeLabel methods on all
the other aggs and they all correctly access the field displayName
already so this should only need fixed for date histograms.

Fixes #8632

Now that we support Painless scripted fields users can create scripted
date fields, and thus scripted date histograms. The label making method
for the date histogram agg was getting the field name in a way that was
incompatible with scripted fields, so I've added some fallback code for
that scenario. I looked through the rest of the makeLabel methods on all
the other aggs and they all correctly access the field displayName
already so this should only need fixed for date histograms.

Fixes elastic#8632
@Bargs
Copy link
Contributor Author

Bargs commented Oct 12, 2016

@stacey-gammon mind reviewing this one as well while you're working on scripted fields? I'd be happy to trade when you have a PR ready for the scripted field filter bug.

Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

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

LGTM

I would consider just using the displayName though. That said, I am not 100% familiar with the semantics of name and displayName, and when one should use one over the other.

@@ -41,7 +41,8 @@ export default function DateHistogramAggType(timefilter, config, Private) {
makeLabel: function (agg) {
const output = this.params.write(agg);
const params = output.params;
return params.field + ' per ' + (output.metricScaleText || output.bucketInterval.description);
const field = params.field || agg.params.field.displayName || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

sweeto!

image

@@ -41,7 +41,8 @@ export default function DateHistogramAggType(timefilter, config, Private) {
makeLabel: function (agg) {
const output = this.params.write(agg);
const params = output.params;
return params.field + ' per ' + (output.metricScaleText || output.bucketInterval.description);
const field = params.field || agg.params.field.displayName || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't trigger a single example where the agg.params.field.displayName was empty. Shouldn't we just use that instead of using the cascade?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd generally agree, but I'm playing it safe since we're so close to release with limited time to let this bake.

Copy link
Contributor

Choose a reason for hiding this comment

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

I worry about accessing the field display name directly like this because elsewhere in this file we access params information in a particularly defensive way: https://github.com/elastic/kibana/pull/8638/files#diff-2cd930ccd69e832107c9578ef648e5b7R23

That leads me to believe that there are circumstances where agg doesn't have the nested params data, which would cause this code to trigger an error.

Copy link
Contributor Author

@Bargs Bargs Oct 12, 2016

Choose a reason for hiding this comment

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

Most other aggs (example) access displayName directly, so it seemed safe to me. I suppose there might something special about the date histogram though. I can change it to use lodash's get if you'd like.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Bargs I'm comfortable with this approach if we want to roll it out for 5.x, since that'll be given a full blown QA run, but if we want to get this into 5.0, we should be more cautious around the access here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@epixa makes sense, it's a trivial change so the question is, do we want to put it in 5.0? If so I'm happy to make the change

Copy link
Contributor

Choose a reason for hiding this comment

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

Was this an issue in 4.x, or is this is a regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's new and only affects painless/groovy/etc - the issue only affects the date histogram and lucene expressions can't produce date fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do it

Copy link
Contributor

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

Verified locally, LGTM

@Bargs Bargs merged commit 733be3f into elastic:master Oct 12, 2016
elastic-jasper added a commit that referenced this pull request Oct 12, 2016
---------

**Commit 1:**
Fix label on scripted field date histograms

Now that we support Painless scripted fields users can create scripted
date fields, and thus scripted date histograms. The label making method
for the date histogram agg was getting the field name in a way that was
incompatible with scripted fields, so I've added some fallback code for
that scenario. I looked through the rest of the makeLabel methods on all
the other aggs and they all correctly access the field displayName
already so this should only need fixed for date histograms.

Fixes #8632

* Original sha: 7359b45
* Authored by Matthew Bargar <[email protected]> on 2016-10-12T15:10:15Z
@Bargs
Copy link
Contributor Author

Bargs commented Oct 12, 2016

@epixa let me know if I should backport to 5.0

Bargs pushed a commit that referenced this pull request Oct 12, 2016
@epixa
Copy link
Contributor

epixa commented Oct 12, 2016

@Bargs I left a post-merge inline comment. Any thoughts you have on that would be appreciated.

@epixa epixa added v5.1.1 and removed v5.1.0 labels Dec 8, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
---------

**Commit 1:**
Fix label on scripted field date histograms

Now that we support Painless scripted fields users can create scripted
date fields, and thus scripted date histograms. The label making method
for the date histogram agg was getting the field name in a way that was
incompatible with scripted fields, so I've added some fallback code for
that scenario. I looked through the rest of the makeLabel methods on all
the other aggs and they all correctly access the field displayName
already so this should only need fixed for date histograms.

Fixes elastic#8632

* Original sha: 9bed93b73c0f3cc90dc1fa2889aa6b18acab402b [formerly 7359b45]
* Authored by Matthew Bargar <[email protected]> on 2016-10-12T15:10:15Z


Former-commit-id: de68ed0
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scripted date fields have undefined labels in charts
5 participants