-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Search] Search Sessions with relative time range #84405
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
05b927f
send to background with relative timerange
Dosant 5bdfb7a
Merge branch 'master' of github.com:elastic/kibana into dev/search/re…
Dosant 8526dba
review improvements
Dosant 29c330d
clean up
Dosant 6d9f18b
Merge branch 'master' of github.com:elastic/kibana into dev/search/re…
Dosant 543203e
Merge branch 'master' of github.com:elastic/kibana into dev/search/re…
Dosant d001f1b
move conversion to handleRequest based on discussion with @ppisljar
Dosant 8da16d0
Merge branch 'master' of github.com:elastic/kibana into dev/search/re…
Dosant 2a7f482
fix
Dosant 10deea5
Merge branch 'master' into dev/search/relative-timerange
kibanamachine ed491c5
review
Dosant 3014cbf
Merge branch 'master' into dev/search/relative-timerange
kibanamachine 5f2a1b6
Merge branch 'master' into dev/search/relative-timerange
kibanamachine 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
11 changes: 11 additions & 0 deletions
11
...a/public/kibana-plugin-plugins-data-public.datapublicpluginstart.nowprovider.md
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [DataPublicPluginStart](./kibana-plugin-plugins-data-public.datapublicpluginstart.md) > [nowProvider](./kibana-plugin-plugins-data-public.datapublicpluginstart.nowprovider.md) | ||
|
||
## DataPublicPluginStart.nowProvider property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
nowProvider: NowProviderPublicContract; | ||
``` |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { | ||
NowProvider, | ||
NowProviderInternalContract, | ||
NowProviderPublicContract, | ||
} from './now_provider'; |
50 changes: 50 additions & 0 deletions
50
src/plugins/data/public/now_provider/lib/get_force_now_from_url.test.ts
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,50 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getForceNowFromUrl } from './get_force_now_from_url'; | ||
const originalLocation = window.location; | ||
afterAll(() => { | ||
window.location = originalLocation; | ||
}); | ||
|
||
function mockLocation(url: string) { | ||
// @ts-ignore | ||
delete window.location; | ||
// @ts-ignore | ||
window.location = new URL(url); | ||
} | ||
|
||
test('should get force now from URL', () => { | ||
const dateString = '1999-01-01T00:00:00.000Z'; | ||
mockLocation(`https://elastic.co/?forceNow=${dateString}`); | ||
|
||
expect(getForceNowFromUrl()).toEqual(new Date(dateString)); | ||
}); | ||
|
||
test('should throw if force now is invalid', () => { | ||
const dateString = 'invalid-date'; | ||
mockLocation(`https://elastic.co/?forceNow=${dateString}`); | ||
|
||
expect(() => getForceNowFromUrl()).toThrowError(); | ||
}); | ||
|
||
test('should return undefined if no forceNow', () => { | ||
mockLocation(`https://elastic.co/`); | ||
expect(getForceNowFromUrl()).toBe(undefined); | ||
}); |
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 |
---|---|---|
|
@@ -16,10 +16,25 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { parse } from 'query-string'; | ||
|
||
/** @internal */ | ||
export function parseQueryString() { | ||
export function getForceNowFromUrl(): Date | undefined { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this moved from |
||
const forceNow = parseQueryString().forceNow as string; | ||
if (!forceNow) { | ||
return; | ||
} | ||
|
||
const ts = Date.parse(forceNow); | ||
if (isNaN(ts)) { | ||
throw new Error(`forceNow query parameter, ${forceNow}, can't be parsed by Date.parse`); | ||
} | ||
return new Date(ts); | ||
} | ||
|
||
/** @internal */ | ||
function parseQueryString() { | ||
lizozom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// window.location.search is an empty string | ||
// get search from href | ||
const hrefSplit = window.location.href.split('?'); | ||
|
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,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { getForceNowFromUrl } from './get_force_now_from_url'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { NowProvider, NowProviderInternalContract } from './now_provider'; | ||
|
||
let mockDateFromUrl: undefined | Date; | ||
let nowProvider: NowProviderInternalContract; | ||
|
||
jest.mock('./lib', () => ({ | ||
// @ts-ignore | ||
...jest.requireActual('./lib'), | ||
getForceNowFromUrl: () => mockDateFromUrl, | ||
})); | ||
|
||
beforeEach(() => { | ||
nowProvider = new NowProvider(); | ||
}); | ||
afterEach(() => { | ||
mockDateFromUrl = undefined; | ||
}); | ||
|
||
test('should return Date.now() by default', async () => { | ||
const now = Date.now(); | ||
await new Promise((r) => setTimeout(r, 10)); | ||
expect(nowProvider.get().getTime()).toBeGreaterThan(now); | ||
}); | ||
|
||
test('should forceNow from URL', async () => { | ||
mockDateFromUrl = new Date('1999-01-01T00:00:00.000Z'); | ||
nowProvider = new NowProvider(); | ||
expect(nowProvider.get()).toEqual(mockDateFromUrl); | ||
}); | ||
|
||
test('should forceNow from URL if custom now is set', async () => { | ||
mockDateFromUrl = new Date('1999-01-01T00:00:00.000Z'); | ||
nowProvider = new NowProvider(); | ||
nowProvider.set(new Date()); | ||
expect(nowProvider.get()).toEqual(mockDateFromUrl); | ||
}); |
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.
Nit: We already have a shortcut const for timefilter declared above. It also might be a bit cleaner to merge the two subs that do the same thing:
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.
Improved 👍