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

Update general logger #96

Closed
wants to merge 113 commits into from
Closed
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
bfd93b4
general ADR on logging
Polichinel Oct 28, 2024
a3447fb
New ADRs todo
Polichinel Oct 28, 2024
36c01b8
the new yaml - not yet used...
Polichinel Oct 28, 2024
cc38240
the config_log_yaml
Polichinel Oct 28, 2024
6510796
new common_logs dir
Polichinel Oct 28, 2024
0f64d29
changed the central logger
Polichinel Oct 28, 2024
b1c704a
detail
Polichinel Oct 28, 2024
69e0207
catalog ADR initial draft
Oct 29, 2024
daa102a
catalog ADR improve draft
Oct 29, 2024
c9a65ec
catalog ADR change title
Oct 29, 2024
e003b96
Use this to see how the logs look now
Polichinel Oct 30, 2024
f941f46
Updated root level
Polichinel Oct 30, 2024
bff0918
whitspace
Polichinel Oct 30, 2024
4c5069f
fix wandb config object in tests
smellycloud Oct 30, 2024
004f40e
this is better...
Polichinel Oct 30, 2024
856a722
corrected doc string
Polichinel Oct 30, 2024
b389b61
fix wandb config object in tests
smellycloud Oct 30, 2024
b9797ad
Merge branch 'fix_test_eval_metrics' of https://github.com/prio-data/…
smellycloud Oct 30, 2024
7613b4c
general ADR on logging
Polichinel Oct 28, 2024
41bfd51
New ADRs todo
Polichinel Oct 28, 2024
bd77bb8
the new yaml - not yet used...
Polichinel Oct 28, 2024
c9fe3d4
the config_log_yaml
Polichinel Oct 28, 2024
1ec2ce3
new common_logs dir
Polichinel Oct 28, 2024
2e8277a
changed the central logger
Polichinel Oct 28, 2024
3d2511a
detail
Polichinel Oct 28, 2024
221d54b
Use this to see how the logs look now
Polichinel Oct 30, 2024
ef52f58
Updated root level
Polichinel Oct 30, 2024
0fc98d2
whitspace
Polichinel Oct 30, 2024
689fb4d
this is better...
Polichinel Oct 30, 2024
a930a95
corrected doc string
Polichinel Oct 30, 2024
7ca3a10
add modelpath and split by model support
smellycloud Oct 30, 2024
f44180b
initial ADR about production development branches
Oct 30, 2024
26ecde4
Merge branch 'development' into fix_test_eval_metrics
Polichinel Oct 30, 2024
5fedb79
Merge pull request #116 from prio-data/fix_test_eval_metrics
Polichinel Oct 30, 2024
7c4799b
add globalcache failsafe
smellycloud Oct 30, 2024
316f283
cleanup
smellycloud Oct 30, 2024
c24458c
Merge remote-tracking branch 'origin/development' into ADR_production…
Oct 30, 2024
269aeca
Merge remote-tracking branch 'origin/development' into ADR_catalogs
Oct 30, 2024
84fa584
ADR catalogs improvement
Oct 30, 2024
5cdca50
adjusting github acgtion to production-development workflow
Oct 30, 2024
6fc3216
Merge pull request #127 from prio-data/fix_prevent_merge_when_branch_…
Polichinel Oct 30, 2024
d304d21
add new templates for darts models
smellycloud Oct 30, 2024
17f39dd
Merge branch 'development' into ADR_catalogs
Polichinel Oct 30, 2024
4c65b69
cleanup
smellycloud Oct 30, 2024
6d56cad
Merge branch 'ADR_catalogs' of https://github.com/prio-data/views_pip…
Polichinel Oct 30, 2024
a9d888e
Accepted
Polichinel Oct 30, 2024
d680ab0
Merge pull request #126 from prio-data/ADR_catalogs
Polichinel Oct 30, 2024
3733aa7
add new templates for darts models
smellycloud Oct 30, 2024
73b1c09
cleanup
smellycloud Oct 30, 2024
a9f4d87
Merge branch 'add_more_model_templates' of https://github.com/prio-da…
smellycloud Oct 30, 2024
7067ebd
In anticipation
Polichinel Oct 30, 2024
8c5ec5f
Merge branch 'development' into ADR_production_development_branches
Polichinel Oct 30, 2024
3e07ab9
Merge pull request #125 from prio-data/ADR_production_development_bra…
Polichinel Oct 30, 2024
bdfb3e5
general ADR on logging
Polichinel Oct 28, 2024
522edc2
New ADRs todo
Polichinel Oct 28, 2024
d9feb35
the new yaml - not yet used...
Polichinel Oct 28, 2024
7885a44
the config_log_yaml
Polichinel Oct 28, 2024
4f677ea
new common_logs dir
Polichinel Oct 28, 2024
18ac2a6
changed the central logger
Polichinel Oct 28, 2024
d81a152
detail
Polichinel Oct 28, 2024
8cc961f
Use this to see how the logs look now
Polichinel Oct 30, 2024
a1a6673
Updated root level
Polichinel Oct 30, 2024
87d804b
whitspace
Polichinel Oct 30, 2024
172f23b
this is better...
Polichinel Oct 30, 2024
7d752eb
corrected doc string
Polichinel Oct 30, 2024
6ed5564
add modelpath and split by model support
smellycloud Oct 30, 2024
badc619
add globalcache failsafe
smellycloud Oct 30, 2024
a45b630
cleanup
smellycloud Oct 30, 2024
a1a8968
Merge branch 'update_general_logger_modelpath' of https://github.com/…
smellycloud Oct 30, 2024
44ff4c9
Merge remote-tracking branch 'origin/update_general_logger_modelpath'…
Polichinel Oct 30, 2024
3f2b6e4
added warning and critical
Polichinel Oct 30, 2024
b249a6a
And ADR to justify this
Polichinel Oct 30, 2024
c934874
updated with new default level INFO
Polichinel Oct 30, 2024
e97769e
Merge branch 'development' into add_more_model_templates
Polichinel Oct 30, 2024
9ac24f0
Merge pull request #128 from prio-data/add_more_model_templates
Polichinel Oct 30, 2024
99cfe9f
general ADR on logging
Polichinel Oct 28, 2024
a3e8bca
New ADRs todo
Polichinel Oct 28, 2024
3150e34
the new yaml - not yet used...
Polichinel Oct 28, 2024
4abe11c
the config_log_yaml
Polichinel Oct 28, 2024
e84fa24
new common_logs dir
Polichinel Oct 28, 2024
af07de5
changed the central logger
Polichinel Oct 28, 2024
aa03a6e
detail
Polichinel Oct 28, 2024
7f0a34a
Use this to see how the logs look now
Polichinel Oct 30, 2024
4bba63d
Updated root level
Polichinel Oct 30, 2024
35dd16d
whitspace
Polichinel Oct 30, 2024
c27d74d
this is better...
Polichinel Oct 30, 2024
174cac6
corrected doc string
Polichinel Oct 30, 2024
d911e8c
the config_log_yaml
Polichinel Oct 28, 2024
792e830
changed the central logger
Polichinel Oct 28, 2024
79ea54f
Use this to see how the logs look now
Polichinel Oct 30, 2024
824688b
Updated root level
Polichinel Oct 30, 2024
e23bc08
this is better...
Polichinel Oct 30, 2024
6dfc993
add modelpath and split by model support
smellycloud Oct 30, 2024
37a91c2
add globalcache failsafe
smellycloud Oct 30, 2024
c92e17d
cleanup
smellycloud Oct 30, 2024
440234a
the config_log_yaml
Polichinel Oct 28, 2024
8ff4b41
Use this to see how the logs look now
Polichinel Oct 30, 2024
f0b9804
Updated root level
Polichinel Oct 30, 2024
c77e7c2
add modelpath and split by model support
smellycloud Oct 30, 2024
44094de
cleanup
smellycloud Oct 30, 2024
0fc2438
added warning and critical
Polichinel Oct 30, 2024
7a07d43
And ADR to justify this
Polichinel Oct 30, 2024
f30f0d7
updated with new default level INFO
Polichinel Oct 30, 2024
0923537
Merge branch 'update_generel_logger' of https://github.com/prio-data/…
Polichinel Oct 31, 2024
9c2006f
add modelpath and split by model support
smellycloud Oct 30, 2024
f060f31
cleanup
smellycloud Oct 30, 2024
2bfddce
add modelpath and split by model support
smellycloud Oct 30, 2024
eccbb8c
cleanup
smellycloud Oct 30, 2024
e962c1c
Merge branch 'update_generel_logger' of https://github.com/prio-data/…
Polichinel Oct 31, 2024
6d0db3c
Merge branch 'development' into update_generel_logger
Polichinel Oct 31, 2024
ec15615
bc Dylan is no fun
Polichinel Oct 31, 2024
8a82a68
slots no longer in use
Polichinel Oct 31, 2024
49e33a6
No longer using slots anywhere
Polichinel Oct 31, 2024
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
28 changes: 17 additions & 11 deletions .github/workflows/prevent_merge_when_branch_behind.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
name: Require Branch to Be Up-to-Date with Production
name: Require Branch to Be Up-to-Date

