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

[Fleet] cypress setup #113106

Merged
merged 71 commits into from
Nov 2, 2021
Merged

[Fleet] cypress setup #113106

merged 71 commits into from
Nov 2, 2021

Conversation

juliaElastic
Copy link
Contributor

@juliaElastic juliaElastic commented Sep 27, 2021

Summary

Cypress setup for Fleet. ON week work.

Setup for Fleet Server and Agent is from Bryan Clement's pr here: #108759

To run locally:

cd x-pack/plugins/fleet
yarn cypress:open-as-ci

Make sure to stop any agent instances before starting, otherwise you might get this grpc port conflict: elastic/beats#28118

image

Added cypress to ci run:
https://github.com/elastic/kibana/pull/113106/checks?check_run_id=3744593878
image

Cypress major upgrade just happened with this: #104301

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@juliaElastic
Copy link
Contributor Author

juliaElastic commented Sep 29, 2021

@elasticmachine merge upstream

@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

@juliaElastic
Copy link
Contributor Author

juliaElastic commented Oct 4, 2021

@joshdover @jen-huang this is the draft pr that I've done during ON week to add cypress setup to Fleet, do we want to merge it or wait until it is presented to the team?

The caveat is that this task adds 2 minutes to build time, I don't know yet if these test tasks are parallelised on CI.
Mostly the API calls take that long, that is why it is recommended to use stubbed network requests for most cases.
image

@joshdover
Copy link
Contributor

If no one on the team is opposed to moving forward with Cypress, I'm +1 on moving this into review.

@juliaElastic
Copy link
Contributor Author

juliaElastic commented Oct 4, 2021

@elasticmachine merge upstream

@juliaElastic juliaElastic marked this pull request as ready for review October 4, 2021 12:54
@juliaElastic juliaElastic requested review from a team as code owners October 4, 2021 12:54
navigateTo(INTEGRATIONS);
cy.get(INTEGRATIONS_CARD).contains(integration).click();
addIntegration();
cy.get(INTEGRATION_NAME_LINK).contains('apache-');
}

it('[Mocked requests] should display Apache integration in the Policies list once installed ', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test is the duplication of the one above, but with mocked requests to showcase network stubbing.
Pros: quicker test, isolation of UI testing
Cons: lot of extra setup needed (fixture files, intercept each api call)
I think for critical testcases real e2e test would be better, mocked requests are useful when the goal is to test complex UI logic without relying on real backend.
See https://docs.cypress.io/guides/guides/network-requests

Copy link
Member

Choose a reason for hiding this comment

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

I think real request will make sense here. But maybe we should do the same things as we do with our API integration tests where we have a docker package registry locally otherwise I think we can have some flakiness here. (This should be done in a following PR already a lot of good stuff here)

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

Pinging @elastic/fleet (Team:Fleet)

'--env',
'FLEET_SERVER_ENABLE=true',
'--env',
`FLEET_SERVER_ELASTICSEARCH_HOST=http://host.docker.internal:${this.esConfig.port}`,
Copy link
Contributor Author

@juliaElastic juliaElastic Oct 28, 2021

Choose a reason for hiding this comment

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

this was working locally, though it is not on CI, trying to figure out why, not able to connect to ES

2021-10-28T17:56:55.723Z	INFO	cmd/enroll_cmd.go:760	Fleet Server - Starting
--
  | 2021-10-28T17:56:56.527Z	ERROR	status/reporter.go:236	Elastic Agent status changed to: 'error'
  | 2021-10-28T17:56:56.528Z	ERROR	log/reporter.go:36	2021-10-28T17:56:56Z - message: Application: fleet-server--8.0.0-SNAPSHOT[]: State changed to FAILED: Error - dial tcp 172.17.0.1:6102: connect: connection refused - type: 'ERROR' - sub_type: 'FAILED'
  | 2021-10-28T17:56:57.726Z	INFO	cmd/enroll_cmd.go:760	Fleet Server - Error - dial tcp 172.17.0.1:6102: connect: connection refused


@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

// define custom es server here
// API Keys is enabled at the top level
'xpack.security.enabled=true',
'http.host=0.0.0.0',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

finally, fleet_server with docker works by adding http.host to make es accessible from the docker container

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

This is great, tested locally and was able to follow the flow of how things are linked together pretty well. I see no reason to hold on merging this and iterating as we go. Thank you for doing this, it's going to be very helpful for us going forward.

elastic-agent-*
fleet-server-*
elastic-agent.yml
fleet-server.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new line

// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we make this a ts file?

Comment on lines 49 to 60
// this.log.info('Updating the default agent output');
// const {
// data: {
// items: [defaultOutput],
// },
// } = await axios.get(this.params.kibanaUrl + '/api/fleet/outputs', this.requestOptions);

// await axios.put(
// `${this.params.kibanaUrl}/api/fleet/outputs/${defaultOutput.id}`,
// { hosts: [this.params.esHost] },
// this.requestOptions
// );
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove

Comment on lines 26 to 29
module.exports = (_on, _config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
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 make this a ts file?

@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
fleet 615.3KB 615.5KB +177.0B

History

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

@juliaElastic juliaElastic merged commit 157a371 into elastic:main Nov 2, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Nov 2, 2021
* added cypress setup for fleet

* updated readme

* fixed types

* fix unused

* starting up fleet server in cypress

* added more fleet tests

* added package update test

* updated readme

* trying jenkins run

* trying jenkins run

* trying jenkins run

* fix types, cypress config

* example of mocked requests

* added getBySel

* fix test after refactor

* removed duplication

* fix tests

* added to buildkite

* updated tests

* starting agent with docker

* trying to fix ip address

* ifconfig

* ip address

* ip address

* ip address

* type fix

* remove extra logging

* fixed test

* fix buildkite

* cleanup

* cleanup

* using docker for fleet_server

* fix

* fix

* trying to fix

* update config

* test

* test

* test

* test

* revert changes

* test

* test

* static ip on linux

* docker version

* try again

* fixed review comments

* fixed types

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Patryk Kopycinski <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
8.0

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Nov 2, 2021
* [Fleet] cypress setup (#113106)

* added cypress setup for fleet

* updated readme

* fixed types

* fix unused

* starting up fleet server in cypress

* added more fleet tests

* added package update test

* updated readme

* trying jenkins run

* trying jenkins run

* trying jenkins run

* fix types, cypress config

* example of mocked requests

* added getBySel

* fix test after refactor

* removed duplication

* fix tests

* added to buildkite

* updated tests

* starting agent with docker

* trying to fix ip address

* ifconfig

* ip address

* ip address

* ip address

* type fix

* remove extra logging

* fixed test

* fix buildkite

* cleanup

* cleanup

* using docker for fleet_server

* fix

* fix

* trying to fix

* update config

* test

* test

* test

* test

* revert changes

* test

* test

* static ip on linux

* docker version

* try again

* fixed review comments

* fixed types

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Patryk Kopycinski <[email protected]>

* using 8.0.0 docker image for backport

Co-authored-by: Julia Bardi <[email protected]>
Co-authored-by: Patryk Kopycinski <[email protected]>
Co-authored-by: Julia Bardi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed buildkite-ci release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants