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

[CI][lint] Enable x-pack linting when OSS changes #23655

Closed

Conversation

v1v
Copy link
Member

@v1v v1v commented Jan 25, 2021

What does this PR do?

Changes in Beats should trigger builds of their x-pack counterparts

  • It will only run the linting if OSS changes among x-pack.
  • It will exclude any mandatory stages for x-pack if only OSS docs changes.

What beats have been enabled?

  • x-pack/auditbeat
  • x-pack/filebeat
  • x-pack/metricbeat
  • x-pack/packetbeat
  • x-pack/winlogbeat

Why is it important?

#22584 changed the packetbeat but didn't update the x-pack/packbeat. This broke the linting job for x-pack/packetbeat, but was not detected.

Related issues

Similar to #23378 but the other way around.

Further details

Code changeSet discover is delegated to the .ci/scripts/get-vendor-dependencies.sh but for non-code changes this is the proposal.

@v1v v1v requested a review from a team as a code owner January 25, 2021 14:22
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jan 25, 2021
@v1v v1v requested review from jsoriano and a team January 25, 2021 14:22
@v1v v1v added automation ci Team:Automation Label for the Observability productivity team labels Jan 25, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jan 25, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jan 25, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #23655 updated

    • Start Time: 2021-01-26T13:12:33.549+0000
  • Duration: 45 min 53 sec

  • Commit: 510bb05

Test stats 🧪

Test Results
Failed 0
Passed 10199
Skipped 1386
Total 11585

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 10199
Skipped 1386
Total 11585

@@ -33,3 +34,7 @@ stages:
tags: true ## for all the tags
build:
mage: "mage build test"
when: ## Override the top-level when.
not_changeset_full_match: "^libbeat/.*" ## Disable the stage if ONLY changes for the OSS beats
Copy link
Member

Choose a reason for hiding this comment

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

If there are changes in the code of libbeat we should run the tests for x-pack/libbeat. I guess this is done now by @ci or GetProjectDependencies, but will this new condition prevent tests to be run if there are changes only in OSS?

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha! Then this is totally a different behaviour that I though! good catch. The @xpack macro already contain the "^libbeat/.*", therefore we don't need this when

@@ -20,6 +21,10 @@ stages:
make check-no-changes;
unitTest:
mage: "mage build unitTest"
when: ## Override the top-level when.
not_changeset_full_match: "^metricbeat/.*" ## Disable the stage if ONLY changes for the OSS beats
Copy link
Member

Choose a reason for hiding this comment

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

Same here (and with the other beats), will this prevent x-pack metricbeat tests to be run if there were changes in oss metricbeat only?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly, for clarity for the below x-pack/metricbeat CI stages:

  • lint stage (L18) will always run as long as the first when condition is set (see L1)
  • unitTest stage (L22) will run if the changeset does not contain ONLY metricbeat changes or it's a build in any branch/tag

not_changeset_full_match is a negative condition, exactly the opposite of what the majority of the other when conditions.

Copy link
Member

Choose a reason for hiding this comment

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

But we want x-pack tests to be run if there are changes in some dependency in OSS (as detected by GetProjectDependencies).

e.g. if we change only something in metricbeat/mb, we want to run x-pack metricbeat tests as it can be affected.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm gonna double check the expected behaviour works as expected, since I'm not convinced now if this might cause that particular regression :/

Copy link
Member Author

Choose a reason for hiding this comment

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

Since there is no an easy way with the proposal, I finally change a bit the implementation to exclude the x-pack/<beat> stages if there are only <beat>/docs changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

e.g. if we change only something in metricbeat/mb, we want to run x-pack metricbeat tests as it can be affected.

It should we now be covered. I just executed some tests for the not_changeset_full_match when condition locally:

