Skip to content

Commit

Permalink
Merge branch '7.7' into backport/7.7/pr-63018
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Apr 13, 2020
2 parents ce699ee + 6794371 commit 8e5779b
Show file tree
Hide file tree
Showing 37 changed files with 182 additions and 73 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
"chai": "3.5.0",
"chance": "1.0.18",
"cheerio": "0.22.0",
"chromedriver": "^80.0.1",
"chromedriver": "^81.0.0",
"classnames": "2.2.6",
"dedent": "^0.7.0",
"delete-empty": "^2.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4013,6 +4013,7 @@ function mkdirP (p, opts, f, made) {
}
switch (er.code) {
case 'ENOENT':
if (path.dirname(p) === p) return cb(er);
mkdirP(path.dirname(p), opts, function (er, made) {
if (er) cb(er, made);
else mkdirP(p, opts, cb, made);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class DashboardAppController {
});

// sync initial app filters from state to filterManager
// if there is an existing similar global filter, then leave it as global
filterManager.setAppFilters(_.cloneDeep(dashboardStateManager.appState.filters));
// setup syncing of app filters between appState and filterManager
const stopSyncingAppFilters = connectToQueryState(
Expand Down Expand Up @@ -175,13 +176,16 @@ export class DashboardAppController {
}

// starts syncing `_g` portion of url with query services
// note: dashboard_state_manager.ts syncs `_a` portion of url
// it is important to start this syncing after `dashboardStateManager.syncTimefilterWithDashboard(timefilter);` above is run,
// otherwise it will case redundant browser history record
// otherwise it will case redundant browser history records
const { stop: stopSyncingQueryServiceStateWithUrl } = syncQueryStateWithUrl(
queryService,
kbnUrlStateStorage
);

// starts syncing `_a` portion of url
dashboardStateManager.startStateSyncing();

$scope.showSaveQuery = dashboardCapabilities.saveQuery as boolean;

const getShouldShowEditHelp = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ export class DashboardStateManager {
},
stateStorage: this.kbnUrlStateStorage,
});
}

// actually start syncing state with container
public startStateSyncing() {
this.saveState({ replace: true });
this.stateSyncRef.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RefreshInterval, TimefilterContract } from 'src/plugins/data/public';
import { FilterUtils } from './filter_utils';
import { SavedObjectDashboard } from '../../../../../../../plugins/dashboard/public';
import { DashboardAppState } from '../types';
import { esFilters } from '../../../../../../../plugins/data/public';

export function updateSavedDashboard(
savedDashboard: SavedObjectDashboard,
Expand All @@ -48,4 +49,9 @@ export function updateSavedDashboard(
'value',
]);
savedDashboard.refreshInterval = savedDashboard.timeRestore ? timeRestoreObj : undefined;
// save only unpinned filters
const unpinnedFilters = savedDashboard
.getFilters()
.filter(filter => !esFilters.isFilterPinned(filter));
savedDashboard.searchSource.setField('filter', unpinnedFilters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,19 @@ describe('filter_manager', () => {
).toBe(3);
});

