Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-86653
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jan 8, 2021
2 parents 902a72c + 1aeb45a commit 414d6ae
Show file tree
Hide file tree
Showing 47 changed files with 426 additions and 335 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
"@babel/traverse": "^7.11.5",
"@babel/types": "^7.11.0",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.4.11",
"@cypress/webpack-preprocessor": "^5.5.0",
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "24.4.0",
Expand Down Expand Up @@ -604,7 +604,7 @@
"cpy": "^8.1.1",
"cronstrue": "^1.51.0",
"css-loader": "^3.4.2",
"cypress": "^6.1.0",
"cypress": "^6.2.1",
"cypress-cucumber-preprocessor": "^2.5.2",
"cypress-multi-reporters": "^1.4.0",
"d3": "3.5.17",
Expand Down
5 changes: 3 additions & 2 deletions packages/kbn-es-archiver/src/actions/empty_kibana_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { Client } from 'elasticsearch';
import { ToolingLog, KbnClient } from '@kbn/dev-utils';

import { migrateKibanaIndex, deleteKibanaIndices, createStats } from '../lib';
import { migrateKibanaIndex, createStats, cleanKibanaIndices } from '../lib';

export async function emptyKibanaIndexAction({
client,
Expand All @@ -32,8 +32,9 @@ export async function emptyKibanaIndexAction({
kbnClient: KbnClient;
}) {
const stats = createStats('emptyKibanaIndex', log);
const kibanaPluginIds = await kbnClient.plugins.getEnabledIds();

await deleteKibanaIndices({ client, stats, log });
await cleanKibanaIndices({ client, stats, log, kibanaPluginIds });
await migrateKibanaIndex({ client, kbnClient });
return stats;
}
1 change: 1 addition & 0 deletions packages/kbn-es-archiver/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
createGenerateIndexRecordsStream,
deleteKibanaIndices,
migrateKibanaIndex,
cleanKibanaIndices,
createDefaultSpace,
} from './indices';

Expand Down
7 changes: 6 additions & 1 deletion packages/kbn-es-archiver/src/lib/indices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
export { createCreateIndexStream } from './create_index_stream';
export { createDeleteIndexStream } from './delete_index_stream';
export { createGenerateIndexRecordsStream } from './generate_index_records_stream';
export { migrateKibanaIndex, deleteKibanaIndices, createDefaultSpace } from './kibana_index';
export {
migrateKibanaIndex,
deleteKibanaIndices,
cleanKibanaIndices,
createDefaultSpace,
} from './kibana_index';
1 change: 1 addition & 0 deletions packages/kbn-es-archiver/src/lib/indices/kibana_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export async function migrateKibanaIndex({
body: {
dynamic: true,
},
ignore: [404],
} as any);

await kbnClient.savedObjects.migrate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ describe('<TemplateEdit />', () => {
const templateToEdit = fixtures.getTemplate({
name: 'index_template_without_mappings',
indexPatterns: ['indexPattern1'],
dataStream: {
hidden: true,
anyUnknownKey: 'should_be_kept',
},
});

beforeAll(() => {
Expand All @@ -85,7 +89,7 @@ describe('<TemplateEdit />', () => {
testBed.component.update();
});

it('allows you to add mappings', async () => {
test('allows you to add mappings', async () => {
const { actions, find } = testBed;
// Logistics
await actions.completeStepOne();
Expand Down Expand Up @@ -123,11 +127,15 @@ describe('<TemplateEdit />', () => {
const expected = {
name: 'index_template_without_mappings',
indexPatterns: ['indexPattern1'],
dataStream: {
hidden: true,
anyUnknownKey: 'should_be_kept',
},
version,
_kbnMeta: {
type: 'default',
isLegacy: templateToEdit._kbnMeta.isLegacy,
hasDatastream: false,
hasDatastream: true,
},
};

Expand All @@ -152,6 +160,47 @@ describe('<TemplateEdit />', () => {

expect(exists('requestTab')).toBe(true);
});

test('should keep data stream configuration', async () => {
const { actions } = testBed;
// Logistics
await actions.completeStepOne({
name: 'test',
indexPatterns: ['myPattern*'],
version: 1,
});
// Component templates
await actions.completeStepTwo();
// Index settings
await actions.completeStepThree();
// Mappings
await actions.completeStepFour();
// Aliases
await actions.completeStepFive();

await act(async () => {
actions.clickNextButton();
});

const latestRequest = server.requests[server.requests.length - 1];

const expected = {
name: 'test',
indexPatterns: ['myPattern*'],
dataStream: {
hidden: true,
anyUnknownKey: 'should_be_kept',
},
version: 1,
_kbnMeta: {
type: 'default',
isLegacy: false,
hasDatastream: true,
},
};

expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
});
});

describe('with mappings', () => {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/index_management/common/types/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export interface TemplateDeserialized {
name: string;
};
_meta?: { [key: string]: any }; // Composable template only
dataStream?: {}; // Composable template only
// Composable template only
dataStream?: {
hidden?: boolean;
[key: string]: any;
};
_kbnMeta: {
type: TemplateType;
hasDatastream: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function getFieldsMeta(esDocsBase: string) {
),
testSubject: 'indexPatternsField',
},
dataStream: {
createDataStream: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.dataStreamTitle', {
defaultMessage: 'Data stream',
}),
Expand Down Expand Up @@ -119,6 +119,7 @@ interface LogisticsForm {

interface LogisticsFormInternal extends LogisticsForm {
addMeta: boolean;
doCreateDataStream: boolean;
}

interface Props {
Expand All @@ -132,12 +133,16 @@ function formDeserializer(formData: LogisticsForm): LogisticsFormInternal {
return {
...formData,
addMeta: Boolean(formData._meta && Object.keys(formData._meta).length),
doCreateDataStream: Boolean(formData.dataStream),
};
}

function formSerializer(formData: LogisticsFormInternal): LogisticsForm {
const { addMeta, ...rest } = formData;
return rest;
function getformSerializer(initialTemplateData: LogisticsForm = {}) {
return (formData: LogisticsFormInternal): LogisticsForm => {
const { addMeta, doCreateDataStream, ...rest } = formData;
const dataStream = doCreateDataStream ? initialTemplateData.dataStream ?? {} : undefined;
return { ...rest, dataStream };
};
}

export const StepLogistics: React.FunctionComponent<Props> = React.memo(
Expand All @@ -146,7 +151,7 @@ export const StepLogistics: React.FunctionComponent<Props> = React.memo(
schema: schemas.logistics,
defaultValue,
options: { stripEmptyFields: false },
serializer: formSerializer,
serializer: getformSerializer(defaultValue),
deserializer: formDeserializer,
});
const {
Expand Down Expand Up @@ -178,7 +183,7 @@ export const StepLogistics: React.FunctionComponent<Props> = React.memo(
});
}, [onChange, isFormValid, validate, getFormData]);

const { name, indexPatterns, dataStream, order, priority, version } = getFieldsMeta(
const { name, indexPatterns, createDataStream, order, priority, version } = getFieldsMeta(
documentationService.getEsDocsBase()
);

Expand Down Expand Up @@ -245,10 +250,10 @@ export const StepLogistics: React.FunctionComponent<Props> = React.memo(

{/* Create data stream */}
{isLegacy !== true && (
<FormRow title={dataStream.title} description={dataStream.description}>
<FormRow title={createDataStream.title} description={createDataStream.description}>
<UseField
path="dataStream"
componentProps={{ 'data-test-subj': dataStream.testSubject }}
path="doCreateDataStream"
componentProps={{ 'data-test-subj': createDataStream.testSubject }}
/>
</FormRow>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,12 @@ export const schemas: Record<string, FormSchema> = {
},
],
},
dataStream: {
doCreateDataStream: {
type: FIELD_TYPES.TOGGLE,
label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.datastreamLabel', {
defaultMessage: 'Create data stream',
}),
defaultValue: false,
serializer: (value) => {
if (value === true) {
// For now, ES expects an empty object when defining a data stream
// https://github.com/elastic/elasticsearch/pull/59317
return {};
}
},
deserializer: (value) => {
if (typeof value === 'boolean') {
return value;
}

/**
* For now, it is enough to have a "data_stream" declared on the index template
* to assume that the template creates a data stream. In the future, this condition
* might change
*/
return value !== undefined;
},
},
order: {
type: FIELD_TYPES.NUMBER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ export const templateSchema = schema.object({
})
),
composedOf: schema.maybe(schema.arrayOf(schema.string())),
dataStream: schema.maybe(schema.object({}, { unknowns: 'allow' })),
dataStream: schema.maybe(
schema.object(
{
hidden: schema.maybe(schema.boolean()),
},
{ unknowns: 'allow' }
)
),
_meta: schema.maybe(schema.object({}, { unknowns: 'allow' })),
ilmPolicy: schema.maybe(
schema.object({
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/index_management/test/fixtures/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const getTemplate = ({
order = getRandomNumber(),
indexPatterns = [],
template: { settings, aliases, mappings } = {},
dataStream,
hasDatastream = false,
isLegacy = false,
type = 'default',
Expand All @@ -73,12 +74,13 @@ export const getTemplate = ({
mappings,
settings,
},
dataStream,
hasSettings: objHasProperties(settings),
hasMappings: objHasProperties(mappings),
hasAliases: objHasProperties(aliases),
_kbnMeta: {
type,
hasDatastream,
hasDatastream: dataStream !== undefined ? true : hasDatastream,
isLegacy,
},
};
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/security_solution/cypress/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"baseUrl": "http://localhost:5601",
"defaultCommandTimeout": 60000,
"execTimeout": 120000,
"pageLoadTimeout": 120000,
"nodeVersion": "system",
"retries": {
"runMode": 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Detections > Callouts indicating read-only access to resources', () =>
const RULES_CALLOUT = 'read-only-access-to-rules';

before(() => {
// First, we have to open the app on behalf of a priviledged user in order to initialize it.
// First, we have to open the app on behalf of a privileged user in order to initialize it.
// Otherwise the app will be disabled and show a "welcome"-like page.
cleanKibana();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL, ROLES.platform_engineer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
import { DEFAULT_RULE_REFRESH_INTERVAL_VALUE } from '../../common/constants';

import { DETECTIONS_URL } from '../urls/navigation';
import { createCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { createCustomRule } from '../tasks/api_calls/rules';
import { cleanKibana } from '../tasks/common';
import { existingRule, newOverrideRule, newRule, newThresholdRule } from '../objects/rule';

describe('Alerts detection rules', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
Expand Down
Loading

0 comments on commit 414d6ae

Please sign in to comment.