diff --git a/src/test/groovy/BeatsWhenStepTests.groovy b/src/test/groovy/BeatsWhenStepTests.groovy
index 9f53c52..792a3a2 100644
--- a/src/test/groovy/BeatsWhenStepTests.groovy
+++ b/src/test/groovy/BeatsWhenStepTests.groovy
+  @Test
+  void test_xpackmetricbeat_test_when_metricbeat_mb_changes() throws Exception {
+    def script = loadScript(scriptName)
+    def changeset = "metricbeat/mb/my-file.go"
+    helper.registerAllowedMethod('readFile', [String.class], { return changeset })
+    def ret = script.whenNotChangesetFullMatch(content: [ not_changeset_full_match: '^metricbeat/docs/.*'])
+    printCallStack()
+    assertTrue(ret)
+  }
+
$ ./mvnw test -Dtest=BeatsWhenStepTests#test_xpackmetricbeat_test_when_metricbeat_mb_changes
...[INFO] Running BeatsWhenStepTests
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.981 s - in BeatsWhenStepTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

x-pack/libbeat/Jenkinsfile.yml Outdated Show resolved Hide resolved
x-pack/libbeat/Jenkinsfile.yml Outdated Show resolved Hide resolved
v1v and others added 4 commits January 26, 2021 10:22
This is already supported with the `@xpack` macro and in fact, it should always run if libbeat changes
…pack-when-oss-changes

* upstream/master:
  [DOCS] Add setup content to Kubernetes and Cloud Foundry docs (elastic#23580)
  [CI] Mandatory windows support for all the versions (elastic#23615)
  Add check when retrieving the worker process id using performance counters  (elastic#23647)
  Remove 4912 evtx from testing (elastic#23669)
  Add missing SSL settings (elastic#23632)
  Update X-Pack Packetbeat config (elastic#23666)
  Use hostname check from verify.go to handle patterns in TLS certs (elastic#23661)
  Fix: Dissect Cisco ASA 302013 message usernames (elastic#21196)
  Add FAQ entry for MADV settings in older versions (elastic#23429)
  Sync fixes from Integration Package Testing (elastic#23424)
  [Filebeat] Add Cisco ASA message '302023' parsing (elastic#23092)
  [Elastic Log Driver] Change hosts config flag (elastic#23628)
  Audit and Authentication Policy Change Events (elastic#20684)
…1v/beats into feature/linting-xpack-when-oss-changes

* 'feature/linting-xpack-when-oss-changes' of github.com:v1v/beats:
  Apply suggestions from code review
@v1v v1v requested a review from jsoriano January 26, 2021 13:22
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks! It looks ok, but it is starting to get a bit complicated to follow.

when: ## Override the top-level when.
not_changeset_full_match: "^auditbeat/docs/.*" ## Disable the stage if ONLY DOC changes for the OSS beats
branches: true ## for all the branches
tags: true ## for all the tags
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to have this override in build and windows*, but not in arm and macos?

Copy link
Member Author

Choose a reason for hiding this comment

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

A brief explanation:

Top-level when condition is the very first evaluation.

Then, any stages with a when condition will be evaluated again. Therefore when for stages and when for top-level don't work together. The initial approach didn't require anything further.

Is there a reason to have this override in build and windows*, but not in arm and macos?

Mandatory stages with this particular cross-project linting require the when: not_changeset_full_match... while arm and macos are optional stages, so they do need to run on a PR basis unless any of the when conditions.

@@ -2,6 +2,7 @@ when:
branches: true ## for all the branches
changeset: ## when PR contains any of those entries in the changeset
- "^x-pack/auditbeat/.*"
- "^auditbeat/.*" ## when changes in the auditbeat
Copy link
Member

Choose a reason for hiding this comment

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

I guess this cannot be added for linting only, so we don't have to add the negation in all the other builds?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could not find a different approach with the existing declarative syntax :(

Although,I just found something that I wanna give a go in another PR

Copy link
Member Author

Choose a reason for hiding this comment

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

My new proposal -> #23695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation ci Team:Automation Label for the Observability productivity team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants