Skip to content

Add the option of sending the DAG parser logs to stdout - #25528

Closed
jhtimmins wants to merge 6 commits into
apache:mainfrom
astronomer:send-parser-logs-to-stdout
Closed

jhtimmins wants to merge 6 commits into
apache:mainfrom
astronomer:send-parser-logs-to-stdout

Conversation

@jhtimmins

Copy link
Copy Markdown
Contributor

No description provided.

@uranusjr

uranusjr commented Aug 4, 2022

Copy link
Copy Markdown
Member

I wonder if we should make the config multi-state; file sends to file, stdout to stdout, and maybe we can have others in the future?

@jhtimmins jhtimmins changed the title Add the option of sending the DAG parser logs to stdout DRAFT: Add the option of sending the DAG parser logs to stdout Aug 4, 2022
@apache apache deleted a comment from skyboi1233 Aug 4, 2022
@jhtimmins

Copy link
Copy Markdown
Contributor Author

@uranusjr That's a good idea. I'll do that.

@jhtimmins
jhtimmins force-pushed the send-parser-logs-to-stdout branch from 667b74b to 566f2e1 Compare August 5, 2022 01:37
@jhtimmins jhtimmins changed the title DRAFT: Add the option of sending the DAG parser logs to stdout Add the option of sending the DAG parser logs to stdout Aug 5, 2022
@jhtimmins
jhtimmins requested a review from ashb August 5, 2022 02:33

@uranusjr uranusjr left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with one thing I’m wondering.


COLORED_FORMATTER_CLASS: str = conf.get_mandatory_value('logging', 'COLORED_FORMATTER_CLASS')

DAG_PROCESSOR_LOG_TARGET: bool = conf.get_mandatory_value('scheduler', 'DAG_PROCESSOR_LOG_TARGET')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this belong to scheduler or logging?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm uncertain of the convention here. It seems like logging makes more sense, however, when the logs are sent to files, the proper directory is defined under scheduler.child_process_log_directory. That's why I put it in scheduler.

With that in mind, which do you think makes more sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I’m not sure either, things are a bit all over the place, there’s even a DAG-processor-related config in core. I would probably put it under logging that’s where most scheduler-related logging configs go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok cool, that works for me. Thanks TP!

@kaxil kaxil Aug 5, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We tried to consolidate all the logging configs into the logging section a couple of years back: 046b36f

So that's the goal at least, other configs are marked for deprecation

deprecated_options: Dict[Tuple[str, str], Tuple[str, str, str]] = {
('celery', 'worker_precheck'): ('core', 'worker_precheck', '2.0.0'),
('logging', 'base_log_folder'): ('core', 'base_log_folder', '2.0.0'),
('logging', 'remote_logging'): ('core', 'remote_logging', '2.0.0'),
('logging', 'remote_log_conn_id'): ('core', 'remote_log_conn_id', '2.0.0'),
('logging', 'remote_base_log_folder'): ('core', 'remote_base_log_folder', '2.0.0'),
('logging', 'encrypt_s3_logs'): ('core', 'encrypt_s3_logs', '2.0.0'),
('logging', 'logging_level'): ('core', 'logging_level', '2.0.0'),
('logging', 'fab_logging_level'): ('core', 'fab_logging_level', '2.0.0'),
('logging', 'logging_config_class'): ('core', 'logging_config_class', '2.0.0'),
('logging', 'colored_console_log'): ('core', 'colored_console_log', '2.0.0'),
('logging', 'colored_log_format'): ('core', 'colored_log_format', '2.0.0'),
('logging', 'colored_formatter_class'): ('core', 'colored_formatter_class', '2.0.0'),
('logging', 'log_format'): ('core', 'log_format', '2.0.0'),
('logging', 'simple_log_format'): ('core', 'simple_log_format', '2.0.0'),
('logging', 'task_log_prefix_template'): ('core', 'task_log_prefix_template', '2.0.0'),
('logging', 'log_filename_template'): ('core', 'log_filename_template', '2.0.0'),
('logging', 'log_processor_filename_template'): ('core', 'log_processor_filename_template', '2.0.0'),
('logging', 'dag_processor_manager_log_location'): (
'core',
'dag_processor_manager_log_location',
'2.0.0',
),
('logging', 'task_log_reader'): ('core', 'task_log_reader', '2.0.0'),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so all the logging related configs should be moved there.

Suggested change
DAG_PROCESSOR_LOG_TARGET: bool = conf.get_mandatory_value('scheduler', 'DAG_PROCESSOR_LOG_TARGET')
DAG_PROCESSOR_LOG_TARGET: bool = conf.get_mandatory_value('logging', 'DAG_PROCESSOR_LOG_TARGET')

Comment thread airflow/config_templates/config.yml Outdated
- name: dag_processor_log_target
description: Where to send dag parser logs. If "file",
logs are sent to log files defined by child_process_log_directory.
version_added: 2.3.4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we planning to include this in 2.3.4?

Comment on lines +161 to +164
if DAG_PROCESSOR_LOG_TARGET == "stdout":
with Stats.timer() as timer:
_handle_dag_file_processing()
else:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some test coverage around this flow would be good :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oooof. Alright I'll think out how to do that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kaxil ok running into some issue with testing this. Can you suggest an effective way to test something dependent on the internal behavior of the processor? It appears that no existing tests actually do this.

This is the basic structure of the test I'm adding to test_processor.py.

    @conf_vars({("logging", "dag_processor_log_target"): "file"})
    def test_stuff(self):
        """
        Test that the dag file processor does not call the sla miss callback when
        given an invalid sla
        """
        with create_session() as session:
            processor = DagFileProcessorProcess('abc.txt', False, ["fake_dag_id"], [])
            # processor.start()
            start_method = processor._get_multiprocessing_start_method()
            context = multiprocessing.get_context(start_method)

            _parent_channel, _child_channel = context.Pipe(duplex=False)
            processor._run_file_processor(
                result_channel=_child_channel,
                parent_channel=_parent_channel,
                file_path='abc.txt',
                pickle_dags=False,
                dag_ids=['fake_dag_ids'],
                thread_name='DagFileProcessor0',
                callback_requests=[],
            )
            _child_channel.close()
            del _child_channel

These tests consistently fail with

ERROR tests/dag_processing/test_processor.py::TestDagFileProcessor::test_stuff - RuntimeError: Session must be set before!
FAILED tests/dag_processing/test_processor.py::TestDagFileProcessor::test_stuff - BrokenPipeError: [Errno 32] Broken pipe

I've attempted to address both of these issues without much luck. I've also looked into both going to a higher level to test (Instantiating DagFileProcessorAgent, which creates the DagFileProcessorProcess class), as well as mocking out internal methods called by DagFileProcessorProcess._run_file_processor, but this seems like a brittle approach, at best.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mocking is fine, the only thing I want to test is the if-else flow tbh :)

Comment thread airflow/config_templates/config.yml Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will be 2.4.0, not 2.3.x

Comment thread airflow/dag_processing/processor.py Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants