Skip to content

Commit

Permalink
Merge branch 'main' into merge_release/2.147.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas1312 authored Oct 9, 2023
2 parents 7f6a919 + 9fdf047 commit 535912d
Show file tree
Hide file tree
Showing 72 changed files with 2,962 additions and 1,130 deletions.
87 changes: 46 additions & 41 deletions .github/scripts/upload_test_stats_datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import time
import zipfile
from collections import defaultdict
from dataclasses import dataclass
from datetime import datetime
from typing import Dict, List, Literal, Optional
Expand All @@ -17,12 +18,27 @@
# https://docs.datadoghq.com/developers/guide/what-best-practices-are-recommended-for-naming-metrics-and-tags/#rules-and-best-practices-for-naming-metrics
# map the test name to the metrics name on datadog
TESTS_TO_PLOT_ON_DATADOG_MAP = {
"tests/e2e/test_notebooks.py::test_all_recipes[tests/e2e/plugin_workflow.ipynb]": (
"plugin_workflow_ipynb"
),
"tests/e2e/test_notebooks.py::test_all_recipes[tests/e2e/import_predictions.ipynb]": (
"import_predictions_ipynb"
),
"tests/e2e/test_notebooks.py::test_all_recipes[recipes/export_a_kili_project.ipynb]": (
"export_a_kili_project_ipynb"
),
"tests/e2e/test_notebooks.py::test_all_recipes[recipes/importing_video_assets.ipynb]": (
"importing_video_assets_ipynb"
),
"tests/e2e/test_copy_project.py::test_copy_project_e2e_video": "copy_project_e2e_video",
"tests/e2e/test_copy_project.py::test_copy_project_e2e_with_ocr_metadata": (
"copy_project_e2e_with_ocr_metadata"
),
"tests/e2e/test_projects.py::test_create_project": "create_project",
"tests/e2e/test_mutations_label.py::test_append_many_labels": "append_many_labels",
"tests/e2e/test_mutations_asset.py::test_append_many_assets": "append_many_assets",
"tests/e2e/test_mutations_asset.py::test_send_back_to_queue": "send_back_to_queue",
"tests/e2e/test_mutations_asset.py::test_delete_many_from_dataset": "delete_many_from_dataset",
"tests/e2e/test_mutations_asset.py::test_change_asset_external_ids": (
"change_asset_external_ids"
),
}

OWNER = "kili-technology"
Expand All @@ -38,9 +54,6 @@
url = f"https://api.github.com/repos/{OWNER}/{REPO}/actions/workflows/{WORKFLOW}/runs?per_page={BATCH_SIZE}"


PYTEST_TEST_DURATIONS_REGEX_PATTERN = r"=+ slowest \d+ durations =+"


def get_and_dump_data() -> None:
"""Fetch data from github ci logs and dump in csv files."""
workflow_runs_dict = get_workflow_runs_from_github()
Expand Down Expand Up @@ -117,7 +130,7 @@ def parse_workflow_runs(workflow_runs: List[Dict]):

with z.open(filename) as f:
full_logs = f.read().decode("utf-8")
if re.search(PYTEST_TEST_DURATIONS_REGEX_PATTERN, full_logs):
if re.search(r"=+ slowest .*durations =+", full_logs):
run_id = run_json["id"]
test_durations.extend(get_test_durations_from_logs(full_logs, run_id))
git_ref = get_git_ref_from_logs(full_logs)
Expand Down Expand Up @@ -166,44 +179,35 @@ def get_test_durations_from_logs(logs: str, run_id: str) -> List[TestDuration]:
"""Extract the test durations from the logs of a workflow run."""
logs_split = [l for l in logs.split("\n") if l]

test_name_to_infos = {}
test_name_to_infos = defaultdict(list)

# find all matches
# Twice, one for e2e tests, the other one for notebook tests.
for match in re.finditer(PYTEST_TEST_DURATIONS_REGEX_PATTERN, logs):
assert match is not None
index = match.start()
nb_tests_in_log = int(match.group().split(" ")[2])
lines = logs[index:].splitlines()
for line in lines:
if nb_tests_in_log == 0:
break
if "FAILED" in line or "ERROR" in line or "PASSED" in line:
for line in logs_split:
if any(x in line for x in ("FAILED", "ERROR", "PASSED", "SKIPPED")):
continue
if "s " in line and "tests/e2e" in line and ("call" in line or "setup" in line):
split_ = line.split(" ")
split_ = [s for s in split_ if s]
try:
_, duration, call_or_setup, test_name = split_
except ValueError:
print("Cannot parse line: ", line)
continue
if "test" in line and ("call" in line or "setup" in line):
split_ = line.split(" ")
split_ = [s for s in split_ if s]
try:
_, duration, call_or_setup, test_name = split_
except ValueError:
print("Cannot parse line: ", line)
continue

lines_matching_test_name = [
l for l in logs_split if f" {test_name} \x1b[32mPASSED\x1b[0m" in l
]
if len(lines_matching_test_name) == 0:
# print("Cannot find test finished date for test: ", test_name)
continue
if len(lines_matching_test_name) > 1:
raise ValueError(f"Found too many matches: {lines_matching_test_name}")
lines_matching_test_name = [
l for l in logs_split if f" {test_name} \x1b[32mPASSED\x1b[0m" in l
]
if len(lines_matching_test_name) == 0:
# print("Cannot find test finished date for test: ", test_name)
continue
if len(lines_matching_test_name) > 1:
raise ValueError(f"Found too many matches: {lines_matching_test_name}")

