-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor build failure library to use metrics data (#515)
Signed-off-by: Sayali Gaikawad <[email protected]>
- Loading branch information
Showing
23 changed files
with
474 additions
and
681 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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 utils.OpenSearchMetricsQuery | ||
|
||
class 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 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.distributionBuildNumber = distributionBuildNumber | ||
this.buildStartTimeFrom = buildStartTimeFrom | ||
this.buildStartTimeTo = buildStartTimeTo | ||
this.script = script | ||
} | ||
|
||
def getQuery(String componentBuildResult) { | ||
def queryMap = [ | ||
_source: [ | ||
"component", | ||
], | ||
query: [ | ||
bool: [ | ||
filter: [ | ||
[ | ||
match_phrase: [ | ||
component_category: "${this.product}" | ||
] | ||
], | ||
[ | ||
match_phrase: [ | ||
component_build_result: "${componentBuildResult}" | ||
] | ||
], | ||
[ | ||
match_phrase: [ | ||
version: "${this.version}" | ||
] | ||
], | ||
[ | ||
match_phrase : [ | ||
distribution_build_number : "${this.distributionBuildNumber}" | ||
] | ||
], | ||
[ | ||
range: [ | ||
build_start_time: [ | ||
from: "${this.buildStartTimeFrom}", | ||
to: "${this.buildStartTimeTo}" | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
def query = JsonOutput.toJson(queryMap) | ||
return query.replace('"', '\\"') | ||
} | ||
|
||
def getComponents(String componentBuildResult) { | ||
def jsonResponse = new OpenSearchMetricsQuery(metricsUrl,awsAccessKey, awsSecretKey, awsSessionToken, indexName, script).fetchMetrics(getQuery(componentBuildResult)) | ||
def components = jsonResponse.hits.hits.collect { it._source.component } | ||
return components | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,124 @@ | ||
/* | ||
* 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.mock.interceptor.MockFor | ||
|
||
class TestComponentBuildStatus { | ||
|
||
private ComponentBuildStatus componentBuildStatus | ||
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 indexName = 'opensearch-distribution-build-results-*' | ||
private final String product = "OpenSearch" | ||
private final String version = "2.18.0" | ||
private final String distributionBuildNumber = "4891" | ||
private final String buildStartTimeFrom = "now-6h" | ||
private final String buildStartTimeTo = "now" | ||
private def script | ||
|
||
@Before | ||
void setUp() { | ||
script = new Expando() | ||
script.sh = { Map args -> | ||
if (args.containsKey("script")) { | ||
return """ | ||
{ | ||
"hits": { | ||
"total": { | ||
"value": 2, | ||
"relation": "eq" | ||
}, | ||
"max_score": 0, | ||
"hits": [ | ||
{ | ||
"_index": "opensearch-distribution-build-results-09-2024", | ||
"_id": "QTVbQZIBOi-lzDIlekCk", | ||
"_score": 0, | ||
"_source": { | ||
"component": "performance-analyzer" | ||
} | ||
}, | ||
{ | ||
"_index": "opensearch-distribution-build-results-09-2024", | ||
"_id": "PzVbQZIBOi-lzDIlekCk", | ||
"_score": 0, | ||
"_source": { | ||
"component": "security-analytics" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
""" | ||
} | ||
return "" | ||
} | ||
componentBuildStatus = new ComponentBuildStatus(metricsUrl, awsAccessKey, awsSecretKey, awsSessionToken, indexName, product, version, distributionBuildNumber, buildStartTimeFrom, buildStartTimeTo, script) | ||
} | ||
|
||
@Test | ||
void testGetQueryReturnsExpectedQuery() { | ||
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" | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]).replace('"', '\\"') | ||
|
||
def result = componentBuildStatus.getQuery('failed') | ||
assert result == expectedOutput | ||
} | ||
|
||
@Test | ||
void testComponentBuildStatusReturns() { | ||
def expectedOutput = ['performance-analyzer', 'security-analytics'] | ||
def result = componentBuildStatus.getComponents('failed') | ||
|
||
assert result == expectedOutput | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.