Skip to content

Shrike #38560

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 72 commits into from
Nov 18, 2024
Merged

Shrike #38560

Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
086e24b
fixing sweep job service response parsing issue
achauhan-scc May 14, 2024
2d60c09
fixing sweep job service response parsing issue
achauhan-scc May 14, 2024
6bf90d1
Merge branch 'Azure:main' into main
achauhan-scc May 17, 2024
11bc156
raising a work around for cmd job and spark job name lowering case
achauhan-scc May 17, 2024
0cab591
fixing black issue
achauhan-scc May 17, 2024
e6a6177
fixing serialization issue in sweep job
achauhan-scc May 20, 2024
54f97db
include black fix
achauhan-scc May 20, 2024
b6647ba
found and fix the issue in compute validation
achauhan-scc May 20, 2024
68cffc1
fixing a corrupt wokspace arm template
achauhan-scc May 23, 2024
9a073a5
Merge branch 'Azure:main' into main
achauhan-scc May 23, 2024
7adb27f
Merge branch 'Azure:main' into main
achauhan-scc May 31, 2024
ff1caf9
fixing the failed test case
achauhan-scc May 31, 2024
a4c6ec8
Merge branch 'Azure:main' into main
achauhan-scc Jun 1, 2024
cd7349b
Merge branch 'Azure:main' into main
achauhan-scc Jun 3, 2024
55580cd
Merge branch 'Azure:main' into main
achauhan-scc Jun 5, 2024
fc75809
Merge branch 'Azure:main' into main
achauhan-scc Jul 1, 2024
e7fb030
updating the date for 1.18.0 release
achauhan-scc Jul 1, 2024
d167e90
removing empty section
achauhan-scc Jul 1, 2024
df1448e
Merge branch 'Azure:main' into main
achauhan-scc Jul 2, 2024
eb78fff
Merge branch 'Azure:main' into main
achauhan-scc Jul 2, 2024
a6d644a
adding in progress version details
achauhan-scc Jul 2, 2024
248fb11
adding IDC code reviewers
achauhan-scc Jul 3, 2024
96bc9af
Merge branch 'Azure:main' into main
achauhan-scc Jul 3, 2024
899fb63
merging master
achauhan-scc Jul 3, 2024
2c9d4a1
Merge branch 'Azure:main' into main
achauhan-scc Jul 11, 2024
8c9b43d
Merge branch 'Azure:main' into main
achauhan-scc Jul 16, 2024
4fc5d3c
correcting the directory path
achauhan-scc Jul 16, 2024
3073577
Merge branch 'Azure:main' into main
achauhan-scc Jul 17, 2024
c2a42b0
Merge branch 'Azure:main' into main
achauhan-scc Jul 25, 2024
28a84b4
lint fix
achauhan-scc Jul 25, 2024
c942e3b
main merge
achauhan-scc Jul 25, 2024
723e268
adding change log entry
achauhan-scc Jul 25, 2024
7a4a36c
Merge branch 'Azure:main' into main
achauhan-scc Jul 26, 2024
f29cb62
addressing review comment
achauhan-scc Jul 26, 2024
296bb47
fixing ut
achauhan-scc Jul 26, 2024
de46e97
merging master
achauhan-scc Aug 1, 2024
5e147e7
addressing api review comment
achauhan-scc Aug 1, 2024
3ef24d2
Merge branch 'Azure:main' into main
achauhan-scc Aug 1, 2024
d452f7f
adding a fix for subnet validation in compute instance
achauhan-scc Aug 1, 2024
7c7da5c
Merge branch 'main' of https://github.com/achauhan-scc/azure-sdk-for-…
achauhan-scc Aug 1, 2024
c184b75
my py fix
achauhan-scc Aug 1, 2024
8a4f0ae
fixing autoML serialization issue
achauhan-scc Aug 27, 2024
29cacd6
Merge branch 'Azure:main' into main
achauhan-scc Aug 27, 2024
e25d364
formatting
achauhan-scc Aug 27, 2024
9624cfa
moving auto ML job create API to 2024
achauhan-scc Aug 27, 2024
5bcfd97
Merge branch 'Azure:main' into main
achauhan-scc Aug 29, 2024
3f61b10
Merge branch 'Azure:main' into main
achauhan-scc Sep 4, 2024
231f594
Merge branch 'Azure:main' into main
achauhan-scc Sep 12, 2024
154f098
Merge branch 'Azure:main' into main
achauhan-scc Sep 19, 2024
50398fd
Merge branch 'Azure:main' into main
achauhan-scc Sep 19, 2024
b4f1cd3
Merge branch 'Azure:main' into main
achauhan-scc Sep 20, 2024
e8ae640
Merge branch 'Azure:main' into main
achauhan-scc Sep 23, 2024
8d59810
Merge branch 'Azure:main' into main
achauhan-scc Sep 30, 2024
877c89d
Merge branch 'Azure:main' into main
achauhan-scc Oct 3, 2024
b2a7408
Merge branch 'Azure:main' into main
achauhan-scc Oct 3, 2024
55053d3
Merge branch 'Azure:main' into main
achauhan-scc Oct 7, 2024
8f12f36
Merge branch 'Azure:main' into main
achauhan-scc Oct 7, 2024
cad9ad6
Merge branch 'Azure:main' into main
achauhan-scc Oct 8, 2024
d534a0d
Merge branch 'Azure:main' into main
achauhan-scc Oct 15, 2024
e98c81e
Merge branch 'Azure:main' into main
achauhan-scc Oct 21, 2024
4811abc
adding compliant logger
achauhan-scc Oct 21, 2024
69bedd7
Merge branch 'Azure:main' into main
achauhan-scc Oct 22, 2024
b9abee1
Merge branch 'Azure:main' into main
achauhan-scc Oct 28, 2024
f937d9f
Merge branch 'Azure:main' into main
achauhan-scc Nov 6, 2024
b051425
Merge branch 'Azure:main' into main
achauhan-scc Nov 14, 2024
23f5436
Merge branch 'Azure:main' into main
achauhan-scc Nov 15, 2024
948f5a3
Merge branch 'main' into shrike
achauhan-scc Nov 15, 2024
03ee8f6
getting compliant logger fix
achauhan-scc Nov 15, 2024
ae9591a
better variable name for line is compliant
achauhan-scc Nov 15, 2024
2cba42a
Merge branch 'Azure:main' into main
achauhan-scc Nov 18, 2024
82a9aaf
Merge branch 'main' into shrike
achauhan-scc Nov 18, 2024
45c7515
fix mypy issue
achauhan-scc Nov 18, 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
176 changes: 176 additions & 0 deletions sdk/ml/azure-ai-ml/azure/ai/ml/_logging/compliant_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