date = datetime.strptime(
lines_matching_test_name[0].split(" ")[0][:19], r"%Y-%m-%dT%H:%M:%S"
)
date = datetime.strptime(
lines_matching_test_name[0].split(" ")[0][:19], r"%Y-%m-%dT%H:%M:%S"
)

test_name_to_infos[test_name] = (date, call_or_setup, duration)
nb_tests_in_log -= 1
test_name_to_infos[test_name].append((date, call_or_setup, duration))

return [
TestDuration(
Expand All @@ -213,7 +217,8 @@ def get_test_durations_from_logs(logs: str, run_id: str) -> List[TestDuration]:
date=date,
run_id=run_id,
)
for test_name, (date, call_or_setup, duration) in test_name_to_infos.items()
for test_name, test_entries in test_name_to_infos.items()
for (date, call_or_setup, duration) in test_entries
]


Expand Down Expand Up @@ -302,7 +307,7 @@ def upload_to_datadog(df: pd.DataFrame) -> None:

short_test_name = TESTS_TO_PLOT_ON_DATADOG_MAP[test_name]
points = sorted(zip(timestamps, durations), key=lambda x: x[0])
datadog_metric_name = f"sdk.tests.{short_test_name}.duration"
datadog_metric_name = f"sdk.tests.{short_test_name}.duration_seconds"

print("\nSending metric to datadog: ", datadog_metric_name)
print(points)
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

get_sdk_version_from_pyproject_toml() {
sdk_version=$(cat pyproject.toml | grep version | cut -d ' ' -f 3 | sed -r s,"^\"(.*)\"$","\1",)
sdk_version=$(cat pyproject.toml | grep "^version" | cut -d '"' -f 2)
echo "$sdk_version"
}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bump_commit_release_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
cache: "pip"

- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Pylint test
strategy:
matrix:
python-version: ["3.8", "3.11"]
python-version: ['3.8', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["3.8", "3.11"]
version: ['3.8', '3.12']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand All @@ -62,7 +62,7 @@ jobs:
- os: windows-latest
python-version: 3.8
- os: ubuntu-latest
python-version: 3.11
python-version: 3.12
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/create_draft_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ on:
required: true
type: string
default: "X.XXX.0"
checkAgainstLatestRelease:
description: >
"Check that the release version is greater than the latest release on github.
If not, the workflow will fail.
Enter 'true' to check against the latest release on github, 'false' otherwise:"
required: true
type: boolean
default: true

jobs:
create_draft_release:
Expand Down Expand Up @@ -54,9 +62,11 @@ jobs:
# make sure release_version is greater than last github release
latest_release=$(get_last_release_tag_github)
echo "Latest release: $latest_release"
if ! [[ $(version_to_int "$release_version") -gt $(version_to_int "$latest_release") ]]; then
echo "The release you are trying to create ($release_version) is older than the latest release on github ($latest_release)"
exit 1
if [[ ${{ inputs.checkAgainstLatestRelease }} == true ]]; then
if ! [[ $(version_to_int "$release_version") -gt $(version_to_int "$latest_release") ]]; then
echo "The release you are trying to create ($release_version) is lower than the latest release on github ($latest_release)"
exit 1
fi
fi
# tag and push the tag
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/datadog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Install dependencies
run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
- os: ubuntu-latest
python-version: 3.8
- os: windows-latest
python-version: 3.11
python-version: 3.12

runs-on: ${{ matrix.os }}
needs: [test_setup]
Expand Down Expand Up @@ -254,8 +254,8 @@ jobs:
- name: E2E tests
id: e2e
if: github.event.inputs.runE2ETests != 'false'
timeout-minutes: 30
run: pytest -ra -sv --color yes --code-highlight yes --durations=0 -vv --ignore tests/e2e/test_notebooks.py tests/e2e
timeout-minutes: 60
run: pytest --timeout=600 -ra -sv --color yes --code-highlight yes --durations=0 -vv --ignore tests/e2e/test_notebooks.py tests/e2e
env:
KILI_API_CLOUD_VISION: ${{ secrets.KILI_API_CLOUD_VISION }}
KILI_API_ENDPOINT: ${{ env.KILI_API_ENDPOINT }}
Expand All @@ -267,9 +267,9 @@ jobs:
- name: Notebook tests
# we don't run notebook tests on push to main
# we run regardless of the outcome of the e2e tests
if: ${{ !cancelled() }} && github.event.inputs.runNotebookTests != 'false' && (github.event_name != 'push' || github.ref_name != 'main') && (steps.e2e.outcome != 'cancelled')
timeout-minutes: 45
run: pytest -ra -sv --color yes --code-highlight yes --durations=0 -vv tests/e2e/test_notebooks.py
if: ${{ !cancelled() && github.event.inputs.runNotebookTests != 'false' && (github.event_name != 'push' || github.ref_name != 'main') && (steps.e2e.outcome != 'cancelled') }}
timeout-minutes: 60
run: pytest --timeout=600 -ra -sv --color yes --code-highlight yes --durations=0 -vv tests/e2e/test_notebooks.py
env:
KILI_API_CLOUD_VISION: ${{ secrets.KILI_API_CLOUD_VISION }}
KILI_API_ENDPOINT: ${{ env.KILI_API_ENDPOINT }}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -13,7 +13,7 @@ repos:
args: [--in-place, --black, --wrap-summaries=0, --wrap-descriptions=0]

- repo: https://github.com/asottile/pyupgrade
rev: v3.13.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -29,7 +29,7 @@ repos:
- --

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.0.292
hooks:
- id: ruff
args:
Expand Down
Loading

0 comments on commit 535912d

Please sign in to comment.