Skip to content

Commit 532317c

Browse files
authored
Run monitoring manually (#860)
1 parent 2dcebb5 commit 532317c

File tree

5 files changed

+268
-122
lines changed

5 files changed

+268
-122
lines changed
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
name: "UTBot Java: collect statistics"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
runners:
7+
description: 'Runners number'
8+
required: false
9+
default: '1'
10+
type: string
11+
run_number:
12+
description: 'Number of run tries per runner'
13+
required: false
14+
default: '1'
15+
type: string
16+
message_prefix:
17+
description: 'Commit message prefix'
18+
required: false
19+
default: manual-run
20+
type: string
21+
aggregate:
22+
description: 'Aggregate data'
23+
required: false
24+
default: false
25+
type: boolean
26+
27+
workflow_dispatch:
28+
inputs:
29+
runners:
30+
description: 'Runners number'
31+
required: false
32+
default: '1'
33+
type: string
34+
run_number:
35+
description: 'Number of run tries per runner'
36+
required: false
37+
default: '1'
38+
type: string
39+
message_prefix:
40+
description: 'Commit message prefix'
41+
required: false
42+
default: manual-run
43+
type: string
44+
aggregate:
45+
description: 'Aggregate data'
46+
required: false
47+
default: false
48+
type: boolean
49+
50+
env:
51+
data_branch: monitoring-data
52+
data_path: monitoring/data
53+
aggregated_data_branch: monitoring-aggregated-data
54+
aggregated_data_path: monitoring/aggregated_data
55+
monitoring_properties: monitoring/monitoring.properties
56+
push_script: monitoring/push_with_rebase.sh
57+
58+
jobs:
59+
setup_matrix:
60+
runs-on: ubuntu-latest
61+
outputs:
62+
matrix: ${{ steps.set-matrix.outputs.matrix }}
63+
steps:
64+
- name: Create matrix
65+
id: set-matrix
66+
run: |
67+
arr=$(echo [$(seq -s , ${{ inputs.runners }})])
68+
echo "::set-output name=matrix::$arr"
69+
echo $arr
70+
71+
build_and_collect_statistics:
72+
needs: setup_matrix
73+
continue-on-error: true
74+
strategy:
75+
matrix:
76+
value: ${{ fromJson(needs.setup_matrix.outputs.matrix) }}
77+
runs-on: ubuntu-20.04
78+
container: unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
79+
steps:
80+
- name: Install git
81+
run: |
82+
apt-get upgrade -y
83+
apt-get update -y
84+
apt-get install git -y
85+
git config --global --add safe.directory $(pwd)
86+
87+
- name: Checkout repository
88+
uses: actions/checkout@v3
89+
90+
- name: Checkout monitoring data
91+
uses: actions/checkout@v3
92+
with:
93+
ref: ${{ env.data_branch }}
94+
path: ${{ env.data_path }}
95+
96+
- uses: actions/setup-python@v4
97+
with:
98+
python-version: '3.9'
99+
100+
- name: Build and run monitoring UTBot Java
101+
run: |
102+
gradle :utbot-junit-contest:monitoringJar
103+
for i in $(seq ${{ inputs.run_number }})
104+
do
105+
java -jar \
106+
-Dutbot.monitoring.settings.path=$monitoring_properties \
107+
utbot-junit-contest/build/libs/monitoring.jar \
108+
stats-$i.json
109+
mv logs/utbot.log logs/utbot-$i.log
110+
done
111+
112+
- name: Get current date
113+
id: date
114+
run: |
115+
echo "::set-output name=date::$(date +'%Y-%m-%d')"
116+
echo "::set-output name=timestamp::$(date +%s)"
117+
echo "::set-output name=last_month::$(date --date='last month' +%s)"
118+
119+
- name: Get metadata
120+
id: metadata
121+
run: |
122+
echo "::set-output name=commit::$(git rev-parse HEAD)"
123+
echo "::set-output name=short_commit::$(git rev-parse --short HEAD)"
124+
echo "::set-output name=branch::$(git name-rev --name-only HEAD)"
125+
echo "::set-output name=build::$(date +'%Y.%-m')"
126+
127+
- name: Insert metadata
128+
shell: bash
129+
run: |
130+
OUT_FILE="$data_path/data-$branch-$date-$timestamp-$short_commit-${{ matrix.value }}.json"
131+
INPUTS=($(seq ${{ inputs.run_number }}))
132+
INPUTS=(${INPUTS[@]/#/stats-})
133+
INPUTS=(${INPUTS[@]/%/.json})
134+
INPUTS=${INPUTS[@]}
135+
echo $INPUTS
136+
python monitoring/insert_metadata.py \
137+
--stats_file $INPUTS \
138+
--output_file "$OUT_FILE" \
139+
--commit $commit \
140+
--branch $branch \
141+
--build "$build" \
142+
--timestamp $timestamp \
143+
--source_type "github-action" \
144+
--source_id $run_id
145+
env:
146+
date: ${{ steps.date.outputs.date }}
147+
timestamp: ${{ steps.date.outputs.timestamp }}
148+
commit: ${{ steps.metadata.outputs.commit }}
149+
short_commit: ${{ steps.metadata.outputs.short_commit }}
150+
branch: ${{ steps.metadata.outputs.branch }}
151+
build: ${{ steps.metadata.outputs.build }}
152+
run_id: ${{ github.run_id }}-${{ matrix.value }}
153+
154+
- name: Commit and push statistics
155+
run: |
156+
chmod +x $push_script
157+
./$push_script
158+
env:
159+
target_branch: ${{ env.data_branch }}
160+
target_directory: ${{ env.data_path }}
161+
message: ${{ inputs.message_prefix }}-${{ steps.date.outputs.date }}
162+
github_token: ${{ secrets.GITHUB_TOKEN }}
163+
164+
- name: Upload logs
165+
if: ${{ always() }}
166+
uses: actions/upload-artifact@v3
167+
with:
168+
name: logs-${{ matrix.value }}
169+
path: logs/
170+
171+
aggregate:
172+
needs: build_and_collect_statistics
173+
if: ${{ inputs.aggregate }}
174+
runs-on: ubuntu-latest
175+
steps:
176+
- name: Checkout repository
177+
uses: actions/checkout@v3
178+
179+
- name: Checkout monitoring data
180+
uses: actions/checkout@v3
181+
with:
182+
ref: ${{ env.data_branch }}
183+
path: ${{ env.data_path }}
184+
185+
- name: Checkout aggregated monitoring data
186+
uses: actions/checkout@v3
187+
with:
188+
ref: ${{ env.aggregated_data_branch }}
189+
path: ${{ env.aggregated_data_path }}
190+
191+
- uses: actions/setup-python@v4
192+
with:
193+
python-version: '3.9'
194+
195+
- name: Get current date
196+
id: date
197+
run: |
198+
echo "::set-output name=date::$(date +'%Y-%m-%d')"
199+
echo "::set-output name=timestamp::$(date +%s)"
200+
echo "::set-output name=last_month::$(date --date='last month' +%s)"
201+
202+
- name: Build aggregated data (last month)
203+
run: |
204+
OUT_FILE=$aggregated_data_path/aggregated-data-$date.json
205+
python monitoring/build_aggregated_data.py \
206+
--input_data_dir $data_path \
207+
--output_file $OUT_FILE \
208+
--timestamp_from $timestamp_from \
209+
--timestamp_to $timestamp
210+
env:
211+
date: ${{ steps.date.outputs.date }}
212+
timestamp: ${{ steps.date.outputs.timestamp }}
213+
timestamp_from: ${{ steps.date.outputs.last_month }}
214+
215+
- name: Commit and push aggregated statistics
216+
run: |
217+
chmod +x $push_script
218+
./$push_script
219+
env:
220+
target_branch: ${{ env.aggregated_data_branch }}
221+
target_directory: ${{ env.aggregated_data_path }}
222+
message: ${{ inputs.message_prefix }}-${{ steps.date.outputs.date }}
223+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/night-statistics-monitoring.yml

Lines changed: 8 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -4,119 +4,12 @@ on:
44
schedule:
55
- cron: '0 0 * * *'
66

7-
env:
8-
data_branch: monitoring-data
9-
data_path: monitoring/data
10-
aggregated_data_branch: monitoring-aggregated-data
11-
aggregated_data_path: monitoring/aggregated_data
12-
monitoring_properties: monitoring/monitoring.properties
13-
output_stats: stats.json
14-
157
jobs:
16-
build_and_run_monitoring:
17-
runs-on: ubuntu-20.04
18-
container: unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
19-
steps:
20-
- name: Install git
21-
run: |
22-
apt-get upgrade -y
23-
apt-get update -y
24-
apt-get install git -y
25-
git config --global --add safe.directory $(pwd)
26-
27-
- name: Checkout main
28-
uses: actions/checkout@v3
29-
30-
- name: Checkout monitoring data
31-
uses: actions/checkout@v3
32-
with:
33-
ref: ${{ env.data_branch }}
34-
path: ${{ env.data_path }}
35-
36-
- name: Checkout aggregated monitoring data
37-
uses: actions/checkout@v3
38-
with:
39-
ref: ${{ env.aggregated_data_branch }}
40-
path: ${{ env.aggregated_data_path }}
41-
42-
- uses: actions/setup-python@v4
43-
with:
44-
python-version: '3.9'
45-
46-
- name: Build and run monitoring UTBot Java
47-
run: |
48-
gradle :utbot-junit-contest:monitoringJar
49-
java -jar \
50-
-Dutbot.monitoring.settings.path=$monitoring_properties \
51-
utbot-junit-contest/build/libs/monitoring.jar \
52-
$output_stats
53-
54-
- name: Get current date
55-
id: date
56-
run: |
57-
echo "::set-output name=date::$(date +'%Y-%m-%d')"
58-
echo "::set-output name=timestamp::$(date +%s)"
59-
echo "::set-output name=last_month::$(date --date='last month' +%s)"
60-
61-
- name: Get metadata
62-
id: metadata
63-
run: |
64-
echo "::set-output name=commit::$(git rev-parse HEAD)"
65-
echo "::set-output name=short_commit::$(git rev-parse --short HEAD)"
66-
echo "::set-output name=branch::$(git name-rev --name-only HEAD)"
67-
echo "::set-output name=build::$(date +'%Y.%-m')"
68-
69-
- name: Insert metadata
70-
run: |
71-
python monitoring/insert_metadata.py \
72-
--stats_file $output_stats \
73-
--output_file "$data_path/data-$branch-$date-$timestamp-$short_commit.json" \
74-
--commit $commit \
75-
--branch $branch \
76-
--build "$build" \
77-
--timestamp $timestamp \
78-
--source_type "github-action" \
79-
--source_id $run_id
80-
env:
81-
date: ${{ steps.date.outputs.date }}
82-
timestamp: ${{ steps.date.outputs.timestamp }}
83-
commit: ${{ steps.metadata.outputs.commit }}
84-
short_commit: ${{ steps.metadata.outputs.short_commit }}
85-
branch: ${{ steps.metadata.outputs.branch }}
86-
build: ${{ steps.metadata.outputs.build }}
87-
run_id: ${{ github.run_id }}
88-
89-
- name: Build aggregated data (last month)
90-
run: |
91-
python monitoring/build_aggregated_data.py \
92-
--input_data_dir $data_path \
93-
--output_file $aggregated_data_path/aggregated-data-$date.json \
94-
--timestamp_from $timestamp_from \
95-
--timestamp_to $timestamp
96-
env:
97-
date: ${{ steps.date.outputs.date }}
98-
timestamp: ${{ steps.date.outputs.timestamp }}
99-
timestamp_from: ${{ steps.date.outputs.last_month }}
100-
101-
- name: Commit and push statistics
102-
uses: actions-js/push@master
103-
with:
104-
branch: ${{ env.data_branch }}
105-
message: 'night-monitoring-${{ steps.date.outputs.date }}'
106-
directory: ${{ env.data_path }}
107-
github_token: ${{ secrets.GITHUB_TOKEN }}
108-
109-
- name: Commit and push aggregated statistics
110-
uses: actions-js/push@master
111-
with:
112-
branch: ${{ env.aggregated_data_branch }}
113-
message: 'night-monitoring-${{ steps.date.outputs.date }}'
114-
directory: ${{ env.aggregated_data_path }}
115-
github_token: ${{ secrets.GITHUB_TOKEN }}
116-
117-
- name: Upload logs
118-
if: ${{ always() }}
119-
uses: actions/upload-artifact@v3
120-
with:
121-
name: logs
122-
path: logs/utbot.log
8+
run_monitoring:
9+
uses: ./.github/workflows/collect-statistics.yml
10+
secrets: inherit
11+
with:
12+
runners: 3
13+
run_number: 1
14+
message_prefix: night-monitoring
15+
aggregate: true

monitoring/insert_metadata.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ def build_targets(stats_array: List[dict]) -> List[dict]:
108108

109109
def insert_metadata(args: argparse.Namespace) -> dict:
110110
"""
111-
Collect metadata and statistics from specified file and merge them into result
111+
Collect metadata and statistics from specified files and merge them into result
112112
:param args: parsed program arguments
113113
:return: dictionary with statistics and metadata
114114
"""
115-
stats_array = load(args.stats_file)
116-
if stats_array is None:
117-
raise FileNotFoundError("File with stats does not exist!")
115+
stats_array = [item for f in args.stats_file for item in load(f)]
118116
result = {
119117
'version': JSON_VERSION,
120118
'targets': build_targets(stats_array),
@@ -126,8 +124,8 @@ def insert_metadata(args: argparse.Namespace) -> dict:
126124
def get_args():
127125
parser = argparse.ArgumentParser()
128126
parser.add_argument(
129-
'--stats_file', required=True,
130-
help='file with statistics', type=str
127+
'--stats_file', required=True, nargs='+',
128+
help='files (one or more) with statistics', type=str
131129
)
132130
parser.add_argument(
133131
'--commit', help='commit hash', type=str

monitoring/monitoring.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
project=guava
22
classTimeoutMillis=20
3-
runTries=3
3+
runTries=1
44
runTimeoutMinutes=20

0 commit comments

Comments
 (0)