-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: conditionally run pipelines in debug mode (#223)
* Consider the current log_level * Consider the current log_level * Unit test * Unit test simplify * Dockerfile and small bug fix * fix env conversion * Simplify Dockerfile * Instructions * Renames * Renames
- Loading branch information
Showing
9 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM blsq/openhexa-base-environment:latest | ||
|
||
USER root | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
|
||
RUN pip install build | ||
RUN python -m build . | ||
|
||
RUN pip install --no-cache-dir /app/dist/*.tar.gz && rm -rf /app/dist/*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Log levels for the pipeline runs.""" | ||
from enum import IntEnum | ||
|
||
|
||
class LogLevel(IntEnum): | ||
""" | ||
Enum representing different log levels. | ||
- Attributes: | ||
DEBUG (int): Debug level, value 0. | ||
INFO (int): Info level, value 1. | ||
WARNING (int): Warning level, value 2. | ||
ERROR (int): Error level, value 3. | ||
CRITICAL (int): Critical level, value 4. | ||
""" | ||
|
||
DEBUG = 0 | ||
INFO = 1 | ||
WARNING = 2 | ||
ERROR = 3 | ||
CRITICAL = 4 | ||
|
||
@classmethod | ||
def parse_log_level(cls, value) -> "LogLevel": | ||
"""Parse a log level from a string or integer.""" | ||
if isinstance(value, int) and 0 <= value <= 4: | ||
return LogLevel(value) | ||
if isinstance(value, str): | ||
if value.isdigit(): | ||
return cls.parse_log_level(int(value)) | ||
value = value.upper() | ||
if hasattr(cls, value): | ||
return getattr(cls, value) | ||
return cls.INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest.mock import ANY, patch | ||
|
||
from openhexa.sdk.pipelines.run import CurrentRun, LogLevel | ||
|
||
|
||
@patch.object(CurrentRun, "_connected", True) | ||
@patch("openhexa.sdk.pipelines.run.graphql") | ||
def test_default_log_level(mock_graphql): | ||
current_run = CurrentRun() | ||
|
||
current_run.log_debug("This is a debug message") | ||
current_run.log_info("This is an info message") | ||
|
||
assert mock_graphql.call_count == 1 | ||
mock_graphql.assert_any_call(ANY, {"input": {"priority": "INFO", "message": "This is an info message"}}) | ||
|
||
|
||
@patch.object(CurrentRun, "_connected", True) | ||
@patch("openhexa.sdk.pipelines.run.graphql") | ||
def test_filtering_log_messages_based_on_settings(mock_graphql, settings): | ||
settings.log_level = LogLevel.ERROR | ||
current_run = CurrentRun() | ||
|
||
current_run.log_warning("This is a warning message") | ||
current_run.log_error("This is an error message") | ||
current_run.log_critical("This is a critical message") | ||
|
||
assert mock_graphql.call_count == 2 | ||
mock_graphql.assert_any_call(ANY, {"input": {"priority": "ERROR", "message": "This is an error message"}}) | ||
mock_graphql.assert_any_call(ANY, {"input": {"priority": "CRITICAL", "message": "This is a critical message"}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters