Skip to content

Commit 9c092d5

Browse files
Add qualifier support to metrics queries (#611)
(cherry picked from commit 822d25f) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3684ee5 commit 9c092d5

15 files changed

+336
-113
lines changed

src/jenkins/ComponentBuildStatus.groovy

+27-5
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,40 @@ class ComponentBuildStatus {
1818
String awsSecretKey
1919
String awsSessionToken
2020
String indexName
21-
String product
21+
String product
2222
String version
23+
String qualifier
2324
String distributionBuildNumber
2425
String buildStartTimeFrom
2526
String buildStartTimeTo
2627
def script
2728
OpenSearchMetricsQuery openSearchMetricsQuery
2829

29-
ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String distributionBuildNumber, String buildStartTimeFrom, String buildStartTimeTo, def script) {
30+
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) {
3031
this.metricsUrl = metricsUrl
3132
this.awsAccessKey = awsAccessKey
3233
this.awsSecretKey = awsSecretKey
3334
this.awsSessionToken = awsSessionToken
3435
this.indexName = indexName
3536
this.product = product
3637
this.version = version
38+
this.qualifier = qualifier
3739
this.distributionBuildNumber = distributionBuildNumber
3840
this.buildStartTimeFrom = buildStartTimeFrom
3941
this.buildStartTimeTo = buildStartTimeTo
4042
this.script = script
4143
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
4244
}
4345

44-
ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, def script) {
46+
ComponentBuildStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String qualifier, def script) {
4547
this.metricsUrl = metricsUrl
4648
this.awsAccessKey = awsAccessKey
4749
this.awsSecretKey = awsSecretKey
4850
this.awsSessionToken = awsSessionToken
4951
this.indexName = indexName
5052
this.product = product
5153
this.version = version
54+
this.qualifier = qualifier
5255
this.script = script
5356
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
5457
}
@@ -57,7 +60,7 @@ class ComponentBuildStatus {
5760
def queryMap = [
5861
_source: [
5962
"component",
60-
],
63+
],
6164
query: [
6265
bool: [
6366
filter: [
@@ -93,6 +96,13 @@ class ComponentBuildStatus {
9396
]
9497
]
9598
]
99+
if (!isNullOrEmpty(this.qualifier)) {
100+
queryMap.query.bool.filter.add([
101+
match_phrase: [
102+
qualifier: "${this.qualifier}"
103+
]
104+
])
105+
}
96106
def query = JsonOutput.toJson(queryMap)
97107
return query.replace('"', '\\"')
98108
}
@@ -102,7 +112,7 @@ class ComponentBuildStatus {
102112
size : 1,
103113
_source: [
104114
"distribution_build_number",
105-
],
115+
],
106116
query: [
107117
bool: [
108118
filter: [
@@ -127,6 +137,14 @@ class ComponentBuildStatus {
127137
]
128138
]
129139
]
140+
141+
if (!isNullOrEmpty(this.qualifier)) {
142+
queryMap.query.bool.filter.add([
143+
match_phrase: [
144+
qualifier: "${this.qualifier}"
145+
]
146+
])
147+
}
130148
def query = JsonOutput.toJson(queryMap)
131149
return query.replace('"', '\\"')
132150
}
@@ -142,4 +160,8 @@ class ComponentBuildStatus {
142160
def latestDistributionBuildNumber = jsonResponse.hits.hits[0]._source.distribution_build_number
143161
return latestDistributionBuildNumber
144162
}
163+
164+
private boolean isNullOrEmpty(String str) {
165+
return (str == 'Null' || str == null || str.allWhitespace || str.isEmpty()) || str == "None"
166+
}
145167
}

src/jenkins/ComponentIntegTestStatus.groovy

+21-1
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ class ComponentIntegTestStatus {
2020
String indexName
2121
String product
2222
String version
23+
String qualifier
2324
String distributionBuildNumber
2425
def script
2526
OpenSearchMetricsQuery openSearchMetricsQuery
2627

27-
ComponentIntegTestStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String distributionBuildNumber, def script) {
28+
ComponentIntegTestStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String product, String version, String qualifier, String distributionBuildNumber, def script) {
2829
this.metricsUrl = metricsUrl
2930
this.awsAccessKey = awsAccessKey
3031
this.awsSecretKey = awsSecretKey
3132
this.awsSessionToken = awsSessionToken
3233
this.indexName = indexName
3334
this.product = product
3435
this.version = version
36+
this.qualifier = qualifier
3537
this.distributionBuildNumber = distributionBuildNumber
3638
this.script = script
3739
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
@@ -70,6 +72,13 @@ class ComponentIntegTestStatus {
7072
]
7173
]
7274
]
75+
if (!isNullOrEmpty(this.qualifier)) {
76+
queryMap.query.bool.filter.add([
77+
match_phrase: [
78+
qualifier: "${this.qualifier}"
79+
]
80+
])
81+
}
7382
def query = JsonOutput.toJson(queryMap)
7483
return query.replace('"', '\\"')
7584
}
@@ -106,6 +115,13 @@ class ComponentIntegTestStatus {
106115
]
107116
]
108117
]
118+
if (!isNullOrEmpty(this.qualifier)) {
119+
queryMap.query.bool.filter.add([
120+
match_phrase: [
121+
qualifier: "${this.qualifier}"
122+
]
123+
])
124+
}
109125
def query = JsonOutput.toJson(queryMap)
110126
return query.replace('"', '\\"')
111127
}
@@ -121,4 +137,8 @@ class ComponentIntegTestStatus {
121137
return jsonResponse
122138
}
123139

