Skip to content

Commit

Permalink
Merge branch 'main' into console/fix-failing-bulk-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaStoeva authored Jul 23, 2024
2 parents 5679762 + 2ced941 commit 3d94173
Show file tree
Hide file tree
Showing 39 changed files with 699 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ steps:
limit: 1

- command: .buildkite/scripts/pipelines/security_solution_quality_gate/security_solution_cypress/mki_security_solution_cypress.sh cypress:run:qa:serverless:rule_management:prebuilt_rules
label: "Cypress MKI - Rule Management - Prebuilt Rules
label: "Cypress MKI - Rule Management - Prebuilt Rules"
key: test_rule_management_prebuilt_rules
env:
BK_TEST_SUITE_KEY: "serverless-cypress-rule-management"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const DataControlEditor = <State extends DataControlEditorState = DataCon
initialState.controlType
);
const [controlEditorValid, setControlEditorValid] = useState<boolean>(false);

/** TODO: Make `editorConfig` work when refactoring the `ControlGroupRenderer` */
// const editorConfig = controlGroup.getEditorConfig();

Expand Down Expand Up @@ -193,7 +194,6 @@ export const DataControlEditor = <State extends DataControlEditorState = DataCon
const CustomSettings = controlFactory.CustomOptionsComponent;

if (!CustomSettings) return;

