Skip to content

Commit 18f7153

Browse files
authored
Test pipeline for spring application insights (Azure#36356)
* prepare monitor pipeline * add test
1 parent fb6c49a commit 18f7153

File tree

6 files changed

+213
-1
lines changed

6 files changed

+213
-1
lines changed

sdk/spring/ci.monitor.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ trigger:
1111
include:
1212
- sdk/spring/ci.monitor.yml
1313
- sdk/spring/spring-cloud-azure-starter-monitor/
14+
- sdk/spring/spring-cloud-azure-starter-monitor-test/
1415
pr:
1516
branches:
1617
include:
@@ -22,6 +23,7 @@ pr:
2223
include:
2324
- sdk/spring/ci.monitor.yml
2425
- sdk/spring/spring-cloud-azure-starter-monitor/
26+
- sdk/spring/spring-cloud-azure-starter-monitor-test/
2527

2628
extends:
2729
template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
@@ -36,4 +38,7 @@ extends:
3638
skipPublishDocMs: true
3739
skipUpdatePackageJson: true
3840
skipVerifyChangelog: true
39-
releaseInBatch: ${{ parameters.release_springcloudazurestartermonitor }}
41+
releaseInBatch: true
42+
AdditionalModules:
43+
- name: spring-cloud-azure-starter-monitor-test
44+
groupId: com.azure.spring

sdk/spring/monitor-matrix.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"displayNames": {
3+
4+
},
5+
"matrix": {
6+
"Agent": {
7+
"ubuntu-20.04": { "OSVmImage": "MMSUbuntu20.04", "Pool": "azsdk-pool-mms-ubuntu-2004-general" }
8+
},
9+
"JavaTestVersion": "1.17",
10+
"TEST_SPRING_BOOT_VERSION": [
11+
12+
]
13+
}
14+
}

sdk/spring/monitor-tests-job.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
parameters:
2+
Matrix: ''
3+
MaxParallel: 10
4+
SkipOptions: "-Dcheckstyle.skip -Dcodesnippet.skip -Denforcer.skip -Djacoco.skip -Dmaven.javadoc.skip -Drevapi.skip -Dspotbugs.skip"
5+
BuildParallelization: '2C'
6+
7+
jobs:
8+
- job: 'monitor_test'
9+
dependsOn: ${{ parameters.DependsOn }}
10+
condition: and(succeededOrFailed(), ne(${{ parameters.Matrix }}, '{}'))
11+
strategy:
12+
maxParallel: ${{ parameters.MaxParallel }}
13+
matrix: $[ ${{ parameters.Matrix }} ]
14+
variables:
15+
- template: ../../eng/pipelines/templates/variables/globals.yml
16+
steps:
17+
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
18+
parameters:
19+
Paths:
20+
- 'sdk/spring/spring-cloud-azure-starter-monitor-test'
21+
# - script: |
22+
# python -m pip install termcolor
23+
# displayName: 'Python module install'
24+
- bash: |
25+
echo "$(TEST_SPRING_BOOT_VERSION):"
26+
echo "https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/$(TEST_SPRING_BOOT_VERSION)/spring-boot-dependencies-$(TEST_SPRING_BOOT_VERSION).pom"
27+
displayName: 'Print version maven pom'
28+
- script: |
29+
python ./sdk/spring/scripts/replace_v_4_monitor.py -b $(TEST_SPRING_BOOT_VERSION)
30+
displayName: 'Replace Spring version'
31+
- task: Maven@3
32+
displayName: 'Run tests'
33+
inputs:
34+
options: '$(DefaultOptions) -ntp -T ${{parameters.BuildParallelization}} ${{parameters.SkipOptions}}'
35+
mavenPomFile: sdk/spring/spring-cloud-azure-starter-monitor-test/pom.xml
36+
mavenOptions: '$(MemoryOptions)'
37+
javaHomeOption: 'JDKVersion'
38+
jdkVersionOption: $(JavaTestVersion)
39+
jdkArchitectureOption: 'x64'
40+
goals: 'clean verify'
41+

