Skip to content

Commit 27e0617

Browse files
moromimayralphrass
authored andcommitted
[MLOP-639] Track logs in S3 (#306)
* Apply tracking logs and logging config. * Adjusts in CLI and logging.conf. * Some adjusts. * Change version to generate new dev package * Fix version. * Apply style. * Add new assert in the migrate unit test.
1 parent 149c205 commit 27e0617

File tree

6 files changed

+65
-10
lines changed

6 files changed

+65
-10
lines changed

butterfree/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
"""Module docstring example, following Google's docstring style."""
2+
import logging.config
3+
import os
4+
import sys
5+
6+
sys.path.insert(0, os.path.abspath("."))
7+
8+
logging.config.fileConfig(fname="butterfree/logging.conf")

butterfree/_cli/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
import logging
2-
3-
4-
def __logger(name: str) -> logging.Logger:
5-
format_ = "%(name)s:%(asctime)-15s:%(levelname)s:< %(message)s >"
6-
logging.basicConfig(format=format_, level=logging.INFO)
7-
return logging.getLogger(name)
8-
9-
10-
cli_logger = __logger("butterfree")

butterfree/_cli/migrate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class Migrate:
115115

116116
def __init__(self, pipelines: Set[FeatureSetPipeline],) -> None:
117117
self.pipelines = pipelines
118+
self.spark_client = spark_client or SparkClient()
118119

119120
def _send_logs_to_s3(self, file_local: bool, debug_mode: bool) -> None:
120121
"""Send all migration logs to S3."""
@@ -168,6 +169,7 @@ def run(self, generate_logs: bool = False, debug_mode: bool = False) -> None:
168169

169170
self._send_logs_to_s3(generate_logs, debug_mode)
170171

172+
self._send_logs_to_s3(generate_logs)
171173

172174
@app.command("apply")
173175
def migrate(

butterfree/logging.conf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[loggers]
2+
keys=root,cli,migrate,database_migrate
3+
4+
[handlers]
5+
keys=consoleHandler,file
6+
7+
[formatters]
8+
keys=simpleFormatter,jsonFormatter
9+
10+
[logger_root]
11+
level=DEBUG
12+
handlers=consoleHandler
13+
14+
[logger_cli]
15+
level=DEBUG
16+
handlers=file
17+
qualname=cli
18+
propagate=0
19+
20+
[logger_migrate]
21+
level=DEBUG
22+
handlers=file
23+
qualname=migrate
24+
propagate=0
25+
26+
[logger_database_migrate]
27+
level=DEBUG
28+
handlers=file
29+
qualname=database_migrate
30+
propagate=0
31+
32+
[handler_consoleHandler]
33+
class=StreamHandler
34+
level=DEBUG
35+
formatter=simpleFormatter
36+
args=(sys.stdout,)
37+
38+
[handler_file]
39+
class=FileHandler
40+
level=DEBUG
41+
formatter=jsonFormatter
42+
args=('logs/logging.json', "a")
43+
44+
[formatter_simpleFormatter]
45+
format=%(name)s:%(asctime)-15s:%(levelname)s:%(message)s
46+
datefmt=
47+
class=logging.Formatter
48+
49+
[formatter_jsonFormatter]
50+
format={"name": "%(name)s", "timestamp": "%(asctime)-15s", "level": "%(levelname)s", "message": "%(message)s"}
51+
datefmt=
52+
class=logging.Formatter

logs/logging.json

Whitespace-only changes.

tests/unit/butterfree/_cli/test_migrate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
runner = CliRunner()
1111

12+
def test_migrate_all_pairs(self, mocker):
13+
mocker.patch.object(MetastoreMigration, "apply_migration")
14+
mocker.patch.object(CassandraMigration, "apply_migration")
15+
mocker.patch.object(migrate.Migrate, "_send_logs_to_s3")
1216

1317
class TestMigrate:
1418
def test_migrate_success(self, mocker):

0 commit comments

Comments
 (0)