Add trash script for tests history

This commit is contained in:
alesapin 2020-01-23 15:29:08 +03:00
parent 0e906b29e1
commit 36e619ab4b
3 changed files with 168 additions and 0 deletions

View File

@ -0,0 +1,59 @@
## Script for ClickHouse tests history
Allows to view test-suite history for master branch.
## Usage
```bash
$ sudo pip install -r requirements.txt
$ test-history --token 4773293b76c0d3f27fb87cf9ea7e08d370d6e334 --since '2020-01-22 00:00:00' --substr Performance'
+---------------------|---------|--------------------+
| Date | SHA | Performance test |
+=====================+=========+====================+
| 2020-01-22 12:54:59 | 47ffa40 | succes |
+---------------------|---------|--------------------+
| 2020-01-22 13:06:16 | 0d484be | failure |
+---------------------|---------|--------------------+
| 2020-01-22 14:18:34 | 289f169 | succes |
+---------------------|---------|--------------------+
| 2020-01-22 14:27:27 | e357c6f | not run |
+---------------------|---------|--------------------+
| 2020-01-22 15:29:30 | 6cd6b4d | not run |
+---------------------|---------|--------------------+
| 2020-01-22 16:52:26 | 6fc7a82 | not run |
+---------------------|---------|--------------------+
| 2020-01-22 16:55:52 | c683c77 | failure |
+---------------------|---------|--------------------+
| 2020-01-22 16:58:36 | d68f8d1 | pending |
+---------------------|---------|--------------------+
| 2020-01-22 17:59:43 | ba7ab32 | succes |
+---------------------|---------|--------------------+
| 2020-01-22 18:32:38 | eadb902 | failure |
+---------------------|---------|--------------------+
| 2020-01-22 19:11:34 | 8f241ea | succes |
+---------------------|---------|--------------------+
| 2020-01-22 19:56:49 | f0b7422 | failure |
+---------------------|---------|--------------------+
| 2020-01-22 21:26:16 | 55be790 | not run |
+---------------------|---------|--------------------+
| 2020-01-22 22:23:59 | c00636b | not run |
+---------------------|---------|--------------------+
| 2020-01-22 23:09:23 | 8cfe9a4 | failure |
+---------------------|---------|--------------------+
| 2020-01-23 00:10:33 | a02b59f | succes |
+---------------------|---------|--------------------+
| 2020-01-23 05:56:11 | 48b3f33 | failure |
+---------------------|---------|--------------------+
| 2020-01-23 05:56:54 | d807088 | succes |
+---------------------|---------|--------------------+
| 2020-01-23 06:01:48 | 2e84949 | failure |
+---------------------|---------|--------------------+
| 2020-01-23 11:18:19 | b80e3dc | pending |
+---------------------|---------|--------------------+
| 2020-01-23 11:53:30 | 0e906b2 | pending |
+---------------------|---------|--------------------+
```
### Options
Script allows to specify start date for commits range in `'%Y-%m-%d %H:%M:%S'` format with `--since` option, default is three days. Also there is `--substr` option which allows to filter test suites by substring occurrence. Github token is required for script and can be found at https://github.com/settings/tokens.

View File

@ -0,0 +1,3 @@
pygithub==1.43.5
tabulate==0.8.6
termcolor==1.1.0

106
utils/test_history/test-history Executable file
View File

@ -0,0 +1,106 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Note: should work with python 2 and 3
from __future__ import print_function
from github import Github
import datetime
import tabulate
import argparse
from termcolor import colored
import sys
COLORMAP = {
"success": colored("succes", 'green'),
"failure": colored("failure", 'red'),
"error": colored("error", 'red'),
"pending": colored("pending", 'yellow'),
"not run": colored("not run", 'white'),
}
def _filter_statuses(statuses):
"""
Squash statuses to latest state
1. context="first", state="success", update_time=1
2. context="second", state="success", update_time=2
3. context="first", stat="failure", update_time=3
=========>
1. context="second", state="success"
2. context="first", stat="failure"
"""
filt = {}
for status in sorted(statuses, key=lambda x: x.updated_at):
filt[status.context] = status
return filt.values()
def get_filtered_statuses(commit):
return _filter_statuses(commit.get_statuses())
def get_commits(repo, since):
return sorted(repo.get_commits(since=since), key=lambda x: x.commit.author.date)
def process_one_commit(commit):
commit_statuses = get_filtered_statuses(commit)
# very dirty, but don't require additional dependencies
commit_modified = commit.commit.author.date + datetime.timedelta(hours=3)
commit_sha = commit.sha
checks_result = {}
for commit_status in commit_statuses:
state = commit_status.state
check_name = commit_status.context
checks_result[check_name] = state
return commit_sha, commit_modified, checks_result
if __name__ == "__main__":
three_days_ago = datetime.datetime.now() - datetime.timedelta(days=3)
parser = argparse.ArgumentParser("ClickHouse commits history parser")
parser.add_argument("--token", required=True)
parser.add_argument("--since", default=three_days_ago.strftime("%Y-%m-%d %H:%M:%S"))
parser.add_argument("--substr", default="Functional stateful")
args = parser.parse_args()
date_since = datetime.datetime.strptime(args.since, "%Y-%m-%d %H:%M:%S")
gh = Github(args.token)
repo = gh.get_repo('ClickHouse/ClickHouse')
commits = get_commits(repo, date_since)
longest_header = []
all_data = []
for num, commit in enumerate(commits):
commit_sha, commit_modified, check_results = process_one_commit(commit)
mapped_keys = [key for key in check_results.keys() if args.substr in key]
if len(mapped_keys) > len(longest_header):
longest_header = mapped_keys
all_data.append((commit_modified, commit_sha, check_results))
if (num + 1) % 10 == 0:
print("Processed", num + 1, "commits")
longest_header = ["Date", "SHA"] + longest_header
result_data = []
for row in all_data:
current_result = [row[0].strftime("%Y-%m-%d %H:%M:%S"), row[1][0:7]]
for check_name in longest_header[2:]:
if check_name in row[2]:
check_result = row[2][check_name]
else:
check_result = "not run"
if sys.stdout.isatty():
current_result.append(COLORMAP[check_result])
else:
current_result.append(check_result)
result_data.append(current_result)
if sys.stdout.isatty():
longest_header = [colored(h, 'white', attrs=['bold']) for h in longest_header]
print(tabulate.tabulate(result_data, headers=longest_header, tablefmt="grid"))