Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into rxjs-over-rxjs/…
Browse files Browse the repository at this point in the history
…operators
  • Loading branch information
afharo committed Apr 2, 2024
2 parents 713e7a1 + 6ecbe53 commit cedc45e
Show file tree
Hide file tree
Showing 21 changed files with 782 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ingest-agent-policies": "7633e578f60c074f8267bc50ec4763845e431437",
"ingest-download-sources": "279a68147e62e4d8858c09ad1cf03bd5551ce58d",
"ingest-outputs": "daafff49255ab700e07491376fe89f04fc998b91",
"ingest-package-policies": "f4c2767e852b700a8b82678925b86bac08958b43",
"ingest-package-policies": "8a99e165aab00c6c365540427a3abeb7bea03f31",
"ingest_manager_settings": "91445219e7115ff0c45d1dabd5d614a80b421797",
"inventory-view": "b8683c8e352a286b4aca1ab21003115a4800af83",
"kql-telemetry": "93c1d16c1a0dfca9c8842062cf5ef8f62ae401ad",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React, { createContext, useContext } from 'react';
import ReactDOM from 'react-dom';
import { batch, Provider, TypedUseSelectorHook, useSelector } from 'react-redux';
import { BehaviorSubject, merge, Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, filter, first, skip } from 'rxjs';
import { debounceTime, distinctUntilChanged, skip } from 'rxjs';

import { OverlayRef } from '@kbn/core/public';
import { Container, EmbeddableFactory } from '@kbn/embeddable-plugin/public';
Expand Down Expand Up @@ -173,6 +173,13 @@ export class ControlGroupContainer extends Container<
this.setupSubscriptions();
const { filters, timeslice } = this.recalculateFilters();
this.publishFilters({ filters, timeslice });

this.calculateFiltersFromSelections(initialComponentState?.lastSavedInput?.panels ?? {}).then(
(filterOutput) => {
this.dispatch.setLastSavedFilters(filterOutput);
}
);

this.initialized$.next(true);
});

Expand Down Expand Up @@ -206,29 +213,6 @@ export class ControlGroupContainer extends Container<
};

private setupSubscriptions = () => {
/**
* on initialization, in order for comparison to be performed, calculate the last saved filters based on the
* selections from the last saved input and save them to component state. This is done as a subscription so that
* it can be done async without actually slowing down the loading of the controls.
*/
this.subscriptions.add(
this.initialized$
.pipe(
filter((isInitialized) => isInitialized),
first()
)
.subscribe(async () => {
const {
componentState: { lastSavedInput },
explicitInput: { panels },
} = this.getState();
const filterOutput = await this.calculateFiltersFromSelections(
lastSavedInput?.panels ?? panels
);
this.dispatch.setLastSavedFilters(filterOutput);
})
);

/**
* refresh control order cache and make all panels refreshInputFromParent whenever panel orders change
*/
Expand Down Expand Up @@ -289,11 +273,12 @@ export class ControlGroupContainer extends Container<
);
};

