Skip to content

Conversation

@CohenIdo
Copy link
Contributor

@CohenIdo CohenIdo commented Mar 29, 2022

Add a new call-back type that will be executed after the package policy is created.

@CohenIdo CohenIdo linked an issue Mar 29, 2022 that may be closed by this pull request
@joshdover
Copy link
Contributor

I'm curious if we could instead move the current callback to be executed after the package policy is created rather than before. It's current name even indicates it would be executed after: PostPackagePolicyCreateCallback.

@paul-tavares It looks like you added these back in #69428, do you remember why the hook is called before the package policy is created?

@paul-tavares
Copy link
Contributor

@joshdover ,

Re:

I'm curious if we could instead move the current callback to be executed after the package policy is created rather than before. It's current name even indicates it would be executed after: PostPackagePolicyCreateCallback.

So the name is certainly confusing - the Post* word refers to the HTTP verb for the API operation.

For Endpoint, we do need an extension point before the package policy is saved. Thats because we need to retrieve the latest endpoint artifact manifest in order to include it in the package policy being created.

@joshdover
Copy link
Contributor

Thanks, Paul. Makes sense.

Ido, I think it makes sense to proceed with this PR. Maybe we should change some of the naming and not use the word post anywhere to make this more clear.

@paul-tavares
Copy link
Contributor

yeah, renaming would be good. names like PreCreate* and PostCreate* make more sense and are clearer in understanding when they are executed

@CohenIdo
Copy link
Contributor Author

Hey @joshdover and @paul-tavares - thanks for your comments, I will take them into account while working on it.

@CohenIdo CohenIdo force-pushed the addPostCreatePackageCBHook branch from 079da5d to a4a6033 Compare April 4, 2022 15:34
@CohenIdo CohenIdo marked this pull request as ready for review April 4, 2022 16:12
@CohenIdo CohenIdo requested a review from a team as a code owner April 4, 2022 16:12
@CohenIdo CohenIdo changed the title draft PR for adding post create package callback Adding post create package callback Apr 4, 2022
@CohenIdo
Copy link
Contributor Author

CohenIdo commented Apr 4, 2022

Hey @joshdover, @paul-tavares - updating that I added the new callback type packagePolicyPostCreate with the relevant tests.

For now, I leave the naming of the existing callback packagePolicyCreate as is.
I think it's better to manage this change in a different PR.

One known gap: I still didn't solve typescript issue that can be found also in the CI output

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Calling this in the handler means this will not work for preconfigured package policies, we already have the bug for other callbacks so it should probably not be addressed here #129383

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great callout, agreed it'd be ok to defer on this and fix it for all callbacks in the same PR. That way they're all at least consistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 because the extension points are executed from the PackagePolicy service, I'm assuming the fix to the mentioned issue is to call the service method (runExternalCallbacks()) from the location where the preconfigured packages policies are added/updated while still leaving this code here in place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea would be to have packagePolicyService.create call runExternalCallbacks before returning the newly created policy to the caller. That way there is only a single call site that always runs regardless of how the package policy was created.

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Apr 4, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

Copy link
Contributor

@kfirpeled kfirpeled left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, fills our requirement: having integration's assets available on post-create callback

@kfirpeled kfirpeled added backport:skip This PR does not require backporting v8.3.0 release_note:skip Skip the PR/issue when compiling release notes labels Apr 5, 2022
Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for including me on this. The changes look good to me 👍 , but I defer approval to the fleet team on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 because the extension points are executed from the PackagePolicy service, I'm assuming the fix to the mentioned issue is to call the service method (runExternalCallbacks()) from the location where the preconfigured packages policies are added/updated while still leaving this code here in place.

@CohenIdo CohenIdo force-pushed the addPostCreatePackageCBHook branch from a4a6033 to c637bc6 Compare April 11, 2022 10:35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea would be to have packagePolicyService.create call runExternalCallbacks before returning the newly created policy to the caller. That way there is only a single call site that always runs regardless of how the package policy was created.

@CohenIdo CohenIdo force-pushed the addPostCreatePackageCBHook branch from 56bff9b to 11ac705 Compare April 11, 2022 13:10
...PackagePolicyInputsSchema,
compiled_input: schema.maybe(schema.any()),
})
),
Copy link
Contributor Author

@CohenIdo CohenIdo Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @joshdover, I re-request your review according to this change, I tried to use this scheme for validation and found that is not aligned with the PackagePolicy type.

export interface PackagePolicy extends Omit<NewPackagePolicy, 'inputs'> {
  id: string;
  inputs: PackagePolicyInput[];
  version?: string;
  revision: number;
  updated_at: string;
  updated_by: string;
  created_at: string;
  created_by: string;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping, this change makes sense. At first I thought that maybe the elasticsearch key should be duplicated / moved to CreatePackagePolicyProps as well but that would allow setting it on the API which we explicitly do not support. Everything else LGTM, thanks @CohenIdo

In the future, we may want to try refactoring this to derive the TS types from the config schema using the TypeOf helper from kbn/config-schema.

@CohenIdo CohenIdo requested a review from joshdover April 12, 2022 14:06
@CohenIdo
Copy link
Contributor Author

Thanks for including me on this. The changes look good to me 👍 , but I defer approval to the fleet team on this.

@paul-tavares, @joshdover already approved, (I re-request his review again according to one more change), please have a look:)

...PackagePolicyInputsSchema,
compiled_input: schema.maybe(schema.any()),
})
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping, this change makes sense. At first I thought that maybe the elasticsearch key should be duplicated / moved to CreatePackagePolicyProps as well but that would allow setting it on the API which we explicitly do not support. Everything else LGTM, thanks @CohenIdo

In the future, we may want to try refactoring this to derive the TS types from the config schema using the TypeOf helper from kbn/config-schema.

@CohenIdo CohenIdo enabled auto-merge (squash) April 13, 2022 10:22
@CohenIdo CohenIdo force-pushed the addPostCreatePackageCBHook branch from a03e724 to c213090 Compare April 13, 2022 10:24
@CohenIdo CohenIdo merged commit dbb6b1a into elastic:main Apr 13, 2022
@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
fleet 1263 1267 +4

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
fleet 9 10 +1
Unknown metric groups

API count

id before after diff
fleet 1380 1384 +4

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding callback post create package

7 participants