Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] [Elastic AI Assistant] Adds internal Get Evaluate API and migrates Post Evaluate API to OAS #176025

Merged
merged 16 commits into from
Feb 1, 2024

Conversation

spong
Copy link
Member

@spong spong commented Jan 31, 2024

Important

This PR is a reintroduction of #175338, which was reverted due to sporadic jest failures within the security_solution plugin. Root cause was identified and detailed in #176005 (comment).

Summary

In #174317 we added support for OpenAPI codegen, this PR builds on that functionality by migrating the Post Evaluate route /internal/elastic_assistant/evaluate to be backed by an OAS, and adds a basic Get Evaluate route for rounding out the enhancements outlined in https://github.com/elastic/security-team/issues/8167 (to be in a subsequent PR).

Changes include:

  • Migration of Post Evaluate route to OAS
  • Migration of Post Evaluate route to use versioned router
  • Extracted evaluate API calls from x-pack/packages/kbn-elastic-assistant/impl/assistant/api/api.tsx to x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx
    • Co-located relevant use_perform_evaluation hook
  • Adds Get Evaluate route, and corresponding use_evaluation_data hook. Currently only returns agentExecutors to be selected for evaluation.
  • API versioning constants added to x-pack/packages/kbn-elastic-assistant-common/impl/schemas/index.ts
  • Adds new buildRouteValidationWithZod function to x-pack/plugins/elastic_assistant/server/schemas/common.ts for validating routes against OAS generated zod schemas.

Checklist

Delete any items that are not applicable to this PR.

