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

Use forceNow query parameter when parsing timefilter #16236

Merged
merged 5 commits into from
Feb 13, 2018

Conversation

kobelb
Copy link
Contributor

@kobelb kobelb commented Jan 23, 2018

Reporting needs a way to emulate a different Date for now when parsing relative dates. This adds a forceNow query parameter that can be used for this purpose.

Were also adding data-shared-timefilter-from and data-shared-timefilter-to to expose the effective global time filters.

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -105,10 +106,21 @@ uiModules
return this.calculateBounds(this.time);
};

Timefilter.prototype.getForceNow = function () {
const query = querystring.parse(window.location.search.replace(/^\?/, '')).forceNow;
Copy link
Contributor

Choose a reason for hiding this comment

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

Being Angular code and all, should this use $location.search() instead? And actually, isn't that required since we're using hash routing?

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 want this to be a normal querystring parameter outside of the AngularJS based hash routing, because I assumed that Canvas itself might not be using the hash based routing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, fair enough. We are using hash routing though, and actually I think everything would need to. Though, I suppose an app could use search param routing...

So your intention is that you'd have something like http://localhost:5601/acd/app/canvas?forceNow=2001-01-01T00:00:00Z#/workpad/workpad-1ba0f600-47f0-4306-a587-17cc95a74281?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that's the intent right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if an app needs the forceNow parameter to be part of the hash route?

I think that's actually going to be the case for Canvas. Our router is going to assume that the entirety of the parameters it should be looking at come after the hash. I can work around it, but I wonder if the location of this setting can be left up to the app creating the URL somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allowing the application to decide where to look for the parameter in the URL is going against the intent of this change entirely. The goal is to make the applications abide by a standard "interface" and then they'll work with Reporting, changing where the forceNow is for different applications is the exact thing that we're trying to avoid by introducing application specific logic.

With that being said, if we want to move the forceNow to the hash parameters, we can, as we can support this within Kibana. There's been discussion about moving to non hash-based routing, but we can readdress this when this happens

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I'll add an issue in Canvas to address search params that could be in the URL already and we can push forward that way.

const $el = compile();
expect($el.attr('data-shared-timefilter')).to.eql('false');

expect($el.attr('data-shared-timefilter-from')).to.eql('');
Copy link
Contributor

Choose a reason for hiding this comment

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

Contrary to the test description, this isn't testing for null. The code that uses this is checking for a truthy value... maybe the test should do the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When there's an attribute added without a value, like this:

screen shot 2018-02-05 at 1 54 31 pm

the DOM APIs are returning a value of '', I'm open to rewording recommendations to make this more explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

The value is fine, but the test says "sets data-shared-timefilter-* to null", but it's not null, and it's not testing for null. My only beef here is the description of what is being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does doesn't set data-shared-timefilter-* using the timefilter when auto-refresh selector is enabled seem any more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine. My only issue was the mention of null, since null is never the value and was not actually be tested for.

@w33ble
Copy link
Contributor

w33ble commented Feb 5, 2018

@kobelb this also doesn't seem to ever test the values returned when the forceNow argument is true. Unless I'm missing something...

@kobelb
Copy link
Contributor Author

kobelb commented Feb 5, 2018

@kobelb this also doesn't seem to ever test the values returned when the forceNow argument is true. Unless I'm missing something...

Would you mind elaborating, I'm not following?

@w33ble
Copy link
Contributor

w33ble commented Feb 5, 2018

Would you mind elaborating, I'm not following?

Sorry, for some reason I was thinking forceNow was a boolean. That's not right at all.

You have 3 tests for <kbn-global-timepicker>, which all look fine. But in addition to changing the arguments for that directive in this PR, you've added checking for forceNow in timefilter.js, but I don't see any tests for the from/to dates that are provided when a forceNow value is provided.

@kobelb
Copy link
Contributor Author

kobelb commented Feb 5, 2018

Yeah... at the time my reasoning was that the supplier of forceNow via Reporting's regression tests would be sufficient, but in retrospect, I was being lazy. I'll go back and add some unit tests for that new behavior.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@kobelb kobelb merged commit b677848 into elastic:master Feb 13, 2018
@kobelb kobelb deleted the reporting-canvas-support branch February 13, 2018 17:09
kobelb added a commit to kobelb/kibana that referenced this pull request Feb 13, 2018
* Using "forceNow" parameter to adjust "now" and exposing timeRange

* Moving forceNow parameter to the hash, adding tests

* Renaming test
kobelb added a commit that referenced this pull request Feb 13, 2018
* Using "forceNow" parameter to adjust "now" and exposing timeRange

* Moving forceNow parameter to the hash, adding tests

* Renaming test
@bhavyarm
Copy link
Contributor

How do I test this PR @kobelb ? Please & Thank you :)

@kobelb
Copy link
Contributor Author

kobelb commented May 24, 2018

@bhavyarm the only thing that utilizes this right now is Reporting, so I'd recommend testing that Reporting works correctly when there's a delay between the Reporting job being created and when it's actually run.

To do this, I created a Metric Visualization that displayed the max timestamp and a Metric Visualization that displayed the minimum timestamp, and I added them both to a Dashboard. I then clicked the "Generate PDF" button to create the Reporting job, and then immediately stopped the Kibana server. I wanted about 5 minutes, started the Kibana server back up and made sure that the timestamps in the PDF were relative to the time the job was created, as opposed to the current time.

@bhavyarm
Copy link
Contributor

@kobelb thank you!!!!

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.

5 participants