""" This is logger utility which will work with allowed logged filter AML policy
https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Machine%20Learning/AllowedLogFilter_EnforceSetting.json
You have to define the same "logFilters" while initializing the logger using "enable_compliant_logging" method
e.g.
log filters: ["^SystemLog:.*$"]
initialize : enable_compliant_logging(format_key="prefix",
format_key_value="SystemLog",
format=f"%(prefix)s{logging.BASIC_FORMAT}")
By default log message will not compliant e.g. not modified
"""

import logging
import sys
from datetime import datetime
from threading import Lock
from typing import Optional

_LOCK = Lock()
_FORMAT_KEY = None
_FORMAT_VALUE = None


# pylint: disable=global-statement
def set_format(key_name: str, value: str) -> None:
with _LOCK:
global _FORMAT_KEY
_FORMAT_KEY = key_name
global _FORMAT_VALUE
_FORMAT_VALUE = value


def get_format_key() -> Optional[str]:
return _FORMAT_KEY


def get_format_value() -> Optional[str]:
return _FORMAT_VALUE


def get_default_logging_format() -> str:
return f"%({get_format_key()})s{logging.BASIC_FORMAT}"


class CompliantLogger(logging.getLoggerClass()): # type: ignore
"""
Subclass of the default logging class with an explicit `is_compliant` parameter
on all logging methods. It will pass an `extra` param with `format` key
(value depending on whether `is_compliant` is True or False) to the
handlers.

The default value for data `is_compliant` is `False` for all methods.

Implementation is inspired by:
https://github.com/python/cpython/blob/3.8/Lib/logging/__init__.py
"""

def __init__(self, name: str, handlers=None):
super().__init__(name) # type: ignore

self.format_key = get_format_key()
self.format_value = get_format_value()

if handlers:
self.handlers = handlers

self.start_time = datetime.now()
self.metric_count = 1
# number of iterable items that are logged
self.max_iter_items = 10

def _log(
self,
level,
msg,
args=None,
exc_info=None,
extra=None,
stack_info=False,
stacklevel=1,
is_compliant=False,
):
if is_compliant:
format_value = self.format_value
else:
format_value = ""

if extra:
extra.update({self.format_key: format_value})
else:
extra = {self.format_key: format_value}

if sys.version_info[1] <= 7:
super(CompliantLogger, self)._log(
level=level,
msg=msg,
args=args,
exc_info=exc_info,
extra=extra,
stack_info=stack_info,
)
else:
super(CompliantLogger, self)._log(
level=level,
msg=msg,
args=args,
exc_info=exc_info,
extra=extra,
stack_info=stack_info,
stacklevel=stacklevel, # type: ignore
)


_logging_basic_config_set_warning = """
********************************************************************************
The root logger already has handlers set! As a result, the behavior of this
library is undefined. If running in Python >= 3.8, this library will attempt to
call logging.basicConfig(force=True), which will remove all existing root
handlers. See https://stackoverflow.com/q/20240464 and
https://github.com/Azure/confidential-ml-utils/issues/33 for more information.
********************************************************************************
"""


def enable_compliant_logging(
format_key: str = "prefix",
format_key_value: str = "SystemLog:",
**kwargs,
) -> None:
"""
The default format is `logging.BASIC_FORMAT` (`%(levelname)s:%(name)s:%(message)s`).
All other kwargs are passed to `logging.basicConfig`. Sets the default
logger class and root logger to be compliant. This means the format
string `%(xxxx)` will work.

:param format_key: key for format
:type format_key: str
:param format_key_value: value for format
:type format_key_value: str

Set the format using the `format` kwarg.

If running in Python >= 3.8, will attempt to add `force=True` to the kwargs
for logging.basicConfig.

The standard implementation of the logging API is a good reference:
https://github.com/python/cpython/blob/3.9/Lib/logging/__init__.py
"""
set_format(format_key, format_key_value)

if "format" not in kwargs:
kwargs["format"] = get_default_logging_format()

# Ensure that all loggers created via `logging.getLogger` are instances of
# the `CompliantLogger` class.
logging.setLoggerClass(CompliantLogger)

if len(logging.root.handlers) > 0:
p = get_format_value()
for line in _logging_basic_config_set_warning.splitlines():
print(f"{p}{line}", file=sys.stderr)

if "force" not in kwargs and sys.version_info >= (3, 8):
kwargs["force"] = True

root = CompliantLogger(logging.root.name, handlers=logging.root.handlers)

logging.root = root
logging.Logger.root = root # type: ignore
logging.Logger.manager = logging.Manager(root) # type: ignore

# https://github.com/kivy/kivy/issues/6733
logging.basicConfig(**kwargs)