Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flaky tests + increase runner size when building docker image #4502

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
build-engine-docker-image-and-publish-to-dockerhub:
name: Build engine Docker image and publish to Dockerhub
runs-on: ubuntu-latest
runs-on: ubuntu-latest-16-cores
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to see if I can speed up building of our multi-platform Docker image (linux/arm64 + linux/amd64) by just throwing more resources at it.. it seems that installing the Python deps on linux/arm64 takes ~400s

alternative here would be to build the different image variants on different hardware and publish the image manifest separately (something like this, seems much more involved...)

# These permissions are needed to assume roles from Github's OIDC.
# https://github.com/grafana/shared-workflows/tree/main/actions/build-push-to-dockerhub
permissions:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linting-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:

unit-test-backend-mysql-rabbitmq:
name: "Backend Tests: MySQL + RabbitMQ (RBAC enabled: ${{ matrix.rbac_enabled }})"
runs-on: ubuntu-latest-8-cores
runs-on: ubuntu-latest-16-cores
strategy:
matrix:
rbac_enabled: ["True", "False"]
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:

unit-test-backend-postgresql-rabbitmq:
name: "Backend Tests: PostgreSQL + RabbitMQ (RBAC enabled: ${{ matrix.rbac_enabled }})"
runs-on: ubuntu-latest-8-cores
runs-on: ubuntu-latest-16-cores
strategy:
matrix:
rbac_enabled: ["True", "False"]
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:

unit-test-backend-sqlite-redis:
name: "Backend Tests: SQLite + Redis (RBAC enabled: ${{ matrix.rbac_enabled }})"
runs-on: ubuntu-latest-8-cores
runs-on: ubuntu-latest-16-cores
strategy:
matrix:
rbac_enabled: ["True", "False"]
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/snyk-security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ jobs:
synk-security-scan:
name: Snyk security scan
runs-on: ubuntu-latest
# see this PR regarding the permissions needed for this workflow
# https://github.com/snyk/actions/pull/79
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
Comment on lines +10 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scratch that, still not working.. opened a separate issue to fix this

#4503

steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand Down
21 changes: 15 additions & 6 deletions engine/apps/alerts/tests/test_escalation_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,24 @@ def test_next_escalation_policy_snapshot(escalation_snapshot_test_setup):

@pytest.mark.django_db
@pytest.mark.parametrize(
"next_step_eta,expected",
"timedelta,time_in_past,expected",
[
(None, None),
(timezone.now() - timezone.timedelta(weeks=50), False),
(timezone.now() - timezone.timedelta(minutes=4), True),
(timezone.now() + timezone.timedelta(minutes=4), True),
Comment on lines -189 to -191
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fact that timezone.now was being invoked before the actual test was running was causing some funkiness w/ pytest-xdist

(None, None, None),
(timezone.timedelta(weeks=50), True, False),
(timezone.timedelta(minutes=4), True, True),
(timezone.timedelta(minutes=4), False, True),
],
)
def test_next_step_eta_is_valid(escalation_snapshot_test_setup, next_step_eta, expected) -> None:
def test_next_step_eta_is_valid(escalation_snapshot_test_setup, timedelta, time_in_past, expected) -> None:
now = timezone.now()

if timedelta is None:
next_step_eta = None
elif time_in_past:
next_step_eta = now - timedelta
else:
next_step_eta = now + timedelta

alert_group, _, _, _ = escalation_snapshot_test_setup
escalation_snapshot = alert_group.escalation_snapshot

Expand Down
3 changes: 2 additions & 1 deletion engine/apps/api/tests/test_user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from unittest import mock
from unittest.mock import Mock, patch

import pytest
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_current_user(
"user": user.username,
}
},
"cloud_connection_status": 0,
"cloud_connection_status": mock.ANY,
"notification_chain_verbal": {"default": "", "important": ""},
"slack_user_identity": None,
"avatar": user.avatar_url,
Expand Down
8 changes: 7 additions & 1 deletion engine/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ banned-modules =
[pytest]
# https://pytest-django.readthedocs.io/en/latest/configuring_django.html#order-of-choosing-settings
# https://pytest-django.readthedocs.io/en/latest/database.html
# dist=load = "load balance by sending any pending test to any available environment"
# https://pytest-xdist.readthedocs.io/en/stable/distribution.html#running-tests-across-multiple-cpus
#
# dist=loadscope
# Tests are grouped by module for test functions and by class for test methods.
# Groups are distributed to available workers as whole units. This guarantees that all tests in a group run in the same
# process. This can be useful if you have expensive module-level or class-level fixtures. Grouping by class takes
# priority over grouping by module.
addopts = -n auto --dist=loadscope --no-migrations --color=yes --showlocals
# https://pytest-django.readthedocs.io/en/latest/faq.html#my-tests-are-not-being-found-why
python_files = tests.py test_*.py *_tests.py
Loading