test('should set app filters and remove any duplicated global filters', async function() {
filterManager.addFilters(readyFilters, true);
test('should set app filters and merge them with duplicate global filters', async function() {
const [filter, ...otherFilters] = readyFilters;
filterManager.addFilters(otherFilters, true);
const appFilter1 = _.cloneDeep(readyFilters[1]);
const appFilter2 = _.cloneDeep(readyFilters[2]);

filterManager.setAppFilters([appFilter1, appFilter2]);
filterManager.setAppFilters([filter, appFilter1, appFilter2]);

const newGlobalFilters = filterManager.getGlobalFilters();
const newAppFilters = filterManager.getAppFilters();

expect(newGlobalFilters).toHaveLength(1);
expect(newAppFilters).toHaveLength(2);
expect(newGlobalFilters).toHaveLength(2);
expect(newAppFilters).toHaveLength(1);
});

test('should set global filters and remove any duplicated app filters', async function() {
Expand Down
17 changes: 4 additions & 13 deletions src/plugins/data/public/query/filter_manager/filter_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,9 @@ export class FilterManager {
public setGlobalFilters(newGlobalFilters: Filter[]) {
newGlobalFilters = mapAndFlattenFilters(newGlobalFilters);
FilterManager.setFiltersStore(newGlobalFilters, FilterStateStore.GLOBAL_STATE, true);
const { appFilters: currentAppFilters } = this.getPartitionedFilters();
// remove duplicates from current app filters, to make sure global will take precedence
const filteredAppFilters = currentAppFilters.filter(
appFilter => !newGlobalFilters.find(globalFilter => compareFilters(globalFilter, appFilter))
);
const { appFilters } = this.getPartitionedFilters();
const newFilters = this.mergeIncomingFilters({
appFilters: filteredAppFilters,
appFilters,
globalFilters: newGlobalFilters,
});

Expand All @@ -198,14 +194,9 @@ export class FilterManager {
public setAppFilters(newAppFilters: Filter[]) {
newAppFilters = mapAndFlattenFilters(newAppFilters);
FilterManager.setFiltersStore(newAppFilters, FilterStateStore.APP_STATE, true);
const { globalFilters: currentGlobalFilters } = this.getPartitionedFilters();
// remove duplicates from current global filters, to make sure app will take precedence
const filteredGlobalFilters = currentGlobalFilters.filter(
globalFilter => !newAppFilters.find(appFilter => compareFilters(appFilter, globalFilter))
);

const { globalFilters } = this.getPartitionedFilters();
const newFilters = this.mergeIncomingFilters({
globalFilters: filteredGlobalFilters,
globalFilters,
appFilters: newAppFilters,
});
this.handleStateUpdate(newFilters);
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/ui/filter_bar/filter_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class FilterItemUI extends Component<Props, State> {
const dataTestSubjDisabled = `filter-${
this.props.filter.meta.disabled ? 'disabled' : 'enabled'
}`;
const dataTestSubjPinned = `filter-${isFilterPinned(filter) ? 'pinned' : 'unpinned'}`;

const classes = classNames(
'globalFilterItem',
Expand All @@ -107,7 +108,7 @@ class FilterItemUI extends Component<Props, State> {
className={classes}
iconOnClick={() => this.props.onRemove()}
onClick={this.handleBadgeClick}
data-test-subj={`filter ${dataTestSubjDisabled} ${dataTestSubjKey} ${dataTestSubjValue}`}
data-test-subj={`filter ${dataTestSubjDisabled} ${dataTestSubjKey} ${dataTestSubjValue} ${dataTestSubjPinned}`}
/>
);

Expand Down
38 changes: 38 additions & 0 deletions test/functional/apps/dashboard/dashboard_filter_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function({ getService, getPageObjects }) {
const pieChart = getService('pieChart');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const browser = getService('browser');
const PageObjects = getPageObjects(['common', 'dashboard', 'header', 'visualize', 'timePicker']);

describe('dashboard filter bar', () => {
Expand Down Expand Up @@ -126,9 +127,46 @@ export default function({ getService, getPageObjects }) {

const filterCount = await filterBar.getFilterCount();
expect(filterCount).to.equal(1);
await pieChart.expectPieSliceCount(1);
});

it("restoring filters doesn't break back button", async () => {
await browser.goBack();
await PageObjects.dashboard.expectExistsDashboardLandingPage();
await browser.goForward();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.waitForRenderComplete();
await pieChart.expectPieSliceCount(1);
});

it("saving with pinned filter doesn't unpin them", async () => {
const filterKey = 'bytes';
await filterBar.toggleFilterPinned(filterKey);
await PageObjects.dashboard.switchToEditMode();
await PageObjects.dashboard.saveDashboard('saved with pinned filters', {
saveAsNew: true,
});
expect(await filterBar.isFilterPinned(filterKey)).to.be(true);
await pieChart.expectPieSliceCount(1);
});

it("navigating to a dashboard with global filter doesn't unpin it if same filter is saved with dashboard", async () => {
await PageObjects.dashboard.preserveCrossAppState();
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.loadSavedDashboard('with filters');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await filterBar.isFilterPinned('bytes')).to.be(true);
await pieChart.expectPieSliceCount(1);
});

it("pinned filters aren't saved", async () => {
await filterBar.removeFilter('bytes');
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.loadSavedDashboard('saved with pinned filters');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await filterBar.getFilterCount()).to.be(0);
await pieChart.expectPieSliceCount(5);
});
});

describe('saved search filtering', function() {
Expand Down
15 changes: 13 additions & 2 deletions test/functional/services/filter_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ export function FilterBarProvider({ getService, getPageObjects }: FtrProviderCon
* @param value filter value
* @param enabled filter status
*/
public async hasFilter(key: string, value: string, enabled: boolean = true): Promise<boolean> {
public async hasFilter(
key: string,
value: string,
enabled: boolean = true,
pinned: boolean = false
): Promise<boolean> {
const filterActivationState = enabled ? 'enabled' : 'disabled';
const filterPinnedState = pinned ? 'pinned' : 'unpinned';
return testSubjects.exists(
`filter filter-${filterActivationState} filter-key-${key} filter-value-${value}`,
`filter filter-${filterActivationState} filter-key-${key} filter-value-${value} filter-${filterPinnedState}`,
{
allowHidden: true,
}
Expand Down Expand Up @@ -80,6 +86,11 @@ export function FilterBarProvider({ getService, getPageObjects }: FtrProviderCon
await PageObjects.header.awaitGlobalLoadingIndicatorHidden();
}

public async isFilterPinned(key: string): Promise<boolean> {
const filter = await testSubjects.find(`~filter & ~filter-key-${key}`);
return (await filter.getAttribute('data-test-subj')).includes('filter-pinned');
}

public async getFilterCount(): Promise<number> {
const filters = await testSubjects.findAll('~filter');
return filters.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ManageCustomLink } from './ManageCustomLink';
import { px } from '../../../../style/variables';

const ScrollableContainer = styled.div`
-ms-overflow-style: none;
max-height: ${px(535)};
overflow: scroll;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const TransactionActionMenu: FunctionComponent<Props> = ({
<ActionMenuButton onClick={() => setIsActionPopoverOpen(true)} />
}
>
<div style={{ maxHeight: px(600) }}>
<div style={{ maxHeight: px(600), width: px(335) }}>
{isCustomLinksPopoverOpen ? (
<CustomLinkPopover
customLinks={customLinks.slice(3, customLinks.length)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that rarely uses the network could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "linux_anomalous_network_activity_ecs",
"name": "Unusual Linux Network Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that rarely uses the network could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "linux_anomalous_network_port_activity_ecs",
"name": "Unusual Linux Network Port Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that rarely uses the network could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "linux_anomalous_network_service",
"name": "Unusual Linux Network Service",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A new and unusual program or artifact download in the course of software upgrades, debugging, or troubleshooting could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "linux_anomalous_network_url_activity_ecs",
"name": "Unusual Linux Web Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that runs rarely as part of a monthly or quarterly workflow could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "linux_anomalous_process_all_hosts_ecs",
"name": "Anomalous Process For a Linux Population",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"Uncommon user activity can be due to an engineer logging onto a server instance in order to perform manual troubleshooting or reconfiguration."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "linux_anomalous_user_name_ecs",
"name": "Unusual Linux Username",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"DNS domains that use large numbers of child domains, such as software or content distribution networks, can trigger this signal and such parent domains can be excluded."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "packetbeat_dns_tunneling",
"name": "DNS Tunneling",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that runs rarely as part of a monthly or quarterly workflow could trigger this signal. Network activity that occurs rarely, in small quantities, can trigger this signal. Possible examples are browsing technical support or vendor networks sparsely. A user who visits a new or unique web destination may trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "packetbeat_rare_dns_question",
"name": "Unusual DNS Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"Web activity that occurs rarely in small quantities can trigger this signal. Possible examples are browsing technical support or vendor URLs that are used very sparsely. A user who visits a new and unique web destination may trigger this signal when the activity is sparse. Web applications that generate URLs unique to a transaction may trigger this when they are used sparsely. Web domains can be excluded in cases such as these."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "packetbeat_rare_server_domain",
"name": "Unusual Network Destination Domain Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"Web activity that occurs rarely in small quantities can trigger this signal. Possible examples are browsing technical support or vendor URLs that are used very sparsely. A user who visits a new and unique web destination may trigger this signal when the activity is sparse. Web applications that generate URLs unique to a transaction may trigger this when they are used sparsely. Web domains can be excluded in cases such as these."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "packetbeat_rare_urls",
"name": "Unusual Web Request",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"Web activity that is uncommon, like security scans, may trigger this signal and may need to be excluded. A new or rarely used program that calls web services may trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "packetbeat_rare_user_agent",
"name": "Unusual Web User Agent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that runs rarely as part of a monthly or quarterly workflow could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "rare_process_by_host_linux_ecs",
"name": "Unusual Process For a Linux Host",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that runs rarely as part of a monthly or quarterly workflow could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "rare_process_by_host_windows_ecs",
"name": "Unusual Process For a Windows Host",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"Security audits may trigger this signal. Conditions that generate bursts of failed logins, such as misconfigured applications or account lockouts could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "suspicious_login_activity_ecs",
"name": "Unusual Login Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A newly installed program or one that rarely uses the network could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "windows_anomalous_network_activity_ecs",
"name": "Unusual Windows Network Activity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"false_positives": [
"A new and unusual program or artifact download in the course of software upgrades, debugging, or troubleshooting could trigger this signal. Users downloading and running programs from unusual locations, such as temporary directories, browser caches, or profile paths could trigger this signal."
],
"from": "now-16m",
"from": "now-45m",
"interval": "15m",
"machine_learning_job_id": "windows_anomalous_path_activity_ecs",
"name": "Unusual Windows Path Activity",
Expand Down
Loading

0 comments on commit 8e5779b

Please sign in to comment.