@spong spong added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Security Assistant Security Assistant v8.13.0 labels Jan 31, 2024
@spong spong requested a review from stephmilovic January 31, 2024 22:28
@spong spong self-assigned this Jan 31, 2024
@spong spong requested a review from a team as a code owner January 31, 2024 22:28
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@spong spong requested a review from a team as a code owner January 31, 2024 22:36
@@ -22,7 +22,6 @@ window.HTMLElement.prototype.scrollIntoView = jest.fn();
export const MockAssistantProviderComponent: React.FC<Props> = ({ children }) => {
const actionTypeRegistry = actionTypeRegistryMock.create();
const mockHttp = httpServiceMock.createStartContract({ basePath: '/test' });
mockHttp.get.mockResolvedValue([]);
Copy link
Member Author

@spong spong Jan 31, 2024

Choose a reason for hiding this comment

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

This was the mock causing the 'async issue' which resulted in the revert discussed in #176005 (comment). Removing the mock to see what tests fail, and then will update the mocks accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

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

And there's a 🟢 build with this mock removed. 🎉 Guess it wasn't needed? 😅 Let's verify and re-run the flakey test runner on the security solution tests.

Committed flakey-test runner changes (from #176005) in ef5b297 to ensure there really isn't an error on the security solution side. Will remove once test cycle is complete.

Copy link
Member Author

@spong spong Feb 1, 2024

Choose a reason for hiding this comment

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

🟢 25/25, and that's a success! Here's the build link. Flakey-test runner changes reverted in c2fc97b. This is ready for re-review @stephmilovic.

cc @jbudz

Copy link
Member Author

@spong spong Feb 1, 2024

Choose a reason for hiding this comment

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

Upon further testing locally, I was able to isolate the issue to this test here:

describe('rendering in alerts context', () => {
detectionAlertsTables.forEach((tableId) => {
test(`defaults to the 'Alert events' option when rendering in Alerts`, async () => {
const wrapper = mount(
<TestProviders store={store}>
<StatefulTopN
{...{
...testProps,
scopeId: tableId,
}}
/>
</TestProviders>
);
await waitFor(() => {
const props = wrapper.find('[data-test-subj="top-n"]').first().props() as Props;
expect(props.defaultView).toEqual('alert');
});
});
});
});

Fix to this test is provided in: 0b4028c

@spong spong mentioned this pull request Jan 31, 2024
@spong spong requested a review from a team as a code owner February 1, 2024 00:01
@jbudz jbudz removed the request for review from a team February 1, 2024 00:59
@spong spong requested a review from a team as a code owner February 1, 2024 04:01
@@ -372,6 +372,7 @@ describe('StatefulTopN', () => {
const props = wrapper.find('[data-test-subj="top-n"]').first().props() as Props;
expect(props.defaultView).toEqual('alert');
});
wrapper.unmount();
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI @elastic/security-threat-hunting-explore, this test here was a ⏲️ 💣 waiting for just the right conditions to 💥. I just so happened to stumble upon those conditions with this PR here: #175338 (comment)

Will run the flakey-test runner again with this change to make sure everything is 👍 .

Copy link
Member Author

Choose a reason for hiding this comment

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

Flakey Test runner added in cebd519

Tests results: 🟢 25/25, build link 🎉

Flakey test runner reverted in d44e4af

Copy link
Contributor

@stephmilovic stephmilovic left a comment

Choose a reason for hiding this comment

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

LGTM, sorry jest was mean to you!

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Investigations - Security Solution Cypress Tests #6 / Basic esql search and filter operations "before each" hook for "should remove the query when the back button is pressed after adding a query" "before each" hook for "should remove the query when the back button is pressed after adding a query"

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 4940 4945 +5

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
@kbn/elastic-assistant-common 32 57 +25

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 11.4MB 11.4MB +3.0KB
Unknown metric groups

API count

id before after diff
@kbn/elastic-assistant-common 34 59 +25

History

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

cc @spong

@spong spong merged commit 859e440 into elastic:main Feb 1, 2024
38 checks passed
@spong spong deleted the eval+++ branch February 1, 2024 17:37
fkanout pushed a commit to fkanout/kibana that referenced this pull request Feb 7, 2024
… API and migrates Post Evaluate API to OAS (elastic#176025)

> [!IMPORTANT]
> This PR is a reintroduction of
elastic#175338, which was
[reverted](elastic#175338 (comment))
due to sporadic jest failures within the `security_solution` plugin.
Root cause was identified and detailed in
elastic#176005 (comment).


## Summary

In elastic#174317 we added support for
OpenAPI codegen, this PR builds on that functionality by migrating the
`Post Evaluate` route `/internal/elastic_assistant/evaluate` to be
backed by an OAS, and adds a basic `Get Evaluate` route for rounding out
the enhancements outlined in
elastic/security-team#8167 (to be in a
subsequent PR).

Changes include:
* Migration of `Post Evaluate` route to OAS
* Migration of `Post Evaluate` route to use versioned router
* Extracted `evaluate` API calls from
`x-pack/packages/kbn-elastic-assistant/impl/assistant/api/api.tsx` to
`x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx`
  * Co-located relevant `use_perform_evaluation` hook  
* Adds `Get Evaluate` route, and corresponding `use_evaluation_data`
hook. Currently only returns `agentExecutors` to be selected for
evaluation.
* API versioning constants added to
`x-pack/packages/kbn-elastic-assistant-common/impl/schemas/index.ts`
* Adds new `buildRouteValidationWithZod` function to
`x-pack/plugins/elastic_assistant/server/schemas/common.ts` for
validating routes against OAS generated zod schemas.




### Checklist

Delete any items that are not applicable to this PR.

- [X] 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/packages/kbn-i18n/README.md)
- [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

---------

Co-authored-by: kibanamachine <[email protected]>
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
… API and migrates Post Evaluate API to OAS (elastic#176025)

> [!IMPORTANT]
> This PR is a reintroduction of
elastic#175338, which was
[reverted](elastic#175338 (comment))
due to sporadic jest failures within the `security_solution` plugin.
Root cause was identified and detailed in
elastic#176005 (comment).


## Summary

In elastic#174317 we added support for
OpenAPI codegen, this PR builds on that functionality by migrating the
`Post Evaluate` route `/internal/elastic_assistant/evaluate` to be
backed by an OAS, and adds a basic `Get Evaluate` route for rounding out
the enhancements outlined in
elastic/security-team#8167 (to be in a
subsequent PR).

Changes include:
* Migration of `Post Evaluate` route to OAS
* Migration of `Post Evaluate` route to use versioned router
* Extracted `evaluate` API calls from
`x-pack/packages/kbn-elastic-assistant/impl/assistant/api/api.tsx` to
`x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx`
  * Co-located relevant `use_perform_evaluation` hook  
* Adds `Get Evaluate` route, and corresponding `use_evaluation_data`
hook. Currently only returns `agentExecutors` to be selected for
evaluation.
* API versioning constants added to
`x-pack/packages/kbn-elastic-assistant-common/impl/schemas/index.ts`
* Adds new `buildRouteValidationWithZod` function to
`x-pack/plugins/elastic_assistant/server/schemas/common.ts` for
validating routes against OAS generated zod schemas.




### Checklist

Delete any items that are not applicable to this PR.

- [X] 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/packages/kbn-i18n/README.md)
- [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

---------

Co-authored-by: kibanamachine <[email protected]>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
… API and migrates Post Evaluate API to OAS (elastic#176025)

> [!IMPORTANT]
> This PR is a reintroduction of
elastic#175338, which was
[reverted](elastic#175338 (comment))
due to sporadic jest failures within the `security_solution` plugin.
Root cause was identified and detailed in
elastic#176005 (comment).


## Summary

In elastic#174317 we added support for
OpenAPI codegen, this PR builds on that functionality by migrating the
`Post Evaluate` route `/internal/elastic_assistant/evaluate` to be
backed by an OAS, and adds a basic `Get Evaluate` route for rounding out
the enhancements outlined in
elastic/security-team#8167 (to be in a
subsequent PR).

Changes include:
* Migration of `Post Evaluate` route to OAS
* Migration of `Post Evaluate` route to use versioned router
* Extracted `evaluate` API calls from
`x-pack/packages/kbn-elastic-assistant/impl/assistant/api/api.tsx` to
`x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx`
  * Co-located relevant `use_perform_evaluation` hook  
* Adds `Get Evaluate` route, and corresponding `use_evaluation_data`
hook. Currently only returns `agentExecutors` to be selected for
evaluation.
* API versioning constants added to
`x-pack/packages/kbn-elastic-assistant-common/impl/schemas/index.ts`
* Adds new `buildRouteValidationWithZod` function to
`x-pack/plugins/elastic_assistant/server/schemas/common.ts` for
validating routes against OAS generated zod schemas.




### Checklist

Delete any items that are not applicable to this PR.

- [X] 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/packages/kbn-i18n/README.md)
- [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

---------

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Security Assistant Security Assistant release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants