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: getGitMatchingGroup step #535

Merged
merged 10 commits into from
May 18, 2020
Merged

Conversation

v1v
Copy link
Member

@v1v v1v commented May 14, 2020

What does this PR do?

Given the changeset and a regex pattern with group let's see if all the files in the changeset got in common the regex and gather the group match

For instance:

Given the changeset for the PR elastic/beats#17043
Then the module should be zookeeper
with the pattern 'metricbeat\\/module\\/([^\\/]+)\\/.*'
and exclude pattern (.*\\/docs|.*\\.asciidoc)

CHANGELOG.next.asciidoc
metricbeat/docs/modules/zookeeper.asciidoc
metricbeat/docs/modules/zookeeper/connection.asciidoc
metricbeat/docs/modules_list.asciidoc
metricbeat/module/zookeeper/_meta/docs.asciidoc
metricbeat/module/zookeeper/connection/_meta/docs.asciidoc
metricbeat/module/zookeeper/connection/_meta/fields.yml
metricbeat/module/zookeeper/connection/connection.go
metricbeat/module/zookeeper/fields.go
metricbeat/module/zookeeper/mntr/_meta/docs.asciidoc
metricbeat/module/zookeeper/server/_meta/docs.asciidoc

Why is it important?

isGitRegionMatch returns a boolean, so we need soemthing more specific to look for groups in the given regex. Then the pipelines could use it in favor of filtering what stages should or should not run.

Related issues

Caused by https://github.com/elastic/observability-robots/issues/113

Actions

image

@v1v v1v self-assigned this May 14, 2020
@v1v v1v added the automation label May 14, 2020
@botelastic botelastic bot added the groovy label May 14, 2020
@apmmachine
Copy link
Contributor

apmmachine commented May 14, 2020

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

Test stats 🧪

Test Results
Failed 0
Passed 540
Skipped 11
Total 551

@v1v v1v changed the title wip ci: getRegionFromPattern step ci: getBeatsModule step May 15, 2020
@botelastic botelastic bot added the master label May 15, 2020
@v1v v1v added the enhancement New feature or request label May 15, 2020
@v1v v1v marked this pull request as ready for review May 15, 2020 17:15
@v1v v1v requested review from a team and ycombinator May 15, 2020 17:15
Comment on lines 50 to 51
from: 'b0de59d0ec1e2ae52103a238a2e9cb5b0d7fd9b8',
to: '641fd600836abafa51def05260d63fab6eed4707',
Copy link
Member Author

Choose a reason for hiding this comment

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

Changeset from #524

Comment on lines 22 to 23
from: '347185bd7e2b402ba8f6befa5ef4428ad417fbbc',
to: '4d9fc25d258622c767ec4d38df38520647cc7dda')
Copy link
Member Author

Choose a reason for hiding this comment

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

ChangeSet from #516

Comment on lines 27 to 37
def realData = '''CHANGELOG.next.asciidoc
metricbeat/docs/modules/zookeeper.asciidoc
metricbeat/docs/modules/zookeeper/connection.asciidoc
metricbeat/docs/modules_list.asciidoc
metricbeat/module/zookeeper/_meta/docs.asciidoc
metricbeat/module/zookeeper/connection/_meta/docs.asciidoc
metricbeat/module/zookeeper/connection/_meta/fields.yml
metricbeat/module/zookeeper/connection/connection.go
metricbeat/module/zookeeper/fields.go
metricbeat/module/zookeeper/mntr/_meta/docs.asciidoc
metricbeat/module/zookeeper/server/_meta/docs.asciidoc'''.stripMargin().stripIndent()
Copy link
Member Author

Choose a reason for hiding this comment

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

Changeset from elastic/beats#17043

@@ -0,0 +1,80 @@
// Licensed to Elasticsearch B.V. under one or more contributor
Copy link
Member Author

Choose a reason for hiding this comment

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

Question:

  • I think this step can be called something more generic, but I don't have any sensitive naming off the top of my head, any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did not see this comment :D #535 (comment)

@kuisathaverat
Copy link
Contributor

I am afraid the number of calls to isGitRegionMatch will be the same, but this will help a lot to decrease the time to build on beats that support MODULE.

Comment on lines 120 to 129
void test_multiple_without_match() throws Exception {
def script = loadScript(scriptName)
def changeset = '''foo/bar/file.txt
bar/foo/subfolder'''.stripMargin().stripIndent()
helper.registerAllowedMethod('readFile', [String.class], { return changeset })
def module = script.call(pattern: '([^\\/]+)\\/.*')
assertEquals('', module)
assertTrue(assertMethodCallContainsPattern('log', 'getBeatsModule: not found'))
assertJobStatusSuccess()
}
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 regexp return 2 matches

Copy link
Member Author

Choose a reason for hiding this comment

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

as long as they don't have a folder name in common there is no match.

def module = script.call(pattern: '([^\\/]+)\\/.*', from: 'something')
printCallStack()
assertEquals('foo', module)
assertTrue(assertMethodCallContainsPattern('sh', 'something...bar'))
Copy link
Contributor

Choose a reason for hiding this comment

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

bar confused me until I realized that it is GIT_BASE_COMIT

- When exact match then all the files should match those patterns then it
returns the region otherwise and empty string.

def module = getBeatsModule(pattern: '([^\\/]+)\\/.*')
Copy link
Contributor

Choose a reason for hiding this comment

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

the step really searches for a pattern in the git diff and return the match group, what about to rename it to getGitDiffMatch or similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

getGitMatchingGroup?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done -> 02bb896

if (!isExcluded(line, exclude)) {
def matches = line =~ pattern
def auxModule = matches.collect { it[1] }[0] ?: ''
modules[auxModule] = auxModule

Choose a reason for hiding this comment

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

I'm not a regular groovy developer so I may be off here, but shouldn't we only execute this line if auxModule != ''?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's indeed a good point, I initially coded with d0a1bf6#diff-056e15bb189379e1f510e3402220ddb5R63.

There are three different output in this particular getGroup method:

  • if no matches then returns ''
  • if a match for all the change set then returns module_name
  • if multiple matches then return ''

Therefore '' is a valid output to be returned and that's the reason of no using auxModule != '', in other words:

Given the changeset foo/bar/file.txt
And the pattern ^unknown.txt
the output for getGroup should be ''

For instance, https://github.com/elastic/apm-pipeline-library/pull/535/files#diff-57498ad4c893cd122338bfbdeb7d0aa0R131-R141

Another example that I did not code as an unit test is:

Given the changeset foo/bar/file.txt and bar/foo/file.txt
And the pattern ^unknown.txt
the output for getGroup should be ''

Let me know if what I said it's not clear

Choose a reason for hiding this comment

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

Okay, I see why it's working the way it is implemented now.

@v1v v1v force-pushed the feature/getRegionFromPattern branch from 58eba4a to 02bb896 Compare May 18, 2020 07:02
@v1v v1v changed the title ci: getBeatsModule step ci: getGitMatchingGroup step May 18, 2020
@v1v v1v force-pushed the feature/getRegionFromPattern branch from 02bb896 to 2476123 Compare May 18, 2020 08:08
@v1v v1v merged commit e5de864 into elastic:master May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants