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

Add qualifier support to metrics queries #611

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/jenkins/ComponentBuildStatus.groovy
Original file line number Diff line number Diff line change
@@ -18,37 +18,40 @@
String awsSecretKey
String awsSessionToken
String indexName
String product
String product
String version
String qualifier
String distributionBuildNumber
String buildStartTimeFrom
String buildStartTimeTo
def script
OpenSearchMetricsQuery openSearchMetricsQuery

ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String distributionBuildNumber, String buildStartTimeFrom, String buildStartTimeTo, def script) {
ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String qualifier, String distributionBuildNumber, String buildStartTimeFrom, String buildStartTimeTo, def script) {
this.metricsUrl = metricsUrl
this.awsAccessKey = awsAccessKey
this.awsSecretKey = awsSecretKey
this.awsSessionToken = awsSessionToken
this.indexName = indexName
this.product = product
this.version = version
this.qualifier = qualifier
this.distributionBuildNumber = distributionBuildNumber
this.buildStartTimeFrom = buildStartTimeFrom
this.buildStartTimeTo = buildStartTimeTo
this.script = script
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
}

ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, def script) {
ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String qualifier, def script) {
this.metricsUrl = metricsUrl
this.awsAccessKey = awsAccessKey
this.awsSecretKey = awsSecretKey
this.awsSessionToken = awsSessionToken
this.indexName = indexName
this.product = product
this.version = version
this.qualifier = qualifier
this.script = script
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
}
@@ -57,7 +60,7 @@
def queryMap = [
_source: [
"component",
],
],
query: [
bool: [
filter: [
@@ -93,6 +96,13 @@
]
]
]
if (!isNullOrEmpty(this.qualifier)) {
queryMap.query.bool.filter.add([
match_phrase: [
qualifier: "${this.qualifier}"
]
])
}
def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}
@@ -102,7 +112,7 @@
size : 1,
_source: [
"distribution_build_number",
],
],
query: [
bool: [
filter: [
@@ -127,6 +137,14 @@
]
]
]

if (!isNullOrEmpty(this.qualifier)) {
queryMap.query.bool.filter.add([

Check warning on line 142 in src/jenkins/ComponentBuildStatus.groovy

Codecov / codecov/patch

src/jenkins/ComponentBuildStatus.groovy#L142

Added line #L142 was not covered by tests
match_phrase: [
qualifier: "${this.qualifier}"
]
])
}
def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}
@@ -142,4 +160,8 @@
def latestDistributionBuildNumber = jsonResponse.hits.hits[0]._source.distribution_build_number
return latestDistributionBuildNumber
}

private boolean isNullOrEmpty(String str) {
return (str == 'Null' || str == null || str.allWhitespace || str.isEmpty()) || str == "None"
}
}
22 changes: 21 additions & 1 deletion src/jenkins/ComponentIntegTestStatus.groovy
Original file line number Diff line number Diff line change
@@ -20,18 +20,20 @@
String indexName
String product
String version
String qualifier
String distributionBuildNumber
def script
OpenSearchMetricsQuery openSearchMetricsQuery

ComponentIntegTestStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String distributionBuildNumber, def script) {
ComponentIntegTestStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String qualifier, String distributionBuildNumber, def script) {
this.metricsUrl = metricsUrl
this.awsAccessKey = awsAccessKey
this.awsSecretKey = awsSecretKey
this.awsSessionToken = awsSessionToken
this.indexName = indexName
this.product = product
this.version = version
this.qualifier = qualifier
this.distributionBuildNumber = distributionBuildNumber
this.script = script
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
@@ -70,6 +72,13 @@
]
]
]
if (!isNullOrEmpty(this.qualifier)) {
queryMap.query.bool.filter.add([

Check warning on line 76 in src/jenkins/ComponentIntegTestStatus.groovy

Codecov / codecov/patch

src/jenkins/ComponentIntegTestStatus.groovy#L76

Added line #L76 was not covered by tests
match_phrase: [
qualifier: "${this.qualifier}"
]
])
}
def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}
@@ -106,6 +115,13 @@
]
]
]
if (!isNullOrEmpty(this.qualifier)) {
queryMap.query.bool.filter.add([
match_phrase: [
qualifier: "${this.qualifier}"
]
])
}
def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}
@@ -121,4 +137,8 @@
return jsonResponse
}

