mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Search Connectors] - Remove duplicate agent policy when connector is created as an integration (#208123)
## Summary With Agentless Connectors, users can create a connector without a `connector_id` or a `connector_name`, so when a policy is created without them, they won't be skipped anymore. The connectors do end up getting their `connector_id `updated to be the policy's `package_policy_id`, so when the check is done whether or not to deploy native connectors and create a policy, there's an an additional check for whether `connector_id` is the `package_policy_id`. - Closes https://github.com/orgs/elastic/projects/740/views/58?pane=issue&itemId=94923696&issue=elastic%7Csearch-team%7C9164 - Closes https://github.com/orgs/elastic/projects/740/views/58?pane=issue&itemId=94923696&issue=elastic%7Csearch-team%7C9164 ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
96e3d55638
commit
7ee6c3fcb0
2 changed files with 54 additions and 6 deletions
|
@ -301,7 +301,7 @@ describe('AgentlessConnectorsInfraService', () => {
|
|||
expect(policies[1].agent_policy_ids).toBe(thirdPackagePolicy.policy_ids);
|
||||
});
|
||||
|
||||
test('Skips policies that have missing fields', async () => {
|
||||
test('Returns policies that have missing connector_id and connector_name but not service_type', async () => {
|
||||
const firstPackagePolicy = createPackagePolicyMock();
|
||||
firstPackagePolicy.id = 'this-is-package-policy-id';
|
||||
firstPackagePolicy.policy_ids = ['this-is-agent-policy-id'];
|
||||
|
@ -325,13 +325,28 @@ describe('AgentlessConnectorsInfraService', () => {
|
|||
} as PackagePolicyInput,
|
||||
];
|
||||
|
||||
const thirdPackagePolicy = createPackagePolicyMock();
|
||||
thirdPackagePolicy.inputs = [
|
||||
{
|
||||
type: 'connectors-py',
|
||||
compiled_input: {
|
||||
connector_id: '000002',
|
||||
service_type: 'github',
|
||||
},
|
||||
} as PackagePolicyInput,
|
||||
];
|
||||
|
||||
packagePolicyService.fetchAllItems.mockResolvedValue(
|
||||
getMockPolicyFetchAllItems([[firstPackagePolicy], [secondPackagePolicy]])
|
||||
getMockPolicyFetchAllItems([
|
||||
[firstPackagePolicy],
|
||||
[secondPackagePolicy],
|
||||
[thirdPackagePolicy],
|
||||
])
|
||||
);
|
||||
|
||||
const policies = await service.getConnectorPackagePolicies();
|
||||
|
||||
expect(policies.length).toBe(0);
|
||||
expect(policies.length).toBe(2);
|
||||
});
|
||||
});
|
||||
describe('deployConnector', () => {
|
||||
|
@ -579,6 +594,20 @@ describe('module', () => {
|
|||
is_deleted: false,
|
||||
};
|
||||
|
||||
const confluenceConnector: ConnectorMetadata = {
|
||||
id: '000004',
|
||||
name: 'Confluence Connector',
|
||||
service_type: 'confluence',
|
||||
is_deleted: false,
|
||||
};
|
||||
|
||||
const confluenceConnectorEmptySettings: ConnectorMetadata = {
|
||||
id: '',
|
||||
name: '',
|
||||
service_type: 'confluence',
|
||||
is_deleted: false,
|
||||
};
|
||||
|
||||
const deleted = (connector: ConnectorMetadata): ConnectorMetadata => {
|
||||
return {
|
||||
id: connector.id,
|
||||
|
@ -606,6 +635,12 @@ describe('module', () => {
|
|||
connector_settings: mysqlConnector,
|
||||
};
|
||||
|
||||
const confluencePackagePolicy: PackagePolicyMetadata = {
|
||||
package_policy_id: '000004',
|
||||
agent_policy_ids: [],
|
||||
connector_settings: confluenceConnectorEmptySettings,
|
||||
};
|
||||
|
||||
describe('getPoliciesToDelete', () => {
|
||||
test('Returns one policy if connector has been soft-deleted', async () => {
|
||||
const policiesToDelete = getPoliciesToDelete(
|
||||
|
@ -688,5 +723,14 @@ describe('module', () => {
|
|||
expect(missingConnectors).toContain(sharepointConnector);
|
||||
expect(missingConnectors).toContain(mysqlConnector);
|
||||
});
|
||||
|
||||
test('Returns none if Policy is created without a connector_id or connector_name', async () => {
|
||||
const missingConnectors = getConnectorsToDeploy(
|
||||
[githubPackagePolicy, sharepointPackagePolicy, mysqlPackagePolicy, confluencePackagePolicy],
|
||||
[githubConnector, sharepointConnector, mysqlConnector, confluenceConnector]
|
||||
);
|
||||
|
||||
expect(missingConnectors.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -106,8 +106,8 @@ export class AgentlessConnectorsInfraService {
|
|||
}
|
||||
|
||||
if (input.compiled_input.connector_id == null) {
|
||||
this.logger.debug(`Policy ${policy.id} is missing connector_id, skipping`);
|
||||
continue;
|
||||
this.logger.debug(`Policy ${policy.id} is missing connector_id`);
|
||||
// No need to skip, that's fine
|
||||
}
|
||||
|
||||
if (input.compiled_input.connector_name == null) {
|
||||
|
@ -265,7 +265,11 @@ export const getConnectorsToDeploy = (
|
|||
|
||||
// If no package policies reference this connector by id then it should be deployed
|
||||
if (
|
||||
packagePolicies.every((packagePolicy) => packagePolicy.connector_settings.id !== connector.id)
|
||||
packagePolicies.every(
|
||||
(packagePolicy) =>
|
||||
connector.id !== packagePolicy.connector_settings.id &&
|
||||
connector.id !== packagePolicy.package_policy_id
|
||||
)
|
||||
) {
|
||||
results.push(connector);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue