Skip to content

garbage collector system overhaul and extras #1724

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

Merged
merged 68 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
fcd3ca9
guests without projects are now removed
Aug 20, 2020
1efac17
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Aug 20, 2020
0afaefa
makes no senso for GUEST users
Aug 20, 2020
4620bd8
Merge remote-tracking branch 'upstream/master' into gc-remove-guests-…
Aug 21, 2020
ae7e470
garbage collection should result more descirptive
Aug 21, 2020
d5e33f8
added more notes
Aug 21, 2020
3a2f83a
added more notes
Aug 21, 2020
9f15f2c
minor refactor
Aug 21, 2020
6f2aaf5
fixed error
Aug 21, 2020
7dfb928
functions have been split into smaller self contained entities
Aug 21, 2020
dbbbb48
removed outdated description
Aug 21, 2020
7a16518
moved code blocks up
Aug 21, 2020
bba42b6
removed unused function
Aug 21, 2020
53415cb
moved function position
Aug 21, 2020
076f238
Merge remote-tracking branch 'upstream/master' into gc-remove-guests-…
Aug 31, 2020
67be62d
changed import name
Aug 31, 2020
57b5092
gc takes into consideration access rights when removing users
Sep 1, 2020
575e036
fixed pylint issues
Sep 1, 2020
519646b
removed unused code
Sep 1, 2020
59a457f
refactored code
Sep 2, 2020
1259919
updated changelog
Sep 2, 2020
2101786
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 2, 2020
e47fb02
added link in changelog
Sep 2, 2020
a3bfc58
PRs are now linked in the changelog
Sep 2, 2020
55ce9e7
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 2, 2020
685c5f2
marking container nvidia-smi for autoremove
Sep 3, 2020
3e7578a
during testing aiohttp logs are displayed
Sep 4, 2020
6e78b49
removed unencessary comments
Sep 7, 2020
caa3f6b
fixed issue which caused silent 401
Sep 7, 2020
3e748ea
replaced with a more updated version
Sep 8, 2020
ce07201
added empty_project_data and trapped a new error
Sep 8, 2020
5eeeb76
updated dependencies
Sep 8, 2020
d635e70
removed unused import
Sep 8, 2020
8660d17
added tests for garbage collection
Sep 8, 2020
e94a793
fixed some dependencies
Sep 8, 2020
8fa678c
conftest refactoring
Sep 8, 2020
a3e1b30
now creates a template db to be used between tests
Sep 8, 2020
3151e22
tests correctly run in integration testing
Sep 9, 2020
717e2a9
refactored tests
Sep 9, 2020
d4e5179
fixed an issue with project ownership detection
Sep 9, 2020
a9d8124
implemented t6
Sep 9, 2020
673a7ff
implemented t7
Sep 9, 2020
8d80661
implemented t8
Sep 9, 2020
6f15ca1
implemented t9
Sep 9, 2020
6764f59
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 9, 2020
5a086e4
updated changelog
Sep 9, 2020
36bbae6
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 9, 2020
49b8a1c
removed usless test module
Sep 9, 2020
d33f963
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 10, 2020
1d9b59a
@sanderegg suggestion
Sep 10, 2020
081b052
@sanderegg should adds clarity to the reasoning
Sep 10, 2020
cfe17a2
@sanderegg renaming function to something more clear
Sep 10, 2020
8d7889a
removed typo
Sep 10, 2020
acb935d
@sanderegg removed redundant comments
Sep 10, 2020
1a77741
@sanderegg refactored fixture into a function
Sep 10, 2020
07793aa
fixing out more typos
Sep 10, 2020
cb03419
minor refactor and cleanup
Sep 10, 2020
3853210
introduce tests to handle multiple user deletion
Sep 10, 2020
28c1d9d
removed uneeded comment
Sep 10, 2020
345e41e
used @pcrespov suggestion and refactored
Sep 11, 2020
f070c1f
reverting depenencies for fugure upgrade @pcrespov
Sep 11, 2020
cca0789
moved in a more adequate palce
Sep 11, 2020
fc10058
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 11, 2020
1e2007a
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 11, 2020
e7458e4
changed outdated pytest fixture
Sep 14, 2020
59686c6
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 15, 2020
5bb56b9
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 15, 2020
7d5a2a3
Merge branch 'master' into gc-remove-guests-with-no-projects
GitHK Sep 15, 2020
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
73 changes: 38 additions & 35 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ FIXME: Compare shows single commit. SEE https://github.com/ITISFoundation/osparc
### Added

- Started this *human-readable* CHANGELOG
- ``migration`` service that discovers postgres service and upgrades main database (#1714)
- Every group can register official classifiers for studies and services. Diplayed as a tree in UI (#1670, #1719, #1722)
- ``migration`` service that discovers postgres service and upgrades main database [#1714](https://github.com/ITISFoundation/osparc-simcore/pull/1714)
- Every group can register official classifiers for studies and services. Diplayed as a tree in UI [#1670](https://github.com/ITISFoundation/osparc-simcore/pull/1670), [#1719](https://github.com/ITISFoundation/osparc-simcore/pull/1719) , [#1722](https://github.com/ITISFoundation/osparc-simcore/pull/1722)
- GC tests are run in isolation with a template database [#1724](https://github.com/ITISFoundation/osparc-simcore/pull/1724)

### Changed

- Speedup testing by splitting webserver (#1711)
- Speedup testing by splitting webserver [#1711](https://github.com/ITISFoundation/osparc-simcore/pull/1711)
- Refactored garbage collector and added tests [#1724](https://github.com/ITISFoundation/osparc-simcore/pull/1724)
- Logs are now displayed during testing [#1724](https://github.com/ITISFoundation/osparc-simcore/pull/1724)

<!-- ### Deprecated -->
<!-- ### Removed -->
Expand All @@ -28,45 +31,45 @@ FIXME: Compare shows single commit. SEE https://github.com/ITISFoundation/osparc
## [0.0.25] - 2020-08-04

### Added
- add traefik endpoint to api-gateway (#1555)
- Shared project concurrency (frontend) (#1591)
- Homogenize studies and services (#1569)
- add traefik endpoint to api-gateway [#1555](https://github.com/ITISFoundation/osparc-simcore/pull/1555)
- Shared project concurrency (frontend) [#1591](https://github.com/ITISFoundation/osparc-simcore/pull/1591)
- Homogenize studies and services [#1569](https://github.com/ITISFoundation/osparc-simcore/pull/1569)
- UI Fine grained access - project locking and notification
- Adds support for GPU scheduling of computational services (#1553)
- Adds support for GPU scheduling of computational services [#1553](https://github.com/ITISFoundation/osparc-simcore/pull/1553)

### Changed
- UI/UX improvements (#1657)
- Improving storage performance (#1659)
- Theming (#1656)
- Reduce cardinality of metrics (#1593)
- UI/UX improvements [#1657](https://github.com/ITISFoundation/osparc-simcore/pull/1657)
- Improving storage performance [#1659](https://github.com/ITISFoundation/osparc-simcore/pull/1659)
- Theming [#1656](https://github.com/ITISFoundation/osparc-simcore/pull/1656)
- Reduce cardinality of metrics [#1593](https://github.com/ITISFoundation/osparc-simcore/pull/1593)

### Fixed
- Platform stability: (#1645)
- Fix, improves and re-activate e2e CI testing (#1594, #1620, #1631, #1600)
- Fixes defaults (#1640)
- Upgrade storage service (#1585, #1586)
- UPgrade catalog service (#1582)
- Fixes on publish studies handling (#1632)
- Invalidate cache before starting a study (#1602)
- Some enhancements and bug fixes (#1608)
- filter studies by name before deleting them (#1629)
- Bugfix/apiserver does not need sslheaders (#1564)
- fix testing if node has gpu support (#1604)
- /study fails 500 (#1570, #1572)
- fix codecov reports (#1568)
- Platform stability: [#1645](https://github.com/ITISFoundation/osparc-simcore/pull/1645)
- Fix, improves and re-activate e2e CI testing [#1594](https://github.com/ITISFoundation/osparc-simcore/pull/1594), [#1620](https://github.com/ITISFoundation/osparc-simcore/pull/1620), [#1631](https://github.com/ITISFoundation/osparc-simcore/pull/1631), [#1600](https://github.com/ITISFoundation/osparc-simcore/pull/1600)
- Fixes defaults [#1640](https://github.com/ITISFoundation/osparc-simcore/pull/1640)
- Upgrade storage service [#1585](https://github.com/ITISFoundation/osparc-simcore/pull/1585), [#1586](https://github.com/ITISFoundation/osparc-simcore/pull/1586)
- UPgrade catalog service [#1582](https://github.com/ITISFoundation/osparc-simcore/pull/1582)
- Fixes on publish studies handling [#1632](https://github.com/ITISFoundation/osparc-simcore/pull/1632)
- Invalidate cache before starting a study [#1602](https://github.com/ITISFoundation/osparc-simcore/pull/1602)
- Some enhancements and bug fixes [#1608](https://github.com/ITISFoundation/osparc-simcore/pull/1608)
- filter studies by name before deleting them [#1629](https://github.com/ITISFoundation/osparc-simcore/pull/1629)
- Bugfix/apiserver does not need sslheaders [#1564](https://github.com/ITISFoundation/osparc-simcore/pull/1564)
- fix testing if node has gpu support [#1604](https://github.com/ITISFoundation/osparc-simcore/pull/1604)
- /study fails 500 [#1570](https://github.com/ITISFoundation/osparc-simcore/pull/1570), [#1572](https://github.com/ITISFoundation/osparc-simcore/pull/1572)
- fix codecov reports [#1568](https://github.com/ITISFoundation/osparc-simcore/pull/1568)

### Security
- Bump yarl from 1.4.2 to 1.5.1 in /packages/postgres-database (#1665)
- Bump ujson from 3.0.0 to 3.1.0 in /packages/service-library (#1664)
- Bump pytest-docker from 0.7.2 to 0.8.0 in /packages/service-library (#1647)
- Bump aiozipkin from 0.6.0 to 0.7.0 in /packages/service-library (#1642)
- Bump lodash from 4.17.15 to 4.17.19 (#1639)
- Maintenance/upgrades test tools (#1628)
- Bugfix/concurent opening projects (#1598)
- Bugfix/allow reading groups anonymous user (#1615)
- Bump docker from 4.2.1 to 4.2.2 in /packages/postgres-database (#1605)
- Bump faker from 4.1.0 to 4.1.1 in /packages/postgres-database (#1573)
- Maintenance/upgrades and tooling (#1546)
- Bump yarl from 1.4.2 to 1.5.1 in /packages/postgres-database [#1665](https://github.com/ITISFoundation/osparc-simcore/pull/1665)
- Bump ujson from 3.0.0 to 3.1.0 in /packages/service-library [#1664](https://github.com/ITISFoundation/osparc-simcore/pull/1664)
- Bump pytest-docker from 0.7.2 to 0.8.0 in /packages/service-library [#1647](https://github.com/ITISFoundation/osparc-simcore/pull/1647)
- Bump aiozipkin from 0.6.0 to 0.7.0 in /packages/service-library [#1642](https://github.com/ITISFoundation/osparc-simcore/pull/1642)
- Bump lodash from 4.17.15 to 4.17.19 [#1639](https://github.com/ITISFoundation/osparc-simcore/pull/1639)
- Maintenance/upgrades test tools [#1628](https://github.com/ITISFoundation/osparc-simcore/pull/1628)
- Bugfix/concurent opening projects [#1598](https://github.com/ITISFoundation/osparc-simcore/pull/1598)
- Bugfix/allow reading groups anonymous user [#1615](https://github.com/ITISFoundation/osparc-simcore/pull/1615)
- Bump docker from 4.2.1 to 4.2.2 in /packages/postgres-database [#1605](https://github.com/ITISFoundation/osparc-simcore/pull/1605)
- Bump faker from 4.1.0 to 4.1.1 in /packages/postgres-database [#1573](https://github.com/ITISFoundation/osparc-simcore/pull/1573)
- Maintenance/upgrades and tooling [#1546](https://github.com/ITISFoundation/osparc-simcore/pull/1546)


---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
discovered_cache = os.path.expanduser("~/.simcore_postgres_database_cache.json")

log = logging.getLogger("root")
fileConfig(default_ini)

if __name__ == "__main__":
# swallows up all log messages from tests
# only enable it during cli invocation
fileConfig(default_ini)


def safe(if_fails_return=False):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from logging.config import fileConfig

from alembic import context
Expand All @@ -12,7 +11,11 @@

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

if __name__ == "__main__":
# swallows up all log messages from tests
# only enable it during cli invocation
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
Expand All @@ -38,9 +41,7 @@ def run_migrations_offline():
"""
# pylint: disable=no-member
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -61,9 +62,7 @@ def run_migrations_online():
)

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
context.configure(connection=connection, target_metadata=target_metadata)

with context.begin_transaction():
context.run_migrations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import uuid as uuidlib
from typing import Dict
from simcore_service_webserver.utils import now_str

from aiohttp import web

Expand All @@ -32,6 +33,19 @@
]


def empty_project_data():
return {
"uuid": f"project-{uuidlib.uuid4()}",
"name": "Empty name",
"description": "some description of an empty project",
"prjOwner": "I'm the empty project owner, hi!",
"creationDate": now_str(),
"lastChangeDate": now_str(),
"thumbnail": "",
"workbench": {},
}


def load_data(name):
with resources.stream(name) as fp:
return json.load(fp)
Expand Down Expand Up @@ -62,7 +76,7 @@ async def create_project(
try:
uuidlib.UUID(project_data["uuid"])
assert new_project["uuid"] == project_data["uuid"]
except ValueError:
except (ValueError, AssertionError):
# in that case the uuid gets replaced
assert new_project["uuid"] != project_data["uuid"]
project_data["uuid"] = new_project["uuid"]
Expand Down Expand Up @@ -90,7 +104,7 @@ def __init__(
clear_all=True,
user_id=None,
*,
force_uuid=False
force_uuid=False,
):
self.params = params
self.user_id = user_id
Expand Down
122 changes: 117 additions & 5 deletions packages/pytest-simcore/src/pytest_simcore/postgres_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,134 @@
# pylint:disable=unused-argument
# pylint:disable=redefined-outer-name

import os
from typing import Dict
import logging
import asyncio
import os
from typing import Dict, List

import pytest
import simcore_postgres_database.cli as pg_cli
import sqlalchemy as sa
import tenacity
from sqlalchemy.orm import sessionmaker

import simcore_postgres_database.cli as pg_cli
from simcore_postgres_database.models.base import metadata
from sqlalchemy.orm import sessionmaker

from .helpers.utils_docker import get_service_published_port

log = logging.getLogger(__name__)

TEMPLATE_DB_TO_RESTORE = "template_simcore_db"


def execute_queries(
postgres_engine: sa.engine.Engine,
sql_statements: List[str],
ignore_errors: bool = False,
) -> None:
"""runs the queries in the list in order"""
with postgres_engine.connect() as con:
for statement in sql_statements:
try:
con.execution_options(autocommit=True).execute(statement)
except Exception as e: # pylint: disable=broad-except
# when running tests initially the TEMPLATE_DB_TO_RESTORE dose not exist and will cause an error
# which can safely be ignored. The debug message is here to catch future errors which and
# avoid time wasting
log.debug("SQL error which can be ignored %s", str(e))


def create_template_db(postgres_dsn: Dict, postgres_engine: sa.engine.Engine) -> None:
# create a template db, the removal is necessary to allow for the usage of --keep-docker-up
queries = [
# disconnect existing users
f"""
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity
WHERE pg_stat_activity.datname = '{postgres_dsn["database"]}' AND pid <> pg_backend_pid();
""",
# drop template database
f"ALTER DATABASE {TEMPLATE_DB_TO_RESTORE} is_template false;",
f"DROP DATABASE {TEMPLATE_DB_TO_RESTORE};",
# create template database
"""
CREATE DATABASE {template_db} WITH TEMPLATE {original_db} OWNER {db_user};
""".format(
template_db=TEMPLATE_DB_TO_RESTORE,
original_db=postgres_dsn["database"],
db_user=postgres_dsn["user"],
),
]
execute_queries(postgres_engine, queries, ignore_errors=True)


def drop_template_db(postgres_engine: sa.engine.Engine) -> None:
# remove the template db
queries = [
# drop template database
f"ALTER DATABASE {TEMPLATE_DB_TO_RESTORE} is_template false;",
f"DROP DATABASE {TEMPLATE_DB_TO_RESTORE};",
]
execute_queries(postgres_engine, queries)


@pytest.fixture(scope="module")
def loop(request):
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()


@pytest.fixture(scope="module")
def postgres_with_template_db(
postgres_db: sa.engine.Engine, postgres_dsn: Dict, postgres_engine: sa.engine.Engine
) -> sa.engine.Engine:
create_template_db(postgres_dsn, postgres_engine)
yield postgres_engine
drop_template_db(postgres_engine)


@pytest.fixture
def drop_db_engine(postgres_dsn: Dict) -> sa.engine.Engine:
postgres_dsn_copy = postgres_dsn.copy() # make a copy to change these parameters
postgres_dsn_copy["database"] = "postgres"
dsn = "postgresql://{user}:{password}@{host}:{port}/{database}".format(
**postgres_dsn_copy
)
return sa.create_engine(dsn, isolation_level="AUTOCOMMIT")


@pytest.fixture
def database_from_template_before_each_function(
postgres_dsn: Dict, drop_db_engine: sa.engine.Engine, postgres_db
) -> None:
"""
Will recrate the db before running each test.

**Note: must be implemented in the module where the the
`postgres_with_template_db` is used and mark autouse=True**

It is possible to drop the application database by ussing another one like
the posgtres database. The db will be recrated from the previously created template

The postgres_db fixture is required for the template database to be created.
"""

queries = [
# terminate existing connections to the database
f"""
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity
WHERE pg_stat_activity.datname = '{postgres_dsn["database"]}';
""",
# drop database
f"DROP DATABASE {postgres_dsn['database']};",
# create from template database
f"CREATE DATABASE {postgres_dsn['database']} TEMPLATE template_simcore_db;",
]

execute_queries(drop_db_engine, queries)

yield
# do nothing on teadown


@pytest.fixture(scope="module")
def postgres_dsn(docker_stack: Dict, devel_environ: Dict) -> Dict[str, str]:
Expand Down
Loading