Skip to content

Commit

Permalink
Gradle Check AUTO issue create
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Jun 11, 2024
1 parent 225bdd4 commit b8462b4
Show file tree
Hide file tree
Showing 15 changed files with 1,089 additions and 22 deletions.
26 changes: 14 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
testImplementation group: 'org.yaml', name: 'snakeyaml', version: '2.0'
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
testImplementation group: 'com.lesfurets', name:'jenkins-pipeline-unit', version: '1.13'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.12.0'
}

configurations.all {
Expand All @@ -40,13 +41,13 @@ configurations.all {
sourceSets {
main {
groovy {
srcDirs = ['src/jenkins']
srcDirs = ['src/jenkins', 'src/gradlecheck']
}
}

test {
groovy {
srcDirs = ['tests/jenkins']
srcDirs = ['tests/jenkins', 'tests/gradlecheck']
}
}

Expand Down Expand Up @@ -80,8 +81,8 @@ sharedLibrary {

test {
testLogging {
events "failed"
exceptionFormat "full"
events "failed"
exceptionFormat "full"
}
if (project.hasProperty('pipeline.stack.write')) {
systemProperty 'pipeline.stack.write', project.getProperty('pipeline.stack.write')
Expand All @@ -105,14 +106,15 @@ jacocoTestReport {

afterEvaluate {
classDirectories.from = fileTree(
dir: "$buildDir/jacoco/classpathdumps",
includes: [
'**/*_Jenkinsfile.*',
'**/jenkins/*'
],
excludes: [
'**/*\$_get_closure*'
]
dir: "$buildDir/jacoco/classpathdumps",
includes: [
'**/*_Jenkinsfile.*',
'**/jenkins/*',
'**/gradlecheck/*'
],
excludes: [
'**/*\$_get_closure*'
]
)
}

Expand Down
41 changes: 41 additions & 0 deletions src/gradlecheck/CreateMarkDownTable.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gradlecheck

class CreateMarkDownTable {
String failedTest
ArrayList<String> tableData
ArrayList<String> additionalPullRequests

CreateMarkDownTable(String failedTest, List<Map<String, Object>> tableData, List<String> additionalPullRequests) {
this.failedTest = failedTest
this.tableData = tableData
this.additionalPullRequests = additionalPullRequests
}

def createMarkdownTable() {

def tableHeader = """
## Flaky Test Report for `${this.failedTest}`
Noticed the `${this.failedTest}` has some flaky, failing tests that failed during **post-merge actions**.
### Details
| Git Reference | Merged Pull Request | Build Details | Test Name |
|---------------|----------------------|---------------|-----------|
"""
def tableRows = this.tableData.collect { row ->
"| ${row.gitReference} | ${row.pullRequestLink} | ${row.buildDetailLink} | ${row.testNames.join('<br><br>')} |"
}.join("\n")

def additionalPRSection = """
\nThe other pull requests, besides those involved in post-merge actions, that contain failing tests with the `${this.failedTest}` class are:
${this.additionalPullRequests.collect { pr -> "- [${pr}](https://github.com/opensearch-project/OpenSearch/pull/${pr})" }.join('\n')}
For more details on the failed tests refer to [OpenSearch Gradle Check Metrics](https://metrics.opensearch.org/_dashboards/app/dashboards#/view/e5e64d40-ed31-11ee-be99-69d1dbc75083) dashboard.
"""

return tableHeader + tableRows + additionalPRSection
}

}
5 changes: 5 additions & 0 deletions src/gradlecheck/FetchMetrics.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gradlecheck

interface FetchMetrics {
def fetchMetrics(String escapedQuery)
}
62 changes: 62 additions & 0 deletions src/gradlecheck/FetchPostMergeFailedTestClass.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package gradlecheck

import groovy.json.JsonOutput

class FetchPostMergeFailedTestClass extends OpenSearchMetricsQuery {

FetchPostMergeFailedTestClass(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, def script) {
super(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, script)
}

def getQuery() {
def queryMap = [
size: 200,
query: [
bool: [
must: [
[
match: [
"invoke_type.keyword": [
query: "Post Merge Action",
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
],
[
match: [
test_status: [
query: "FAILED",
operator: "OR"
]
]
]
]
]
],
aggregations: [
test_class_keyword_agg: [
terms: [
field: "test_class",
size: 1
]
]
]
]

def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}

def getPostMergeFailedTestClass() {
def jsonResponse = fetchMetrics(getQuery())
def keys = jsonResponse.aggregations.test_class_keyword_agg.buckets.collect { it.key }
return keys
}
}
112 changes: 112 additions & 0 deletions src/gradlecheck/FetchPostMergeFailedTestName.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

package gradlecheck

import groovy.json.JsonOutput

class FetchPostMergeFailedTestName extends OpenSearchMetricsQuery {

FetchPostMergeFailedTestName(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, def script) {
super(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, script)
}

def getQuery(testName, gitReference) {
def queryMap = [
size: 200,
query: [
bool: [
must: [
[
match: [
"invoke_type.keyword": [
query: "Post Merge Action",
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
],
[
match: [
test_status: [
query: "FAILED",
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
],
[
match: [
test_class: [
query: testName,
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
],
[
match: [
"git_reference.keyword": [
query: gitReference,
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
]
],
adjust_pure_negative: true,
boost: 1
]
],
aggregations: [
test_name_keyword_agg: [
terms: [
field: "test_name",
size: 500
]
],
build_number_agg: [
terms: [
field: "build_number",
size: 500
]
],
pull_request_agg: [
terms: [
field: "pull_request",
size: 500
]
]
]
]

def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')

}
def getPostMergeFailedTestName(testName, gitReference) {
return fetchMetrics(getQuery(testName, gitReference))
}
}
86 changes: 86 additions & 0 deletions src/gradlecheck/FetchPostMergeTestGitReference.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package gradlecheck

import groovy.json.JsonOutput

class FetchPostMergeTestGitReference extends OpenSearchMetricsQuery {

FetchPostMergeTestGitReference(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, def script) {
super(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, script)
}

def getQuery(testName) {
def queryMap = [
size: 200,
query: [
bool: [
must: [
[
match: [
"invoke_type.keyword": [
query: "Post Merge Action",
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
],
[
match: [
test_status: [
query: "FAILED",
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
],
[
match: [
test_class: [
query: testName,
operator: "OR",
prefix_length: 0,
max_expansions: 50,
fuzzy_transpositions: true,
lenient: false,
zero_terms_query: "NONE",
auto_generate_synonyms_phrase_query: true,
boost: 1
]
]
]
],
adjust_pure_negative: true,
boost: 1
]
],
aggregations: [
git_reference_keyword_agg: [
terms: [
field: "git_reference.keyword",
size: 500
]
]
]
]

def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}

def getPostMergeTestGitReference(testName) {
def jsonResponse = fetchMetrics(getQuery(testName))
def keys = jsonResponse.aggregations.git_reference_keyword_agg.buckets.collect { it.key }
return keys
}
}
Loading

0 comments on commit b8462b4

Please sign in to comment.