-
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
[ML] ML on Kibana Management: Add ability to pass a group ID filter to job management page #74533
Changes from all commits
f0e66c0
296688b
0e4f2ed
148ab2a
3e9c17b
812cd04
e4d47f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,21 +370,34 @@ function getUrlVars(url) { | |
return vars; | ||
} | ||
|
||
export function getSelectedJobIdFromUrl(url) { | ||
export function getSelectedIdFromUrl(url) { | ||
const result = {}; | ||
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. total nit, |
||
if (typeof url === 'string') { | ||
const isGroup = url.includes('groupIds'); | ||
url = decodeURIComponent(url); | ||
if (url.includes('mlManagement') && url.includes('jobId')) { | ||
|
||
if (url.includes('mlManagement')) { | ||
const urlParams = getUrlVars(url); | ||
const decodedJson = rison.decode(urlParams.mlManagement); | ||
return decodedJson.jobId; | ||
|
||
if (isGroup) { | ||
result.groupIds = decodedJson.groupIds; | ||
} else { | ||
result.jobId = decodedJson.jobId; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
export function getGroupQueryText(groupIds) { | ||
return `groups:(${groupIds.join(' or ')})`; | ||
} | ||
|
||
export function clearSelectedJobIdFromUrl(url) { | ||
if (typeof url === 'string') { | ||
url = decodeURIComponent(url); | ||
if (url.includes('mlManagement') && url.includes('jobId')) { | ||
if (url.includes('mlManagement') && (url.includes('jobId') || url.includes('groupIds'))) { | ||
const urlParams = getUrlVars(url); | ||
const clearedParams = `ml#/jobs?_g=${urlParams._g}`; | ||
window.history.replaceState({}, document.title, clearedParams); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getGroupQueryText, getSelectedIdFromUrl } from './utils'; | ||
|
||
describe('ML - Jobs List utils', () => { | ||
const jobId = 'test_job_id_1'; | ||
const jobIdUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(jobId:${jobId})`; | ||
const groupIdOne = 'test_group_id_1'; | ||
const groupIdTwo = 'test_group_id_2'; | ||
const groupIdsUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(groupIds:!(${groupIdOne},${groupIdTwo}))`; | ||
const groupIdUrl = `http://localhost:5601/aql/app/ml#/jobs?mlManagement=(groupIds:!(${groupIdOne}))`; | ||
|
||
describe('getSelectedIdFromUrl', () => { | ||
it('should get selected job id from the url', () => { | ||
const actual = getSelectedIdFromUrl(jobIdUrl); | ||
expect(actual).toStrictEqual({ jobId }); | ||
}); | ||
|
||
it('should get selected group ids from the url', () => { | ||
const expected = { groupIds: [groupIdOne, groupIdTwo] }; | ||
const actual = getSelectedIdFromUrl(groupIdsUrl); | ||
expect(actual).toStrictEqual(expected); | ||
}); | ||
|
||
it('should get selected group id from the url', () => { | ||
const expected = { groupIds: [groupIdOne] }; | ||
const actual = getSelectedIdFromUrl(groupIdUrl); | ||
expect(actual).toStrictEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('getGroupQueryText', () => { | ||
it('should get query string for selected group ids', () => { | ||
const actual = getGroupQueryText([groupIdOne, groupIdTwo]); | ||
expect(actual).toBe(`groups:(${groupIdOne} or ${groupIdTwo})`); | ||
}); | ||
|
||
it('should get query string for selected group id', () => { | ||
const actual = getGroupQueryText([groupIdOne]); | ||
expect(actual).toBe(`groups:(${groupIdOne})`); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
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. Could you please implement it as a method in ML URL generator? 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. There is an existing issue for consolidating the url generating functions for 7.10 that @qn895 is working on so this will be addressed by that afaik. |
||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import rison from 'rison-node'; | ||
import { getBasePath } from './dependency_cache'; | ||
|
||
export enum TAB_IDS { | ||
DATA_FRAME_ANALYTICS = 'data_frame_analytics', | ||
ANOMALY_DETECTION = 'jobs', | ||
} | ||
|
||
function getSelectedIdsUrl(tabId: TAB_IDS, settings: { [key: string]: string | string[] }): string { | ||
// Create url for filtering by job id or group ids for kibana management table | ||
const encoded = rison.encode(settings); | ||
const url = `?mlManagement=${encoded}`; | ||
const basePath = getBasePath(); | ||
|
||
return `${basePath.get()}/app/ml#/${tabId}${url}`; | ||
} | ||
|
||
// Create url for filtering by group ids for kibana management table | ||
export function getGroupIdsUrl(tabId: TAB_IDS, ids: string[]): string { | ||
const settings = { | ||
groupIds: ids, | ||
}; | ||
|
||
return getSelectedIdsUrl(tabId, settings); | ||
} | ||
|
||
// Create url for filtering by job id for kibana management table | ||
export function getJobIdUrl(tabId: TAB_IDS, id: string): string { | ||
const settings = { | ||
jobId: id, | ||
}; | ||
|
||
return getSelectedIdsUrl(tabId, settings); | ||
} |
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.
We should not access
window.location.href
directly. Would be great to receive it from the router state insteadThere 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.
👍 To be done in a follow up.