# Trigger this workflow on pull request events targeting a specific branch.
on:
pull_request:
branches:
- production
- development
- test-protect-main-merge # for testing
- fix_prevent_merge_when_branch_behind
workflow_dispatch: # enables manual triggering

jobs:
check-branch:
runs-on: ubuntu-latest
steps:
- name: Determine Comparison Branch
id: comparison
run: |
if [[ "${{ github.event.pull_request.base.ref }}" == "production" && "${{ github.event.pull_request.head.ref }}" == "development" ]]; then
echo "branch=production" >> $GITHUB_ENV
else
echo "branch=development" >> $GITHUB_ENV
fi

- name: Checkout pull request branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Fetch production branch
- name: Fetch comparison branch
run: |
git fetch --unshallow
git fetch origin production
git fetch origin ${{ env.branch }}

- name: Compare branch with production
- name: Compare branch with ${{ env.branch }}
run: |
if git merge-base --is-ancestor origin/production HEAD; then
echo "::notice ::Branch is up-to-date with production."
if git merge-base --is-ancestor origin/${{ env.branch }} HEAD; then
echo "::notice ::Branch is up-to-date with ${{ env.branch }}."
else
echo "::error ::Merge Blocked: Your branch is behind the latest commits on production. Please update your branch with the latest changes from production before attempting to merge."
echo "Merge base: $(git merge-base HEAD origin/production)"
echo "::error ::Merge Blocked: Your branch is behind the latest commits on ${{ env.branch }}. Please update your branch before attempting to merge."
exit 1
fi


