Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 223 additions & 0 deletions .github/workflows/collect-statistics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
name: "UTBot Java: collect statistics"

on:
workflow_call:
inputs:
runners:
description: 'Runners number'
required: false
default: '1'
type: string
run_number:
description: 'Number of run tries per runner'
required: false
default: '1'
type: string
message_prefix:
description: 'Commit message prefix'
required: false
default: manual-run
type: string
aggregate:
description: 'Aggregate data'
required: false
default: false
type: boolean

workflow_dispatch:
inputs:
runners:
description: 'Runners number'
required: false
default: '1'
type: string
run_number:
description: 'Number of run tries per runner'
required: false
default: '1'
type: string
message_prefix:
description: 'Commit message prefix'
required: false
default: manual-run
type: string
aggregate:
description: 'Aggregate data'
required: false
default: false
type: boolean

env:
data_branch: monitoring-data
data_path: monitoring/data
aggregated_data_branch: monitoring-aggregated-data
aggregated_data_path: monitoring/aggregated_data
monitoring_properties: monitoring/monitoring.properties
push_script: monitoring/push_with_rebase.sh

jobs:
setup_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Create matrix
id: set-matrix
run: |
arr=$(echo [$(seq -s , ${{ inputs.runners }})])
echo "::set-output name=matrix::$arr"
echo $arr

build_and_collect_statistics:
needs: setup_matrix
continue-on-error: true
strategy:
matrix:
value: ${{ fromJson(needs.setup_matrix.outputs.matrix) }}
runs-on: ubuntu-20.04
container: unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
steps:
- name: Install git
run: |
apt-get upgrade -y
apt-get update -y
apt-get install git -y
git config --global --add safe.directory $(pwd)

- name: Checkout repository
uses: actions/checkout@v3

- name: Checkout monitoring data
uses: actions/checkout@v3
with:
ref: ${{ env.data_branch }}
path: ${{ env.data_path }}

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Build and run monitoring UTBot Java
run: |
gradle :utbot-junit-contest:monitoringJar
for i in $(seq ${{ inputs.run_number }})
do
java -jar \
-Dutbot.monitoring.settings.path=$monitoring_properties \
utbot-junit-contest/build/libs/monitoring.jar \
stats-$i.json
mv logs/utbot.log logs/utbot-$i.log
done

- name: Get current date
id: date
run: |
echo "::set-output name=date::$(date +'%Y-%m-%d')"
echo "::set-output name=timestamp::$(date +%s)"
echo "::set-output name=last_month::$(date --date='last month' +%s)"

- name: Get metadata
id: metadata
run: |
echo "::set-output name=commit::$(git rev-parse HEAD)"
echo "::set-output name=short_commit::$(git rev-parse --short HEAD)"
echo "::set-output name=branch::$(git name-rev --name-only HEAD)"
echo "::set-output name=build::$(date +'%Y.%-m')"