140+
private boolean isNullOrEmpty(String str) {
141+
return (str == 'Null' || str == null || str.allWhitespace || str.isEmpty()) || str == "None"
142+
}
143+
124144
}

src/jenkins/ReleaseCandidateStatus.groovy

+24-36
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ class ReleaseCandidateStatus {
1919
String awsSessionToken
2020
String indexName
2121
String version
22+
String qualifier
2223
def script
2324
def openSearchMetricsQuery
2425

25-
ReleaseCandidateStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String version, def script) {
26+
ReleaseCandidateStatus(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String version, String qualifier, def script) {
2627
this.metricsUrl = metricsUrl
2728
this.awsAccessKey = awsAccessKey
2829
this.awsSecretKey = awsSecretKey
2930
this.awsSessionToken = awsSessionToken
3031
this.indexName = indexName
3132
this.version = version
33+
this.qualifier = qualifier
3234
this.script = script
3335
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script)
3436
}
@@ -71,43 +73,19 @@ class ReleaseCandidateStatus {
7173
]
7274

7375
if (rcNumber != null) {
74-
queryMap = [
75-
_source: "distribution_build_number",
76-
sort: [
77-
[
78-
distribution_build_number: [
79-
order: "desc"
80-
]
76+
queryMap.sort[0].remove("rc_number")
77+
queryMap.query.bool.filter.add([
78+
match_phrase: [
79+
rc_number: "${rcNumber}"
8180
]
82-
],
83-
size: 1,
84-
query: [
85-
bool: [
86-
filter: [
87-
[
88-
match_phrase: [
89-
component: "${componentName}"
90-
]
91-
],
92-
[
93-
match_phrase: [
94-
rc: "true"
95-
]
96-
],
97-
[
98-
match_phrase: [
99-
version: "${this.version}"
100-
]
101-
],
102-
[
103-
match_phrase: [
104-
rc_number: "${rcNumber}"
105-
]
106-
]
107-
]
81+
])
82+
}
83+
if (!isNullOrEmpty(this.qualifier)) {
84+
queryMap.query.bool.filter.add([
85+
match_phrase: [
86+
qualifier: "${this.qualifier}"
10887
]
109-
]
110-
]
88+
])
11189
}
11290

11391
def query = JsonOutput.toJson(queryMap)
@@ -150,6 +128,13 @@ class ReleaseCandidateStatus {
150128
]
151129
]
152130
]
131+
if (!isNullOrEmpty(this.qualifier)) {
132+
queryMap.query.bool.filter.add([
133+
match_phrase: [
134+
qualifier: "${this.qualifier}"
135+
]
136+
])
137+
}
153138
def query = JsonOutput.toJson(queryMap)
154139
return query.replace('"', '\\"')
155140
}
@@ -166,4 +151,7 @@ class ReleaseCandidateStatus {
166151
return rcNumber
167152
}
168153

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

tests/jenkins/TestComponentBuildStatus.groovy

+52-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TestComponentBuildStatus {
2424
private final String indexName = 'opensearch-distribution-build-results-*'
2525
private final String product = "OpenSearch"
2626
private final String version = "2.18.0"
27+
private final String qualifier = "None"
2728
private final String distributionBuildNumber = "4891"
2829
private final String buildStartTimeFrom = "now-6h"
2930
private final String buildStartTimeTo = "now"
@@ -66,7 +67,7 @@ class TestComponentBuildStatus {
6667
}
6768
return ""
6869
}
69-
componentBuildStatus = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script)
70+
componentBuildStatus = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, qualifier, distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script)
7071
}
7172

7273
@Test
@@ -114,6 +115,56 @@ class TestComponentBuildStatus {
114115
def result = componentBuildStatus.getQuery('failed')
115116
assert result == expectedOutput
116117
}
118+
@Test
119+
void testGetQueryReturnsExpectedQueryWithQualifier() {
120+
def expectedOutput = JsonOutput.toJson([
121+
_source: [
122+
"component",
123+
],
124+
query: [
125+
bool: [
126+
filter: [
127+
[
128+
match_phrase: [
129+
component_category: "OpenSearch"
130+
]
131+
],
132+
[
133+
match_phrase: [
134+
component_build_result: "failed"
135+
]
136+
],
137+
[
138+
match_phrase: [
139+
version: "2.18.0"
140+
]
141+
],
142+
[
143+
match_phrase : [
144+
distribution_build_number : "4891"
145+
]
146+
],
147+
[
148+
range: [
149+
build_start_time: [
150+
from: "now-6h",
151+
to: "now"
152+
]
153+
]
154+
],
155+
[
156+
match_phrase : [
157+
qualifier : "alpha1"
158+
]
159+
]
160+
]
161+
]
162+
]
163+
]).replace('"', '\\"')
164+
def componentBuildStatusNew = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, 'alpha1', distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script)
165+
def result = componentBuildStatusNew.getQuery('failed')
166+
assert result == expectedOutput
167+
}
117168

118169
@Test
119170
void testComponentBuildStatusReturns() {

0 commit comments

Comments
 (0)