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

Add support for loading from .env files #296

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

Conversation

Kilo59
Copy link
Member

@Kilo59 Kilo59 commented Jun 6, 2024

Add an optional gx-agent --env-file CLI argument that allows the agent to load ENV variables from a file.

https://saurabh-kumar.com/python-dotenv/

$ gx-agent --help
usage: gx-agent [-h] [--env-file ENV_FILE] [--log-level LOG_LEVEL] [--skip-log-file SKIP_LOG_FILE] [--json-log] [--log-cfg-file LOG_CFG_FILE]
                [--custom-log-tags CUSTOM_LOG_TAGS] [--version]

optional arguments:
  -h, --help            show this help message and exit
  --env-file ENV_FILE   Path to an environment file to load environment variables from. Defaults to None.

Also, update our readme to have a more complete Quick-Start started example.

@Kilo59 Kilo59 self-assigned this Jun 6, 2024
Copy link

codecov bot commented Jun 6, 2024

❌ 6 Tests Failed:

Tests completed Failed Passed Skipped
502 6 496 2
View the top 3 failed tests by shortest run time
tests.agent.test_event_handler�test_parse_event_invalid_json
Stack Traces | 0.004s run time
cls = <class 'great_expectations_cloud.agent.event_handler.EventHandler'>
msg_body = b'{"type":"onboarding_data_assistant_request.received","organization_id":"b788e1b4-1aa4-4760-bbc6-fa7b63c02812","datasource_name":"abc","data_asset_name":"boo","expectation_suite_name":null}}}}}'

@classmethod
def parse_event_from(cls, msg_body: bytes) -> Event:
try:
> event: Event = pydantic_v1.parse_raw_as(Event, msg_body) # type: ignore[arg-type] # FIXME