private boolean isNullOrEmpty(String str) {
return (str == 'Null' || str == null || str.allWhitespace || str.isEmpty()) || str == "None"
}

}
60 changes: 24 additions & 36 deletions src/jenkins/ReleaseCandidateStatus.groovy
Original file line number Diff line number Diff line change
@@ -19,16 +19,18 @@
String awsSessionToken
String indexName
String version
String qualifier
def script
def openSearchMetricsQuery

ReleaseCandidateStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String version, def script) {
ReleaseCandidateStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String version, String qualifier, def script) {
this.metricsUrl = metricsUrl
this.awsAccessKey = awsAccessKey
this.awsSecretKey = awsSecretKey
this.awsSessionToken = awsSessionToken
this.indexName = indexName
this.version = version
this.qualifier = qualifier
this.script = script
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
}
@@ -71,43 +73,19 @@
]

if (rcNumber != null) {
queryMap = [
_source: "distribution_build_number",
sort: [
[
distribution_build_number: [
order: "desc"
]
queryMap.sort[0].remove("rc_number")
queryMap.query.bool.filter.add([
match_phrase: [
rc_number: "${rcNumber}"
]
],
size: 1,
query: [
bool: [
filter: [
[
match_phrase: [
component: "${componentName}"
]
],
[
match_phrase: [
rc: "true"
]
],
[
match_phrase: [
version: "${this.version}"
]
],
[
match_phrase: [
rc_number: "${rcNumber}"
]
]
]
])
}
if (!isNullOrEmpty(this.qualifier)) {
queryMap.query.bool.filter.add([

Check warning on line 84 in src/jenkins/ReleaseCandidateStatus.groovy

Codecov / codecov/patch

src/jenkins/ReleaseCandidateStatus.groovy#L84

Added line #L84 was not covered by tests
match_phrase: [
qualifier: "${this.qualifier}"
]
]
]
])
}

def query = JsonOutput.toJson(queryMap)
@@ -150,6 +128,13 @@
]
]
]
if (!isNullOrEmpty(this.qualifier)) {
queryMap.query.bool.filter.add([
match_phrase: [
qualifier: "${this.qualifier}"
]
])
}
def query = JsonOutput.toJson(queryMap)
return query.replace('"', '\\"')
}
@@ -166,4 +151,7 @@
return rcNumber
}

private boolean isNullOrEmpty(String str) {
return (str == 'Null' || str == null || str.allWhitespace || str.isEmpty()) || str == "None"
}
}
53 changes: 52 additions & 1 deletion tests/jenkins/TestComponentBuildStatus.groovy
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ class TestComponentBuildStatus {
private final String indexName = 'opensearch-distribution-build-results-*'
private final String product = "OpenSearch"
private final String version = "2.18.0"
private final String qualifier = "None"
private final String distributionBuildNumber = "4891"
private final String buildStartTimeFrom = "now-6h"
private final String buildStartTimeTo = "now"
@@ -66,7 +67,7 @@ class TestComponentBuildStatus {
}
return ""
}
componentBuildStatus = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script)
componentBuildStatus = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, qualifier, distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script)
}

@Test
@@ -114,6 +115,56 @@ class TestComponentBuildStatus {
def result = componentBuildStatus.getQuery('failed')
assert result == expectedOutput
}
@Test
void testGetQueryReturnsExpectedQueryWithQualifier() {
def expectedOutput = JsonOutput.toJson([
_source: [
"component",
],
query: [
bool: [
filter: [
[
match_phrase: [
component_category: "OpenSearch"
]
],
[
match_phrase: [
component_build_result: "failed"
]
],
[
match_phrase: [
version: "2.18.0"
]
],
[
match_phrase : [
distribution_build_number : "4891"
]
],
[
range: [
build_start_time: [
from: "now-6h",
to: "now"
]
]
],
[
match_phrase : [
qualifier : "alpha1"
]
]
]
]
]
]).replace('"', '\\"')
def componentBuildStatusNew = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, 'alpha1', distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script)
def result = componentBuildStatusNew.getQuery('failed')
assert result == expectedOutput
}

@Test
void testComponentBuildStatusReturns() {
Loading
Loading