62 changes: 62 additions & 0 deletions common_configs/config_log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 1
disable_existing_loggers: False

formatters:
detailed:
format: '%(asctime)s %(pathname)s [%(filename)s:%(lineno)d] [%(process)d] [%(threadName)s] - %(levelname)s - %(message)s'

handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: detailed
stream: ext://sys.stdout

info_file_handler:
class: logging.handlers.TimedRotatingFileHandler
level: INFO
formatter: detailed
filename: "{LOG_PATH}/views_pipeline_INFO.log"
when: "midnight"
backupCount: 30
encoding: "utf8"

debug_file_handler:
class: logging.handlers.TimedRotatingFileHandler
level: DEBUG
formatter: detailed
filename: "{LOG_PATH}/views_pipeline_DEBUG.log"
when: "midnight"
backupCount: 10
encoding: "utf8"

warning_file_handler:
class: logging.handlers.TimedRotatingFileHandler
level: WARNING
formatter: detailed
filename: "{LOG_PATH}/views_pipeline_WARNING.log"
when: "midnight"
backupCount: 20
encoding: "utf8"

error_file_handler:
class: logging.handlers.TimedRotatingFileHandler
level: ERROR
formatter: detailed
filename: "{LOG_PATH}/views_pipeline_ERROR.log"
when: "midnight"
backupCount: 60
encoding: "utf8"

critical_file_handler:
class: logging.handlers.TimedRotatingFileHandler
level: CRITICAL
formatter: detailed
filename: "{LOG_PATH}/views_pipeline_CRITICAL.log"
when: "midnight"
backupCount: 90
encoding: "utf8"