- name: Insert metadata
shell: bash
run: |
OUT_FILE="$data_path/data-$branch-$date-$timestamp-$short_commit-${{ matrix.value }}.json"
INPUTS=($(seq ${{ inputs.run_number }}))
INPUTS=(${INPUTS[@]/#/stats-})
INPUTS=(${INPUTS[@]/%/.json})
INPUTS=${INPUTS[@]}
echo $INPUTS
python monitoring/insert_metadata.py \
--stats_file $INPUTS \
--output_file "$OUT_FILE" \
--commit $commit \
--branch $branch \
--build "$build" \
--timestamp $timestamp \
--source_type "github-action" \
--source_id $run_id
env:
date: ${{ steps.date.outputs.date }}
timestamp: ${{ steps.date.outputs.timestamp }}
commit: ${{ steps.metadata.outputs.commit }}
short_commit: ${{ steps.metadata.outputs.short_commit }}
branch: ${{ steps.metadata.outputs.branch }}
build: ${{ steps.metadata.outputs.build }}
run_id: ${{ github.run_id }}-${{ matrix.value }}

- name: Commit and push statistics
run: |
chmod +x $push_script
./$push_script
env:
target_branch: ${{ env.data_branch }}
target_directory: ${{ env.data_path }}
message: ${{ inputs.message_prefix }}-${{ steps.date.outputs.date }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload logs
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: logs-${{ matrix.value }}
path: logs/

aggregate:
needs: build_and_collect_statistics
if: ${{ inputs.aggregate }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Checkout monitoring data
uses: actions/checkout@v3
with:
ref: ${{ env.data_branch }}
path: ${{ env.data_path }}

- name: Checkout aggregated monitoring data
uses: actions/checkout@v3
with:
ref: ${{ env.aggregated_data_branch }}
path: ${{ env.aggregated_data_path }}

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Get current date
id: date
run: |
echo "::set-output name=date::$(date +'%Y-%m-%d')"
echo "::set-output name=timestamp::$(date +%s)"
echo "::set-output name=last_month::$(date --date='last month' +%s)"

- name: Build aggregated data (last month)
run: |
OUT_FILE=$aggregated_data_path/aggregated-data-$date.json
python monitoring/build_aggregated_data.py \
--input_data_dir $data_path \
--output_file $OUT_FILE \
--timestamp_from $timestamp_from \
--timestamp_to $timestamp
env:
date: ${{ steps.date.outputs.date }}
timestamp: ${{ steps.date.outputs.timestamp }}
timestamp_from: ${{ steps.date.outputs.last_month }}

- name: Commit and push aggregated statistics
run: |
chmod +x $push_script
./$push_script
env:
target_branch: ${{ env.aggregated_data_branch }}
target_directory: ${{ env.aggregated_data_path }}
message: ${{ inputs.message_prefix }}-${{ steps.date.outputs.date }}
github_token: ${{ secrets.GITHUB_TOKEN }}
123 changes: 8 additions & 115 deletions .github/workflows/night-statistics-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,119 +4,12 @@ on:
schedule:
- cron: '0 0 * * *'

env:
data_branch: monitoring-data
data_path: monitoring/data
aggregated_data_branch: monitoring-aggregated-data
aggregated_data_path: monitoring/aggregated_data
monitoring_properties: monitoring/monitoring.properties
output_stats: stats.json

jobs:
build_and_run_monitoring:
runs-on: ubuntu-20.04
container: unittestbot/java-env:java11-zulu-jdk-fx-gradle7.4.2-kotlinc1.7.0
steps:
- name: Install git
run: |
apt-get upgrade -y
apt-get update -y
apt-get install git -y
git config --global --add safe.directory $(pwd)

- name: Checkout main
uses: actions/checkout@v3

- name: Checkout monitoring data
uses: actions/checkout@v3
with:
ref: ${{ env.data_branch }}
path: ${{ env.data_path }}

- name: Checkout aggregated monitoring data
uses: actions/checkout@v3
with:
ref: ${{ env.aggregated_data_branch }}
path: ${{ env.aggregated_data_path }}

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Build and run monitoring UTBot Java
run: |
gradle :utbot-junit-contest:monitoringJar
java -jar \
-Dutbot.monitoring.settings.path=$monitoring_properties \
utbot-junit-contest/build/libs/monitoring.jar \
$output_stats

- name: Get current date
id: date
run: |
echo "::set-output name=date::$(date +'%Y-%m-%d')"
echo "::set-output name=timestamp::$(date +%s)"
echo "::set-output name=last_month::$(date --date='last month' +%s)"

- name: Get metadata
id: metadata
run: |
echo "::set-output name=commit::$(git rev-parse HEAD)"
echo "::set-output name=short_commit::$(git rev-parse --short HEAD)"
echo "::set-output name=branch::$(git name-rev --name-only HEAD)"
echo "::set-output name=build::$(date +'%Y.%-m')"

- name: Insert metadata
run: |
python monitoring/insert_metadata.py \
--stats_file $output_stats \
--output_file "$data_path/data-$branch-$date-$timestamp-$short_commit.json" \
--commit $commit \
--branch $branch \
--build "$build" \
--timestamp $timestamp \
--source_type "github-action" \
--source_id $run_id
env:
date: ${{ steps.date.outputs.date }}
timestamp: ${{ steps.date.outputs.timestamp }}
commit: ${{ steps.metadata.outputs.commit }}
short_commit: ${{ steps.metadata.outputs.short_commit }}
branch: ${{ steps.metadata.outputs.branch }}
build: ${{ steps.metadata.outputs.build }}
run_id: ${{ github.run_id }}

- name: Build aggregated data (last month)
run: |
python monitoring/build_aggregated_data.py \
--input_data_dir $data_path \
--output_file $aggregated_data_path/aggregated-data-$date.json \
--timestamp_from $timestamp_from \
--timestamp_to $timestamp
env:
date: ${{ steps.date.outputs.date }}
timestamp: ${{ steps.date.outputs.timestamp }}
timestamp_from: ${{ steps.date.outputs.last_month }}

- name: Commit and push statistics
uses: actions-js/push@master
with:
branch: ${{ env.data_branch }}
message: 'night-monitoring-${{ steps.date.outputs.date }}'
directory: ${{ env.data_path }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Commit and push aggregated statistics
uses: actions-js/push@master
with:
branch: ${{ env.aggregated_data_branch }}
message: 'night-monitoring-${{ steps.date.outputs.date }}'
directory: ${{ env.aggregated_data_path }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload logs
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: logs
path: logs/utbot.log
run_monitoring:
uses: ./.github/workflows/collect-statistics.yml
secrets: inherit
with:
runners: 3
run_number: 1
message_prefix: night-monitoring
aggregate: true
10 changes: 4 additions & 6 deletions monitoring/insert_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ def build_targets(stats_array: List[dict]) -> List[dict]:

def insert_metadata(args: argparse.Namespace) -> dict:
"""
Collect metadata and statistics from specified file and merge them into result
Collect metadata and statistics from specified files and merge them into result
:param args: parsed program arguments
:return: dictionary with statistics and metadata
"""
stats_array = load(args.stats_file)
if stats_array is None:
raise FileNotFoundError("File with stats does not exist!")
stats_array = [item for f in args.stats_file for item in load(f)]
result = {
'version': JSON_VERSION,
'targets': build_targets(stats_array),
Expand All @@ -126,8 +124,8 @@ def insert_metadata(args: argparse.Namespace) -> dict:
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--stats_file', required=True,
help='file with statistics', type=str
'--stats_file', required=True, nargs='+',
help='files (one or more) with statistics', type=str
)
parser.add_argument(
'--commit', help='commit hash', type=str
Expand Down
2 changes: 1 addition & 1 deletion monitoring/monitoring.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project=guava
classTimeoutMillis=20
runTries=3
runTries=1
runTimeoutMinutes=20
Loading