forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more details to integTest failure issues (opensearch-project#545)
Signed-off-by: Sayali Gaikawad <[email protected]>
- Loading branch information
Showing
11 changed files
with
504 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package jenkins | ||
|
||
import groovy.json.JsonOutput | ||
import groovyjarjarantlr.collections.List | ||
import utils.OpenSearchMetricsQuery | ||
|
||
class ReleaseMetricsData { | ||
String metricsUrl | ||
String awsAccessKey | ||
String awsSecretKey | ||
String awsSessionToken | ||
String indexName | ||
String version | ||
def script | ||
OpenSearchMetricsQuery openSearchMetricsQuery | ||
|
||
ReleaseMetricsData(String metricsUrl, String awsAccessKey, String awsSecretKey, String awsSessionToken, String indexName, String version, def script) { | ||
this.metricsUrl = metricsUrl | ||
this.awsAccessKey = awsAccessKey | ||
this.awsSecretKey = awsSecretKey | ||
this.awsSessionToken = awsSessionToken | ||
this.indexName = indexName | ||
this.version = version | ||
this.script = script | ||
this.openSearchMetricsQuery = new OpenSearchMetricsQuery(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, script) | ||
} | ||
|
||
String getReleaseOwnerQuery(String component) { | ||
def queryMap = [ | ||
size : 1, | ||
_source: "release_owners", | ||
query : [ | ||
bool: [ | ||
filter: [ | ||
[ | ||
match_phrase: [ | ||
component: "${component}" | ||
] | ||
], | ||
[ | ||
match_phrase: [ | ||
version: "${this.version}" | ||
] | ||
] | ||
] | ||
], | ||
sort: [ | ||
[ | ||
current_date: [ | ||
order: "desc" | ||
] | ||
] | ||
] | ||
] | ||
] | ||
String query = JsonOutput.toJson(queryMap) | ||
return query.replace('"', '\\"') | ||
} | ||
|
||
ArrayList getReleaseOwners(String component) { | ||
def jsonResponse = this.openSearchMetricsQuery.fetchMetrics(getReleaseOwnerQuery(component)) | ||
def releaseOwners = jsonResponse.hits.hits._source.release_owners.flatten() | ||
return releaseOwners | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package jenkins | ||
|
||
import org.junit.* | ||
import groovy.json.JsonOutput | ||
import groovy.json.JsonSlurper | ||
|
||
class TestReleaseMetricsData { | ||
private ReleaseMetricsData releaseMetricsData | ||
private final String metricsUrl = 'http://example.com' | ||
private final String awsAccessKey = 'testAccessKey' | ||
private final String awsSecretKey = 'testSecretKey' | ||
private final String awsSessionToken = 'testSessionToken' | ||
private final String version = "2.18.0" | ||
private def script | ||
|
||
@Before | ||
void setUp() { | ||
script = new Expando() | ||
script.sh = { Map args -> | ||
if (args.containsKey("script")) { | ||
return """ | ||
{ | ||
"took": 4, | ||
"timed_out": false, | ||
"_shards": { | ||
"total": 5, | ||
"successful": 5, | ||
"skipped": 0, | ||
"failed": 0 | ||
}, | ||
"hits": { | ||
"total": { | ||
"value": 31, | ||
"relation": "eq" | ||
}, | ||
"max_score": null, | ||
"hits": [ | ||
{ | ||
"_index": "opensearch_release_metrics", | ||
"_id": "9ee464d8-b47d-3f5e-aa8f-8768c98a8d69", | ||
"_score": null, | ||
"_source": { | ||
"release_owners": [ | ||
"foo", | ||
"bar" | ||
] | ||
}, | ||
"sort": [ | ||
1729707921551 | ||
] | ||
} | ||
] | ||
} | ||
} | ||
""" | ||
} | ||
return "" | ||
} | ||
releaseMetricsData = new ReleaseMetricsData(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, 'opensearch_release_metrics', version, script) | ||
} | ||
|
||
@Test | ||
void testGetReleaseOwnerReturnQuery(){ | ||
String expectedOutput = JsonOutput.toJson([ | ||
size : 1, | ||
_source: "release_owners", | ||
query : [ | ||
bool: [ | ||
filter: [ | ||
[ | ||
match_phrase: [ | ||
component: "sql" | ||
] | ||
], | ||
[ | ||
match_phrase: [ | ||
version: "2.18.0" | ||
] | ||
] | ||
] | ||
], | ||
sort: [ | ||
[ | ||
current_date: [ | ||
order: "desc" | ||
] | ||
] | ||
] | ||
] | ||
]).replace('"', '\\"') | ||
|
||
def result = releaseMetricsData.getReleaseOwnerQuery('sql') | ||
assert result == expectedOutput | ||
} | ||
|
||
@Test | ||
void testGetReleaseOwners(){ | ||
def expectedOutput = ['foo', 'bar'] | ||
def result = releaseMetricsData.getReleaseOwners('sql') | ||
assert result == expectedOutput | ||
} | ||
} |
Oops, something went wrong.