sdk/spring/monitor-tests.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
trigger: none
2+
pr: none
3+
4+
variables:
5+
- template: ../../eng/pipelines/templates/variables/globals.yml
6+
7+
stages:
8+
- stage: "monitor_tests"
9+
jobs:
10+
- template: /eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml
11+
parameters:
12+
SparseCheckout: true
13+
JobTemplatePath: ../../../../../sdk/spring/monitor-tests-job.yml
14+
AdditionalParameters:
15+
ServiceDirectory: spring
16+
- template: /eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml
17+
parameters:
18+
SparseCheckout: true
19+
JobTemplatePath: ../../../../../sdk/spring/monitor-tests-job.yml
20+
AdditionalParameters:
21+
ServiceDirectory: spring
22+
MatrixConfigs:
23+
- Name: monitor_compatibility_tests
24+
Path: sdk/spring/monitor-matrix.json
25+
Selection: sparse
26+
NonSparseParameters:
27+
- TEST_SPRING_BOOT_VERSION
28+
GenerateVMJobs: true
29+
PreGenerationSteps:
30+
# - script: |
31+
# python -m pip install termcolor
32+
# displayName: 'python module install'
33+
- script: |
34+
python ./sdk/spring/scripts/monitor_update_monitor_matrix_json.py
35+
displayName: 'update test version'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Python version 3.4 or higher is required to run this script.
2+
#
3+
# This script is used to update sdk\spring\supported-version-matrix.json before compatibility check.
4+
# Sample:
5+
# 1. python .\sdk\spring\scripts\monitor_update_monitor_matrix_json.py
6+
#
7+
# The script must be run at the root of azure-sdk-for-java.
8+
9+
10+
import time
11+
from log import log
12+
import os
13+
import json
14+
import requests
15+
16+
17+
def change_to_repo_root_dir():
18+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
19+
os.chdir('../../..')
20+
21+
22+
def update_monitor_matrix_json_file(filepath, test_spring_boot_version):
23+
names = {}
24+
for version in test_spring_boot_version:
25+
names[version] = "springboot" + version.replace(".", "_")
26+
with open(filepath, 'r') as file:
27+
data = json.load(file)
28+
data['displayNames'] = names
29+
data['matrix']['TEST_SPRING_BOOT_VERSION'] = test_spring_boot_version
30+
with open(filepath, 'w') as file:
31+
json.dump(data, file, indent = 2)
32+
33+
34+
def get_supported_spring_boot_version(filepath):
35+
version3 = []
36+
version2 = []
37+
data = requests.get(filepath).json()
38+
for entry in data:
39+
for key in entry:
40+
if entry[key] == "SUPPORTED" and entry["spring-boot-version"].startswith("3."):
41+
version3.append(entry["spring-boot-version"])
42+
if entry[key] == "SUPPORTED" and entry["spring-boot-version"].startswith("2."):
43+
version2.append(entry["spring-boot-version"])
44+
supported_version_list = [max(version3), max(version2)]
45+
return supported_version_list
46+
47+
48+
def main():
49+
start_time = time.time()
50+
change_to_repo_root_dir()
51+
log.debug('Current working directory = {}.'.format(os.getcwd()))
52+
test_spring_boot_version = get_supported_spring_boot_version("https://raw.githubusercontent.com/Azure/azure-sdk-for-java/main/sdk/spring/spring-cloud-azure-supported-spring.json")
53+
update_monitor_matrix_json_file("./sdk/spring/monitor-matrix.json", test_spring_boot_version)
54+
elapsed_time = time.time() - start_time
55+
log.info('elapsed_time = {}'.format(elapsed_time))
56+
57+
58+
if __name__ == '__main__':
59+
main()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Python version 3.4 or higher is required to run this script.
2+
#
3+
# This script is used to update sdk\spring\spring-cloud-azure-starter-monitor-test\pom.xml before compatibility check.
4+
# Sample:
5+
# 1. python .\sdk\spring\scripts\replace_v_4_monitor.py -b 3.1.2
6+
#
7+
# The script must be run at the root of azure-sdk-for-java.
8+
9+
10+
import time
11+
from log import log
12+
import os
13+
import argparse
14+
import re
15+
import xml.etree.ElementTree as ET
16+
17+
18+
def replace_version(file_path, current_version, new_version):
19+
with open(file_path, 'r') as file:
20+
lines = file.readlines()
21+
22+
with open(file_path, 'w') as file:
23+
for line in lines:
24+
if '<!-- {x-version-update;org.springframework.boot:' in line and current_version in line:
25+
line = re.sub(current_version, new_version, line)
26+
file.write(line)
27+
28+
29+
def main():
30+
start_time = time.time()
31+
change_to_repo_root_dir()
32+
log.debug('Current working directory = {}.'.format(os.getcwd()))
33+
file_path = 'sdk/spring/spring-cloud-azure-starter-monitor-test/pom.xml'
34+
current_spring_boot_version = get_current_spring_boot_version(file_path)
35+
replace_version(file_path, current_spring_boot_version, get_args().spring_boot_version)
36+
elapsed_time = time.time() - start_time
37+
log.info('elapsed_time = {}'.format(elapsed_time))
38+
39+
40+
def get_args():
41+
parser = argparse.ArgumentParser()
42+
parser.add_argument('-b', '--spring-boot-version', type = str, required = True)
43+
return parser.parse_args()
44+
45+
46+
def change_to_repo_root_dir():
47+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
48+
os.chdir('../../..')
49+
50+
51+
def get_current_spring_boot_version(filepath):
52+
tree = ET.parse(filepath)
53+
root = tree.getroot()
54+
return root.find("{http://maven.apache.org/POM/4.0.0}parent/{http://maven.apache.org/POM/4.0.0}version").text
55+
56+
57+
if __name__ == '__main__':
58+
main()

0 commit comments

Comments
 (0)