return (
<EuiDescribedFormGroup
ratio="third"
Expand All @@ -210,13 +210,13 @@ export const DataControlEditor = <State extends DataControlEditorState = DataCon
data-test-subj="control-editor-custom-settings"
>
<CustomSettings
initialState={initialState}
currentState={editorState}
updateState={(newState) => setEditorState({ ...editorState, ...newState })}
setControlEditorValid={setControlEditorValid}
/>
</EuiDescribedFormGroup>
);
}, [fieldRegistry, selectedControlType, editorState, initialState]);
}, [fieldRegistry, selectedControlType, editorState]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const initializeDataControl = <EditorState extends object = {}>(
);
} else {
// replace the control with a new one of the updated type
controlGroup.replacePanel(controlId, { panelType: newType, initialState });
controlGroup.replacePanel(controlId, { panelType: newType, initialState: newState });
}
},
initialState: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('RangesliderControlApi', () => {
const CustomSettings = factory.CustomOptionsComponent!;
const component = render(
<CustomSettings
initialState={{}}
currentState={{}}
updateState={jest.fn()}
setControlEditorValid={jest.fn()}
/>
Expand All @@ -263,7 +263,7 @@ describe('RangesliderControlApi', () => {
const CustomSettings = factory.CustomOptionsComponent!;
const component = render(
<CustomSettings
initialState={{}}
currentState={{}}
updateState={jest.fn()}
setControlEditorValid={setControlEditorValid}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useMemo } from 'react';
import deepEqual from 'react-fast-compare';

import { EuiFieldNumber, EuiFormRow } from '@elastic/eui';
Expand Down Expand Up @@ -38,17 +38,15 @@ export const getRangesliderControlFactory = (
isFieldCompatible: (field) => {
return field.aggregatable && field.type === 'number';
},
CustomOptionsComponent: ({ initialState, updateState, setControlEditorValid }) => {
const [step, setStep] = useState(initialState.step ?? 1);

CustomOptionsComponent: ({ currentState, updateState, setControlEditorValid }) => {
const step = currentState.step ?? 1;
return (
<>
<EuiFormRow fullWidth label={RangeSliderStrings.editor.getStepTitle()}>
<EuiFieldNumber
value={step}
onChange={(event) => {
const newStep = event.target.valueAsNumber;
setStep(newStep);
updateState({ step: newStep });
setControlEditorValid(newStep > 0);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import deepEqual from 'react-fast-compare';
import { BehaviorSubject, combineLatest, debounceTime, distinctUntilChanged } from 'rxjs';

Expand Down Expand Up @@ -65,17 +65,15 @@ export const getSearchControlFactory = ({
(field.spec.esTypes ?? []).includes('text')
);
},
CustomOptionsComponent: ({ initialState, updateState }) => {
const [searchTechnique, setSearchTechnique] = useState(initialState.searchTechnique);

CustomOptionsComponent: ({ currentState, updateState }) => {
const searchTechnique = currentState.searchTechnique ?? DEFAULT_SEARCH_TECHNIQUE;
return (
<EuiFormRow label={'Searching'} data-test-subj="searchControl__searchOptionsRadioGroup">
<EuiRadioGroup
options={allSearchOptions}
idSelected={searchTechnique ?? DEFAULT_SEARCH_TECHNIQUE}
idSelected={searchTechnique}
onChange={(id) => {
const newSearchTechnique = id as SearchControlTechniques;
setSearchTechnique(newSearchTechnique);
updateState({ searchTechnique: newSearchTechnique });
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface DataControlFactory<
> extends ControlFactory<State, Api> {
isFieldCompatible: (field: DataViewField) => boolean;
CustomOptionsComponent?: React.FC<{
initialState: Omit<State, keyof DefaultDataControlState>;
currentState: Partial<State>;
updateState: (newState: Partial<State>) => void;
setControlEditorValid: (valid: boolean) => void;
}>;
Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,23 @@ class AgentPolicyService {
);
}

const policyNeedsBump = baseAgentPolicy.package_policies || baseAgentPolicy.is_protected;

// bump revision if agent policy is updated after creation
if (policyNeedsBump) {
await this.bumpRevision(soClient, esClient, newAgentPolicy.id, {
user: options?.user,
});
} else {
await this.deployPolicy(soClient, newAgentPolicy.id);
}

// Get updated agent policy with package policies and adjusted tamper protection
const updatedAgentPolicy = await this.get(soClient, newAgentPolicy.id, true);
if (!updatedAgentPolicy) {
throw new AgentPolicyNotFoundError('Copied agent policy not found');
}

await this.deployPolicy(soClient, newAgentPolicy.id);
logger.debug(`Completed copy of agent policy ${id}`);
return updatedAgentPolicy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ export interface ComponentTemplateListItem {
export interface ComponentTemplateDatastreams {
data_streams: string[];
}

export interface ComponentTemplateMeta {
managed: boolean;
managed_by: string;
package: {
name: string;
};
}
1 change: 1 addition & 0 deletions x-pack/plugins/index_management/common/types/indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IndexModule {
number_of_shards: number | string;
codec: string;
routing_partition_size: number;
refresh_interval: string;
load_fixed_bitset_filters_eagerly: boolean;
shard: {
check_on_startup: boolean | 'checksum';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe('<ComponentTemplateEdit />', () => {
template: {
settings: { number_of_shards: 1 },
},
_kbnMeta: { usedBy: [], isManaged: false },
};

beforeEach(async () => {
Expand Down Expand Up @@ -166,27 +165,30 @@ describe('<ComponentTemplateEdit />', () => {
}),
})
);
// Mapping rollout modal should not be opened if the component template is not managed by Fleet
// Mapping rollout modal should not be opened if the component template is not managed
expect(coreStart.overlays.openModal).not.toBeCalled();
});
});

describe('managed by fleet', () => {
describe('can rollover linked datastreams', () => {
const DATASTREAM_NAME = 'logs-test-default';
const CUSTOM_COMPONENT_TEMPLATE = 'comp-1@custom';
const ENCODED_CUSTOM_COMPONENT_TEMPLATE = encodeURIComponent(CUSTOM_COMPONENT_TEMPLATE);

beforeEach(async () => {
httpRequestsMockHelpers.setLoadComponentTemplateResponse(
COMPONENT_TEMPLATE_TO_EDIT.name,
ENCODED_CUSTOM_COMPONENT_TEMPLATE,
Object.assign({}, COMPONENT_TEMPLATE_TO_EDIT, {
_meta: { managed_by: 'fleet' },
name: CUSTOM_COMPONENT_TEMPLATE,
})
);

httpRequestsMockHelpers.setGetComponentTemplateDatastream(COMPONENT_TEMPLATE_TO_EDIT.name, {
httpRequestsMockHelpers.setGetComponentTemplateDatastream(ENCODED_CUSTOM_COMPONENT_TEMPLATE, {
data_streams: [DATASTREAM_NAME],
});

await act(async () => {
testBed = await setup(httpSetup);
testBed = await setup(httpSetup, '@custom');
});

testBed.component.update();
Expand Down Expand Up @@ -221,7 +223,7 @@ describe('<ComponentTemplateEdit />', () => {
component.update();

expect(httpSetup.put).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/component_templates/${COMPONENT_TEMPLATE_TO_EDIT.name}`,
`${API_BASE_PATH}/component_templates/${ENCODED_CUSTOM_COMPONENT_TEMPLATE}`,
expect.anything()
);
expect(httpSetup.post).toHaveBeenLastCalledWith(
Expand Down Expand Up @@ -259,7 +261,7 @@ describe('<ComponentTemplateEdit />', () => {
component.update();

expect(httpSetup.put).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/component_templates/${COMPONENT_TEMPLATE_TO_EDIT.name}`,
`${API_BASE_PATH}/component_templates/${ENCODED_CUSTOM_COMPONENT_TEMPLATE}`,
expect.anything()
);
expect(httpSetup.post).toHaveBeenLastCalledWith(
Expand All @@ -269,5 +271,76 @@ describe('<ComponentTemplateEdit />', () => {

expect(coreStart.overlays.openModal).not.toBeCalled();
});

it('should show mappings rollover modal on save if referenced index template is managed and packaged', async () => {
httpRequestsMockHelpers.setLoadComponentTemplateResponse(
COMPONENT_TEMPLATE_TO_EDIT.name,
Object.assign({}, COMPONENT_TEMPLATE_TO_EDIT, {
_meta: {},
})
);

httpRequestsMockHelpers.setGetComponentTemplateDatastream(COMPONENT_TEMPLATE_TO_EDIT.name, {
data_streams: [DATASTREAM_NAME],
});

httpRequestsMockHelpers.setLoadReferencedIndexTemplateMetaResponse(
COMPONENT_TEMPLATE_TO_EDIT.name,
{
package: {
name: 'security',
},
managed_by: 'security',
managed: true,
}
);

await act(async () => {
testBed = await setup(httpSetup);
});

testBed.component.update();

httpRequestsMockHelpers.setPostDatastreamMappingsFromTemplate(
DATASTREAM_NAME,
{},
{ message: 'Bad request', statusCode: 400 }
);
const { exists, actions, component, form, coreStart } = testBed;

await act(async () => {
form.setInputValue('versionField.input', '1');
});

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

component.update();

await actions.completeStepSettings();
await actions.completeStepMappings();
await actions.completeStepAliases();

// Make sure the list of affected mappings is shown
expect(exists('affectedMappingsList')).toBe(true);

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

component.update();

expect(httpSetup.put).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/component_templates/${COMPONENT_TEMPLATE_TO_EDIT.name}`,
expect.anything()
);
expect(httpSetup.post).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/data_streams/${DATASTREAM_NAME}/mappings_from_template`,
expect.anything()
);

expect(coreStart.overlays.openModal).toBeCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,5 @@ export type ComponentTemplateFormTestSubjects =
| 'aliasesEditor'
| 'mappingsEditor'
| 'settingsEditor'
| 'affectedMappingsList'
| 'versionField.input';
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ const registerHttpRequestMockHelpers = (
error?: ResponseError
) => mockResponse('GET', `${API_BASE_PATH}/component_templates/${templateId}`, response, error);

const setLoadReferencedIndexTemplateMetaResponse = (
templateId: string,
response?: HttpResponse,
error?: ResponseError
) =>
mockResponse(
'GET',
`${API_BASE_PATH}/component_templates/${templateId}/referenced_index_template_meta`,
response,
error
);

const setDeleteComponentTemplateResponse = (
templateId: string,
response?: HttpResponse,
Expand All @@ -100,6 +112,7 @@ const registerHttpRequestMockHelpers = (

return {
setLoadComponentTemplatesResponse,
setLoadReferencedIndexTemplateMetaResponse,
setDeleteComponentTemplateResponse,
setLoadComponentTemplateResponse,
setCreateComponentTemplateResponse,
Expand Down
Loading

0 comments on commit 3d94173

Please sign in to comment.