root:
level: DEBUG
handlers: [console, info_file_handler, debug_file_handler, warning_file_handler, error_file_handler, critical_file_handler]
Empty file added common_logs/.gitkeep
Empty file.
10 changes: 5 additions & 5 deletions common_utils/global_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ def ensure_cache_file_exists(self):
Ensures that the cache file exists. If it does not exist, creates a new cache file.
"""
if not self.filepath.exists():
logging.info(
logging.warning(
f"Cache file: {self.filepath} does not exist. Creating new cache file..."
)
with open(self.filepath, "wb") as f:
pickle.dump({}, f)
logging.info(f"Created new cache file: {self.filepath}")
logging.debug(f"Created new cache file: {self.filepath}")

def set(self, key, value):
"""
Expand Down Expand Up @@ -167,7 +167,7 @@ def save_cache(self):
"""
with open(self.filepath, "wb") as f:
pickle.dump(self.cache, f)
logging.info(f"Cache saved to file: {self.filepath}")
logging.debug(f"Cache saved to file: {self.filepath}")

def load_cache(self):
"""
Expand All @@ -179,7 +179,7 @@ def load_cache(self):
loaded_cache = pickle.loads(f.read())
if isinstance(loaded_cache, dict):
self.cache = loaded_cache
logging.info(f"Cache loaded from file: {self.filepath}")
logging.debug(f"Cache loaded from file: {self.filepath}")
else:
logging.error(
f"Loaded cache is not a dictionary. Initializing empty cache."
Expand All @@ -192,7 +192,7 @@ def load_cache(self):
self.cache = {}
else:
self.cache = {}
logging.info(f"Cache file does not exist. Initialized empty cache.")
logging.debug(f"Cache file does not exist. Initialized empty cache.")


def cleanup_cache_file():
Expand Down
98 changes: 53 additions & 45 deletions common_utils/model_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,45 @@ class ModelPath:
_ignore_attributes (list): A list of paths to ignore.
"""

__slots__ = (
"_validate",
"target",
"use_global_cache",
"_force_cache_overwrite",
"root",
"models",
"common_utils",
"common_configs",
"_ignore_attributes",
"model_name",
"_instance_hash",
"_queryset",
"model_dir",
"architectures",
"artifacts",
"configs",
"data",
"data_generated",
"data_processed",
"data_raw",
"dataloaders",
"forecasting",
"management",
"notebooks",
"offline_evaluation",
"online_evaluation",
"reports",
"src",
"_templates",
"training",
"utils",
"visualization",
"_sys_paths",
"common_querysets",
"queryset_path",
"scripts",
"meta_tools",
)
# __slots__ = (
# "_validate",
# "target",
# "use_global_cache",
# "_force_cache_overwrite",
# "root",
# "models",
# "common_utils",
# "common_configs",
# "_ignore_attributes",
# "model_name",
# "_instance_hash",
# "_queryset",
# "model_dir",
# "architectures",
# "artifacts",
# "configs",
# "data",
# "data_generated",
# "data_processed",
# "data_raw",
# "dataloaders",
# "forecasting",
# "management",
# "notebooks",
# "offline_evaluation",
# "online_evaluation",
# "reports",
# "src",
# "_templates",
# "training",
# "utils",
# "visualization",
# "_sys_paths",
# "common_querysets",
# "queryset_path",
# "scripts",
# "meta_tools",
# )

_target = "model"
_use_global_cache = True
Expand All @@ -120,6 +120,7 @@ def _initialize_class_paths(cls):
cls._common_configs = cls._root / "common_configs"
cls._common_querysets = cls._root / "common_querysets"
cls._meta_tools = cls._root / "meta_tools"
cls._common_logs = cls._root / "common_logs"

@classmethod
def get_root(cls) -> Path:
Expand Down Expand Up @@ -163,6 +164,13 @@ def get_meta_tools(cls) -> Path:
cls._initialize_class_paths()
return cls._meta_tools

@classmethod
def get_common_logs(cls) -> Path:
"""Get the common logs path."""
if cls._common_logs is None:
cls._initialize_class_paths()
return cls._common_logs

@classmethod
def check_if_model_dir_exists(cls, model_name: str) -> bool:
"""
Expand Down Expand Up @@ -575,8 +583,8 @@ def add_paths_to_sys(self) -> List[str]:
)
if self._sys_paths is None:
self._sys_paths = []
for attr in self.__slots__:
value = getattr(self, attr)
for attr, value in self.__dict__.items():
# value = getattr(self, attr)
if str(attr) not in self._ignore_attributes:
if (
isinstance(value, Path)
Expand Down Expand Up @@ -641,8 +649,8 @@ def view_directories(self) -> None:
"""
print("\n{:<20}\t{:<50}".format("Name", "Path"))
print("=" * 72)
for attr in self.__slots__:
value = getattr(self, attr)
for attr, value in self.__dict__.items():
# value = getattr(self, attr)
if attr not in self._ignore_attributes and isinstance(value, Path):
print("{:<20}\t{:<50}".format(str(attr), str(value)))

Expand Down Expand Up @@ -687,8 +695,8 @@ def get_directories(self) -> Dict[str, Optional[str]]:
# ]
directories = {}
relative = False
for attr in self.__slots__:
value = getattr(self, attr)
for attr, value in self.__dict__.items():
# value = getattr(self, attr)
if str(attr) not in [
"model_name",
"root",
Expand Down
9 changes: 5 additions & 4 deletions common_utils/tests/test_utils_evaluation_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import properscoring as ps
from sklearn.metrics import mean_squared_error, mean_absolute_error
# WARNING: mean_squared_error is deprecated!
import wandb
import sys
from pathlib import Path
PATH = Path(__file__)
Expand Down Expand Up @@ -43,11 +44,11 @@ def mock_config():
Config: A mock configuration object with attributes 'steps' and 'depvar'.
"""

class Config:
steps = [1, 2]
depvar = "depvar"
config = wandb.Config()
config.steps = [1, 2]
config.depvar = "depvar"

return Config()
return config


def test_evaluation_metrics_default_values():
Expand Down
10 changes: 5 additions & 5 deletions common_utils/tests/test_utils_model_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from utils_model_outputs import ModelOutputs, generate_output_dict
import sys
from pathlib import Path

import wandb
PATH = Path(__file__)
if 'views_pipeline' in PATH.parts:
PATH_ROOT = Path(*PATH.parts[:PATH.parts.index('views_pipeline') + 1])
Expand Down Expand Up @@ -53,11 +53,11 @@ def mock_config():
Config: A mock configuration object with predefined attributes.
"""

class Config:
steps = [1, 2]
depvar = "depvar"
config = wandb.Config()
config.steps = [1, 2]
config.depvar = "depvar"

return Config()
return config


def test_model_outputs_default_values():
Expand Down
Loading
Loading