public setSavedState(lastSavedInput: PersistableControlGroupInput): void {
batch(() => {
this.dispatch.setLastSavedInput(lastSavedInput);
const { filters, timeslice } = this.getState().output;
this.dispatch.setLastSavedFilters({ filters, timeslice });
public setSavedState(lastSavedInput: PersistableControlGroupInput | undefined): void {
this.calculateFiltersFromSelections(lastSavedInput?.panels ?? {}).then((filterOutput) => {
batch(() => {
this.dispatch.setLastSavedInput(lastSavedInput);
this.dispatch.setLastSavedFilters(filterOutput);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,8 @@ export class DashboardContainer
omit(loadDashboardReturn?.dashboardInput, 'controlGroupInput')
);
this.dispatch.setManaged(loadDashboardReturn?.managed);
if (this.controlGroup && loadDashboardReturn?.dashboardInput.controlGroupInput) {
this.controlGroup.dispatch.setLastSavedInput(
loadDashboardReturn?.dashboardInput.controlGroupInput
);
if (this.controlGroup) {
this.controlGroup.setSavedState(loadDashboardReturn.dashboardInput?.controlGroupInput);
}
this.dispatch.setAnimatePanelTransforms(false); // prevents panels from animating on navigate.
this.dispatch.setLastSavedId(newSavedObjectId);
Expand Down
5 changes: 2 additions & 3 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare global {
* We use this global variable to track page history changes to ensure that
* navigation is done without causing a full page reload.
*/
__RENDERING_SESSION__: string[];
__RENDERING_SESSION__?: string[];
}
}

Expand All @@ -39,11 +39,10 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
await appsMenu.clickLink(title);
return browser.execute(() => {
if (!('__RENDERING_SESSION__' in window)) {
// @ts-expect-error upgrade typescript v4.9.5
window.__RENDERING_SESSION__ = [];
}

window.__RENDERING_SESSION__.push(window.location.pathname);
window.__RENDERING_SESSION__!.push(window.location.pathname);
});
};

Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
} from './migrations/to_v8_6_0';
import {
migratePackagePolicyToV8100,
migratePackagePolicyToV8140,
migratePackagePolicyToV870,
} from './migrations/security_solution';
import { migratePackagePolicyToV880 } from './migrations/to_v8_8_0';
Expand Down Expand Up @@ -473,6 +474,14 @@ export const getSavedObjectTypes = (): { [key: string]: SavedObjectsType } => ({
},
],
},
'6': {
changes: [
{
type: 'data_backfill',
backfillFn: migratePackagePolicyToV8140,
},
],
},
},
migrations: {
'7.10.0': migratePackagePolicyToV7100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export { migratePackagePolicyToV860 } from './to_v8_6_0';
export { migratePackagePolicyToV870 } from './to_v8_7_0';
export { migratePackagePolicyToV880 } from './to_v8_8_0';
export { migratePackagePolicyToV8100 } from './to_v8_10_0';
export { migratePackagePolicyToV8140 } from './to_v8_14_0';
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
createModelVersionTestMigrator,
type ModelVersionTestMigrator,
} from '@kbn/core-test-helpers-model-versions';

import { cloneDeep } from 'lodash';

import type { SavedObject } from '@kbn/core-saved-objects-server';

import type { PackagePolicy } from '../../../../common';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
import { getSavedObjectTypes } from '../..';

const policyDoc: SavedObject<PackagePolicy> = {
id: 'mock-saved-object-id',
attributes: {
name: 'Some Policy Name',
package: {
name: 'endpoint',
title: '',
version: '',
},
id: 'endpoint',
policy_id: '',
enabled: true,
namespace: '',
revision: 0,
updated_at: '',
updated_by: '',
created_at: '',
created_by: '',
inputs: [
{
type: 'endpoint',
enabled: true,
streams: [],
config: {
policy: {
value: {
windows: {
malware: {
mode: 'detect',
blocklist: true,
},
},
mac: {
malware: {
mode: 'detect',
blocklist: true,
},
},
linux: {
malware: {
mode: 'detect',
blocklist: true,
},
},
},
},
},
},
],
},
type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
references: [],
};

describe('8.14.0 Endpoint Package Policy migration', () => {
let migrator: ModelVersionTestMigrator;

beforeEach(() => {
migrator = createModelVersionTestMigrator({
type: getSavedObjectTypes()[PACKAGE_POLICY_SAVED_OBJECT_TYPE],
});
});

it('should backfill `on_write_scan` field to malware protections on Kibana update', () => {
const originalPolicyConfigSO = cloneDeep(policyDoc);

const migratedPolicyConfigSO = migrator.migrate<PackagePolicy, PackagePolicy>({
document: originalPolicyConfigSO,
fromVersion: 5,
toVersion: 6,
});

const migratedPolicyConfig = migratedPolicyConfigSO.attributes.inputs[0].config?.policy.value;
expect(migratedPolicyConfig.windows.malware.on_write_scan).toBe(true);
expect(migratedPolicyConfig.mac.malware.on_write_scan).toBe(true);
expect(migratedPolicyConfig.linux.malware.on_write_scan).toBe(true);
});

it('should not backfill `on_write_scan` field if already present due to user edit before migration is performed on serverless', () => {
const originalPolicyConfigSO = cloneDeep(policyDoc);
const originalPolicyConfig = originalPolicyConfigSO.attributes.inputs[0].config?.policy.value;
originalPolicyConfig.windows.malware.on_write_scan = false;
originalPolicyConfig.mac.malware.on_write_scan = true;
originalPolicyConfig.linux.malware.on_write_scan = false;

const migratedPolicyConfigSO = migrator.migrate<PackagePolicy, PackagePolicy>({
document: originalPolicyConfigSO,
fromVersion: 5,
toVersion: 6,
});

const migratedPolicyConfig = migratedPolicyConfigSO.attributes.inputs[0].config?.policy.value;
expect(migratedPolicyConfig.windows.malware.on_write_scan).toBe(false);
expect(migratedPolicyConfig.mac.malware.on_write_scan).toBe(true);
expect(migratedPolicyConfig.linux.malware.on_write_scan).toBe(false);
});

// no reason for removing `on_write_scan` for a lower version Kibana - the field will just sit silently in the package config
it('should not strip `on_write_scan` in regards of forward compatibility', () => {
const originalPolicyConfigSO = cloneDeep(policyDoc);
const originalPolicyConfig = originalPolicyConfigSO.attributes.inputs[0].config?.policy.value;
originalPolicyConfig.windows.malware.on_write_scan = false;
originalPolicyConfig.mac.malware.on_write_scan = true;
originalPolicyConfig.linux.malware.on_write_scan = false;

const migratedPolicyConfigSO = migrator.migrate<PackagePolicy, PackagePolicy>({
document: originalPolicyConfigSO,
fromVersion: 6,
toVersion: 5,
});

const migratedPolicyConfig = migratedPolicyConfigSO.attributes.inputs[0].config?.policy.value;
expect(migratedPolicyConfig.windows.malware.on_write_scan).toBe(false);
expect(migratedPolicyConfig.mac.malware.on_write_scan).toBe(true);
expect(migratedPolicyConfig.linux.malware.on_write_scan).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { SavedObjectUnsanitizedDoc } from '@kbn/core/server';

import type { SavedObjectModelDataBackfillFn } from '@kbn/core-saved-objects-server';

import type { PackagePolicy } from '../../../../common';

const ON_WRITE_SCAN_DEFAULT_VALUE = true;

export const migratePackagePolicyToV8140: SavedObjectModelDataBackfillFn<
PackagePolicy,
PackagePolicy
> = (packagePolicyDoc) => {
if (packagePolicyDoc.attributes.package?.name !== 'endpoint') {
return { attributes: packagePolicyDoc.attributes };
}

const updatedPackagePolicyDoc: SavedObjectUnsanitizedDoc<PackagePolicy> = packagePolicyDoc;

const input = updatedPackagePolicyDoc.attributes.inputs[0];

if (input && input.config) {
const policy = input.config.policy.value;

policy.windows.malware.on_write_scan ??= ON_WRITE_SCAN_DEFAULT_VALUE;
policy.mac.malware.on_write_scan ??= ON_WRITE_SCAN_DEFAULT_VALUE;
policy.linux.malware.on_write_scan ??= ON_WRITE_SCAN_DEFAULT_VALUE;
}

return { attributes: updatedPackagePolicyDoc.attributes };
};
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@
"@kbn/config",
"@kbn/core-http-server-mocks",
"@kbn/code-editor",
"@kbn/core-test-helpers-model-versions",
]
}
Loading

0 comments on commit cedc45e

Please sign in to comment.