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

[Cloud Security] Metering integration tests #187219

Merged
merged 25 commits into from
Jul 9, 2024
Merged

Conversation

CohenIdo
Copy link
Contributor

@CohenIdo CohenIdo commented Jul 1, 2024

solves:

Using MSW middleware to mock the usage API service and verify that metering records are collected and sent as expected to the usage service from the background metering task.

@CohenIdo CohenIdo marked this pull request as ready for review July 2, 2024 09:10
@CohenIdo CohenIdo requested review from a team as code owners July 2, 2024 09:10
@CohenIdo CohenIdo added release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related labels Jul 2, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

Copy link
Contributor

@maxcold maxcold left a comment

Choose a reason for hiding this comment

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

Need a bit more time for the full review (though don't be blocked if someone else from the team gets to it first)
One question - have you checked the discussion about the MSW usage in #184555 ? Even though these are different test suite, it would be good to have a consistent approach to the MSW usage in our suits across the board

@CohenIdo
Copy link
Contributor Author

CohenIdo commented Jul 2, 2024

One question - have you checked the discussion about the MSW usage in #184555 ? Even though these are different test suite, it would be good to have a consistent approach to the MSW usage in our suits across the board

Yes, those are different use cases, in #184555 it mocks responses and does not create a real server, here, since the task manager is running on another node worker (there is one worker for the test and another for the server) it cannot intercept the requests. That's the reason I used MSW middleware.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Jul 2, 2024

💔 Build Failed

Failed CI Steps

History

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

@CohenIdo CohenIdo requested a review from maxcold July 2, 2024 16:13
return fetch(url, {
method: 'post',
body: JSON.stringify(records),
headers: { 'Content-Type': 'application/json' },
agent,
agent: isHttps ? agent : undefined, // Conditionally add agent if URL is HTTPS for supporting integration tests.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc: @joeypoon

Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious why we used fetch instead of the core HTTP service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the reason is that the agent attribute is not supported in the core fetch. @joeypoon, please correct me if I'm wrong.

@CohenIdo CohenIdo added the ci:project-deploy-security Create a Security Serverless Project label Jul 3, 2024
Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

I have not had the opportunity to develop any large FTRs but this looks clean to me. I'll approve knowing that @maxcold 's concerns about MKI test will be resolved.

return fetch(url, {
method: 'post',
body: JSON.stringify(records),
headers: { 'Content-Type': 'application/json' },
agent,
agent: isHttps ? agent : undefined, // Conditionally add agent if URL is HTTPS for supporting integration tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious why we used fetch instead of the core HTTP service?

) {
const version = '1.2.5';

const { body: postPackageResponse } =
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move parts which are same to own variables ? eg. the object inside send looks pretty much the same in both code branches, probably can be extracted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, done.

@@ -76,7 +76,8 @@ export const getUsageRecords = async (
{
range: {
'event.ingested': {
gt: searchFrom.toISOString(),
// gt: searchFrom.toISOString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather add the tech debt ticket to the comment, than leaving the old code commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I solved it in #186777, so I remove the comment, and will merge the other PR first.

@CohenIdo CohenIdo requested a review from maxcold July 4, 2024 06:55
@elasticmachine
Copy link
Contributor

elasticmachine commented Jul 9, 2024

⏳ Build in-progress

History

@CohenIdo CohenIdo merged commit 7b29dcc into elastic:main Jul 9, 2024
43 checks passed
@kibanamachine kibanamachine added v8.16.0 backport:skip This commit does not require backporting labels Jul 9, 2024
jeramysoucy added a commit that referenced this pull request Sep 18, 2024
## Summary

Assigns ownership of new dev dep `@mswjs/http-middleware` to cloud
security team (`kibana-cloud-security-posture`).

Dependency was addded in #187219
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Sep 24, 2024
## Summary

Assigns ownership of new dev dep `@mswjs/http-middleware` to cloud
security team (`kibana-cloud-security-posture`).

Dependency was addded in elastic#187219

(cherry picked from commit c426b06)
kibanamachine referenced this pull request Sep 24, 2024
# Backport

This will backport the following commits from `main` to `8.x`:
- [Adds @mswjs/http-middleware to renovate.json
(#193257)](#193257)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jeramy
Soucy","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-18T13:44:53Z","message":"Adds
@mswjs/http-middleware to renovate.json (#193257)\n\n##
Summary\r\n\r\nAssigns ownership of new dev dep `@mswjs/http-middleware`
to cloud\r\nsecurity team
(`kibana-cloud-security-posture`).\r\n\r\nDependency was addded in
https://github.com/elastic/kibana/pull/187219","sha":"c426b06aa442935d02cf171da66212ddce5e5ce9","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["chore","Team:Security","release_note:skip","v9.0.0","v8.16.0","backport:version"],"title":"Adds
@mswjs/http-middleware to
renovate.json","number":193257,"url":"https://github.com/elastic/kibana/pull/193257","mergeCommit":{"message":"Adds
@mswjs/http-middleware to renovate.json (#193257)\n\n##
Summary\r\n\r\nAssigns ownership of new dev dep `@mswjs/http-middleware`
to cloud\r\nsecurity team
(`kibana-cloud-security-posture`).\r\n\r\nDependency was addded in
https://github.com/elastic/kibana/pull/187219","sha":"c426b06aa442935d02cf171da66212ddce5e5ce9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193257","number":193257,"mergeCommit":{"message":"Adds
@mswjs/http-middleware to renovate.json (#193257)\n\n##
Summary\r\n\r\nAssigns ownership of new dev dep `@mswjs/http-middleware`
to cloud\r\nsecurity team
(`kibana-cloud-security-posture`).\r\n\r\nDependency was addded in
https://github.com/elastic/kibana/pull/187219","sha":"c426b06aa442935d02cf171da66212ddce5e5ce9"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jeramy Soucy <[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 ci:project-deploy-security Create a Security Serverless Project release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants