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 issue with long values in TSVB static metric #40256

Merged
merged 5 commits into from
Jul 5, 2019

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Jul 3, 2019

Summary

Fixes #28842

This makes sure that the user can also enter large static values, by using the long suffix in Painless/Java for all integer values. Since the user should still be able to use decimal numbers, we must check beforehand if the value is an integer and if not use the value as it is (double in painless).

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@timroes timroes added Feature:TSVB TSVB (Time Series Visual Builder) release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 v7.3.0 labels Jul 3, 2019
@timroes timroes requested review from emmacunningham, markov00 and a team July 3, 2019 12:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@spalger spalger added the v7.4.0 label Jul 3, 2019
@@ -78,11 +78,12 @@ export const bucketTransform = {
},
static: bucket => {
checkMetric(bucket, ['value']);
const isDecimalValue = !Number.isInteger(Number(bucket.value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can move it into helper 'method' to reuse it in future.
Also looks like it returns 'true' if bucket.value is string.
!Number.isInteger(Number('stringValue')); /// => true

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 don't think this line would justify a utility method, especially as you mentioned it's not very generic, since it works because we know that this will be a valid number in this place, generated by TSVB.

Copy link
Contributor

Choose a reason for hiding this comment

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

what about to use RegExp here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would you prefer using regex, if we can use a native Number method to check the same?

Copy link
Member

Choose a reason for hiding this comment

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

I know that we "sure" that the number in this place is a valid number, but I never trust code, so I'd also like to have a small check for NaN values here. It doesn't hurt the code having one more check

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Code LGTM, I'd prefer one more check on that bucket.value instead of a blind trust on the number correctness

@@ -78,11 +78,12 @@ export const bucketTransform = {
},
static: bucket => {
checkMetric(bucket, ['value']);
const isDecimalValue = !Number.isInteger(Number(bucket.value));
Copy link
Member

Choose a reason for hiding this comment

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

I know that we "sure" that the number in this place is a valid number, but I never trust code, so I'd also like to have a small check for NaN values here. It doesn't hurt the code having one more check

@timroes timroes requested review from markov00 and alexwizp July 5, 2019 09:10
@@ -78,11 +78,13 @@ export const bucketTransform = {
},
static: bucket => {
checkMetric(bucket, ['value']);
// Anything containing a decimal point or an exponent is considered decimal value
const isDecimalValue = bucket.value.match(/[.e]/i);
Copy link
Contributor

@alexwizp alexwizp Jul 5, 2019

Choose a reason for hiding this comment

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

👍
But probably it make sense to wrap it Boolean(bucket.value.match(/[.e]/i)) . In case of false isDecimalValue === undefined

image

Also this solution works only if bucket.value has string value. I still think that we can create a helper method for that because the following code can confuse
Boolean(Number(bucket.value).toString().match(/[.e]/i))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as we're inside JS I think checking for null as a falsey value is fine, but I can wrap it. I cannot convert it to a number, because of the issue you pointed out that it will actually create the 64 bit rounding issues for the check, but then when we later write the script the string value won't have those, so Number('1231123112631231233.123').toString() == "1231123112631231200" meaning we will append a L and then Elasticsearch will fail because it's not a valid long.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@timroes
Copy link
Contributor Author

timroes commented Jul 5, 2019

Jenkins, test this - timeout issue

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@timroes timroes merged commit b7de2ac into elastic:master Jul 5, 2019
@timroes timroes deleted the fix-tsvb-static-long branch July 5, 2019 14:59
timroes pushed a commit to timroes/kibana that referenced this pull request Jul 5, 2019
* Fix issue with long values in TSVB static metric

* Handle numeric values with decimal zeros

* Work properly with exponential values

* Wrap into boolean
timroes pushed a commit to timroes/kibana that referenced this pull request Jul 5, 2019
* Fix issue with long values in TSVB static metric

* Handle numeric values with decimal zeros

* Work properly with exponential values

* Wrap into boolean
timroes pushed a commit that referenced this pull request Jul 5, 2019
* Fix issue with long values in TSVB static metric

* Handle numeric values with decimal zeros

* Work properly with exponential values

* Wrap into boolean
timroes pushed a commit that referenced this pull request Jul 5, 2019
* Fix issue with long values in TSVB static metric

* Handle numeric values with decimal zeros

* Work properly with exponential values

* Wrap into boolean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:TSVB TSVB (Time Series Visual Builder) release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.3.0 v7.4.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TSVB: Cannot use large integers as static value
5 participants