great_expectations_cloud/agent/event_handler.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.11/lib/python3.11.../pydantic/v1/tools.py:74: in parse_raw_as
obj = load_str_bytes(
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.11/lib/python3.11.../pydantic/v1/parse.py:37: in load_str_bytes
return json_loads(b)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/json/__init__.py:346: in loads
return _default_decoder.decode(s)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <json.decoder.JSONDecoder object at 0x7f35e9ada750>
s = '{"type":"onboarding_data_assistant_request.received","organization_id":"b788e1b4-1aa4-4760-bbc6-fa7b63c02812","datasource_name":"abc","data_asset_name":"boo","expectation_suite_name":null}}}}}'
_w = <built-in method match of re.Pattern object at 0x7f35e9a85b10>

def decode(self, s, _w=WHITESPACE.match):
"""Return the Python representation of ``s`` (a ``str`` instance
containing a JSON document).

"""
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
end = _w(s, end).end()
if end != len(s):
> raise JSONDecodeError("Extra data", s, end)
E json.decoder.JSONDecodeError: Extra data: line 1 column 189 (char 188)

.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/json/decoder.py:340: JSONDecodeError

During handling of the above exception, another exception occurred:

example_event = RunOnboardingDataAssistantEvent(type='onboarding_data_assistant_request.received', organization_id=UUID('b788e1b4-1aa4-4760-bbc6-fa7b63c02812'), datasource_name='abc', data_asset_name='boo', expectation_suite_name=None)

def test_parse_event_invalid_json(example_event):
event_dict = example_event.dict()
invalid_json_addition = "}}}}"
serialized_bytes = (orjson.dumps(event_dict).decode() + invalid_json_addition).encode("utf-8")
> event = EventHandler.parse_event_from(serialized_bytes)

tests/agent/test_event_handler.py:344:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
great_expectations_cloud/agent/event_handler.py:109: in parse_event_from
LOGGER.exception("Unable to parse event type", extra={"msg_body": f"{msg_body!r}"})
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1524: in exception
self.error(msg, *args, exc_info=exc_info, **kwargs)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1518: in error
self._log(ERROR, msg, args, **kwargs)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1634: in _log
self.handle(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1644: in handle
self.callHandlers(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1706: in callHandlers
hdlr.handle(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:978: in handle
self.emit(record)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.11/lib/python3.11....../site-packages/_pytest/logging.py:386: in emit
super().emit(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1118: in emit
self.handleError(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:1110: in emit
msg = self.format(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:953: in format
return fmt.format(record)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.11/lib/python3.11....../site-packages/_pytest/logging.py:139: in format
return super().format(record)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:695: in format
record.exc_text = self.formatException(record.exc_info)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/logging/__init__.py:645: in formatException
traceback.print_exception(ei[0], ei[1], tb, None, sio)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/traceback.py:124: in print_exception
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/traceback.py:728: in __init__
self.stack = StackSummary._extract_from_extended_frame_gen(
.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/traceback.py:413: in _extract_from_extended_frame_gen
for f, (lineno, end_lineno, colno, end_colno) in frame_gen:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

tb = 'c'

def _walk_tb_with_full_positions(tb):
# Internal version of walk_tb that yields full code positions including
# end line and column information.
while tb is not None:
> positions = _get_code_position(tb.tb_frame.f_code, tb.tb_lasti)
E AttributeError: 'str' object has no attribute 'tb_frame'

.../hostedtoolcache/Python/3.11.9.................................................../x64/lib/python3.11/traceback.py:350: AttributeError
tests.agent.test_event_handler�test_parse_event_invalid_json
Stack Traces | 0.014s run time
cls = <class 'great_expectations_cloud.agent.event_handler.EventHandler'>
msg_body = b'{"type":"onboarding_data_assistant_request.received","organization_id":"9c305ae2-d27f-4cdc-a361-142cb4855cb4","datasource_name":"abc","data_asset_name":"boo","expectation_suite_name":null}}}}}'

@classmethod
def parse_event_from(cls, msg_body: bytes) -> Event:
try:
> event: Event = pydantic_v1.parse_raw_as(Event, msg_body) # type: ignore[arg-type] # FIXME

great_expectations_cloud/agent/event_handler.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../pydantic/v1/tools.py:74: in parse_raw_as
obj = load_str_bytes(
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../pydantic/v1/parse.py:37: in load_str_bytes
return json_loads(b)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/json/__init__.py:346: in loads
return _default_decoder.decode(s)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <json.decoder.JSONDecoder object at 0x7f6d125bdc90>
s = '{"type":"onboarding_data_assistant_request.received","organization_id":"9c305ae2-d27f-4cdc-a361-142cb4855cb4","datasource_name":"abc","data_asset_name":"boo","expectation_suite_name":null}}}}}'
_w = <built-in method match of re.Pattern object at 0x7f6d12332cf0>

def decode(self, s, _w=WHITESPACE.match):
"""Return the Python representation of ``s`` (a ``str`` instance
containing a JSON document).

"""
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
end = _w(s, end).end()
if end != len(s):
> raise JSONDecodeError("Extra data", s, end)
E json.decoder.JSONDecodeError: Extra data: line 1 column 189 (char 188)

.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/json/decoder.py:340: JSONDecodeError

During handling of the above exception, another exception occurred:

example_event = RunOnboardingDataAssistantEvent(type='onboarding_data_assistant_request.received', organization_id=UUID('9c305ae2-d27f-4cdc-a361-142cb4855cb4'), datasource_name='abc', data_asset_name='boo', expectation_suite_name=None)

def test_parse_event_invalid_json(example_event):
event_dict = example_event.dict()
invalid_json_addition = "}}}}"
serialized_bytes = (orjson.dumps(event_dict).decode() + invalid_json_addition).encode("utf-8")
> event = EventHandler.parse_event_from(serialized_bytes)

tests/agent/test_event_handler.py:344:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
great_expectations_cloud/agent/event_handler.py:109: in parse_event_from
LOGGER.exception("Unable to parse event type", extra={"msg_body": f"{msg_body!r}"})
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1512: in exception
self.error(msg, *args, exc_info=exc_info, **kwargs)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1506: in error
self._log(ERROR, msg, args, **kwargs)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1624: in _log
self.handle(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1634: in handle
self.callHandlers(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1696: in callHandlers
hdlr.handle(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:968: in handle
self.emit(record)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10....../site-packages/_pytest/logging.py:386: in emit
super().emit(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1108: in emit
self.handleError(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:1100: in emit
msg = self.format(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:943: in format
return fmt.format(record)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10....../site-packages/_pytest/logging.py:139: in format
return super().format(record)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:686: in format
record.exc_text = self.formatException(record.exc_info)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/logging/__init__.py:636: in formatException
traceback.print_exception(ei[0], ei[1], tb, None, sio)
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/traceback.py:119: in print_exception
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../site-packages/exceptiongroup/_formatting.py:96: in __init__
self.stack = traceback.StackSummary.extract(
.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/traceback.py:364: in extract
for f, lineno in frame_gen:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

tb = 'c'

def walk_tb(tb):
"""Walk a traceback yielding the frame and line number for each frame.

This will follow tb.tb_next (and thus is in the opposite order to
walk_stack). Usually used with StackSummary.extract.
"""
while tb is not None:
> yield tb.tb_frame, tb.tb_lineno
E AttributeError: 'str' object has no attribute 'tb_frame'

.../hostedtoolcache/Python/3.10.14................................................/x64/lib/python3.10/traceback.py:329: AttributeError
tests.agent.test_event_handler�test_parse_event_missing_required_field
Stack Traces | 0.024s run time
cls = <class 'great_expectations_cloud.agent.event_handler.EventHandler'>
msg_body = b'{"type":"onboarding_data_assistant_request.received","organization_id":"a1b6dead-42ad-4938-b2a7-e213206c9f53","data_asset_name":"boo","expectation_suite_name":null}'

@classmethod
def parse_event_from(cls, msg_body: bytes) -> Event:
try:
> event: Event = pydantic_v1.parse_raw_as(Event, msg_body) # type: ignore[arg-type] # FIXME

great_expectations_cloud/agent/event_handler.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../pydantic/v1/tools.py:82: in parse_raw_as
return parse_obj_as(type_, obj, type_name=type_name)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../pydantic/v1/tools.py:38: in parse_obj_as
return model_type(__root__=obj).__root__
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

__pydantic_self__ = ParsingModel[Annotated[Union[great_expectations_cloud.agent.models.RunOnboardingDataAssistantEvent, great_expectations...expectations_cloud.agent.models.UnknownEvent], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})]]()
data = {'__root__': {'data_asset_name': 'boo', 'expectation_suite_name': None, 'organization_id': 'a1b6dead-42ad-4938-b2a7-e213206c9f53', 'type': 'onboarding_data_assistant_request.received'}}
values = {}, fields_set = {'__root__'}
validation_error = ValidationError(model="ParsingModel[Annotated[Union[great_expectations_cloud.agent.models.RunOnboardingDataAssistantEv...ot__', 'RunOnboardingDataAssistantEvent', 'datasource_name'), 'msg': 'field required', 'type': 'value_error.missing'}])

def __init__(__pydantic_self__, **data: Any) -> None:
"""
Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.
"""
# Uses something other than `self` the first arg to allow "self" as a settable attribute
values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
if validation_error:
> raise validation_error
E pydantic.v1.error_wrappers.ValidationError: 1 validation error for ParsingModel[Annotated[Union[great_expectations_cloud.agent.models.RunOnboardingDataAssistantEvent, great_expectations_cloud.agent.models.RunMissingnessDataAssistantEvent, great_expectations_cloud.agent.models.RunCheckpointEvent, great_expectations_cloud.agent.models.RunScheduledCheckpointEvent, great_expectations_cloud.agent.models.RunColumnDescriptiveMetricsEvent, great_expectations_cloud.agent.models.RunMetricsListEvent, great_expectations_cloud.agent.models.DraftDatasourceConfigEvent, great_expectations_cloud.agent.models.ListTableNamesEvent, great_expectations_cloud.agent.models.UnknownEvent], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})]]
E __root__ -> RunOnboardingDataAssistantEvent -> datasource_name
E field required (type=value_error.missing)

../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../pydantic/v1/main.py:341: ValidationError

During handling of the above exception, another exception occurred:

example_event = RunOnboardingDataAssistantEvent(type='onboarding_data_assistant_request.received', organization_id=UUID('a1b6dead-42ad-4938-b2a7-e213206c9f53'), datasource_name='abc', data_asset_name='boo', expectation_suite_name=None)

def test_parse_event_missing_required_field(example_event):
event_dict = example_event.dict(exclude={"datasource_name"})
serialized_bytes = orjson.dumps(event_dict)
> event = EventHandler.parse_event_from(serialized_bytes)

tests/agent/test_event_handler.py:335:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
great_expectations_cloud/agent/event_handler.py:109: in parse_event_from
LOGGER.exception("Unable to parse event type", extra={"msg_body": f"{msg_body!r}"})
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1512: in exception
self.error(msg, *args, exc_info=exc_info, **kwargs)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1506: in error
self._log(ERROR, msg, args, **kwargs)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1624: in _log
self.handle(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1634: in handle
self.callHandlers(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1696: in callHandlers
hdlr.handle(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:968: in handle
self.emit(record)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10....../site-packages/_pytest/logging.py:386: in emit
super().emit(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1108: in emit
self.handleError(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:1100: in emit
msg = self.format(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:943: in format
return fmt.format(record)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10....../site-packages/_pytest/logging.py:139: in format
return super().format(record)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:686: in format
record.exc_text = self.formatException(record.exc_info)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/logging/__init__.py:636: in formatException
traceback.print_exception(ei[0], ei[1], tb, None, sio)
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/traceback.py:119: in print_exception
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
../../../..../pypoetry/virtualenvs/great-expectations-cloud-dnvvXDHn-py3.10/lib/python3.10.../site-packages/exceptiongroup/_formatting.py:96: in __init__
self.stack = traceback.StackSummary.extract(
.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/traceback.py:364: in extract
for f, lineno in frame_gen:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

tb = 'c'

def walk_tb(tb):
"""Walk a traceback yielding the frame and line number for each frame.

This will follow tb.tb_next (and thus is in the opposite order to
walk_stack). Usually used with StackSummary.extract.
"""
while tb is not None:
> yield tb.tb_frame, tb.tb_lineno
E AttributeError: 'str' object has no attribute 'tb_frame'

.../hostedtoolcache/Python/3.10.14........................................../x64/lib/python3.10/traceback.py:329: AttributeError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@Kilo59 Kilo59 marked this pull request as ready for review June 6, 2024 20:22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be included in changes?

Copy link
Member Author

@Kilo59 Kilo59 Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of the README update to better explain where the env variables come from.

cc @joshzzheng

import os

# throw error if file does not exist
initial_vars: set[str] = set(os.environ.keys()) # noqa: TID251 # we aren't actually using these vars
Copy link
Contributor

@rreinoldsc rreinoldsc Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to avoid loading all the user's env vars. Can the following be used instead:

from dotenv import dotenv_values

config = dotenv_values(".env")

"returns a dict with the values parsed from the .env file."

https://pypi.org/project/python-dotenv/#load-configuration-without-altering-the-environment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi doing above would mean we cannot merge system env vars + .env

Copy link
Member Author

@Kilo59 Kilo59 Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the concern here?

Users have to opt-in to load their environment variables in 2 different ways.

  1. By creating a env file and specifically putting the variables they want loaded into it.
  2. By explicitly passing that file to gx-agent --env-file

We are never directly accessing any env variable values in the agent code.

Copy link
Member Author

@Kilo59 Kilo59 Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that we would selectively load environment variables from the env file?
That would be a departure from how .env file loading typically works.

Or are you just saying you want me to use dotenv_values() to determine which env variables were loaded (instead of doing the set difference operation)?

Edit:

I've updated the implementation.

@Kilo59
Copy link
Member Author

Kilo59 commented Jun 7, 2024

I don't understand the test failures I'm seeing.

The only way I could see the changes I've added affecting these tests is if they were relying on some prior env variable state, which my clean_gx_env fixture is removing.

AttributeError: 'str' object has no attribute 'tb_frame'
FAILED tests/agent/test_event_handler.py::test_parse_event_extra_field - AttributeError: 'str' object has no attribute 'tb_frame'
FAILED tests/agent/test_event_handler.py::test_parse_event_missing_required_field - AttributeError: 'str' object has no attribute 'tb_frame'
FAILED tests/agent/test_event_handler.py::test_parse_event_invalid_json - AttributeError: 'str' object has no attribute 'tb_frame'

@Kilo59 Kilo59 requested a review from rreinoldsc June 10, 2024 19:23
Comment on lines +38 to +43
--json-log Output logs in JSON format. Defaults to False.
--log-cfg-file LOG_CFG_FILE
Path to a logging configuration json file. Supersedes --log-level and --skip-log-file.
--version Show the GX Agent version.
Path to a logging configuration file in JSON format. Supersedes --log-level and --skip-log-file.
--custom-log-tags CUSTOM_LOG_TAGS
Additional tags for logs in form of key-value pairs
--version Show the gx agent version.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These args aren't new but the Readme example hadn't been updated in awhile.

@mirie mirie removed the request for review from JennyTee August 6, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants