Giter VIP home page Giter VIP logo

Comments (5)

dosubot avatar dosubot commented on June 12, 2024 3

🤖

Hello again @adammarples! It's good to see you back in our issue threads. I hope you're doing well.

I understand that you're experiencing an issue with duplicate log lines when running a CeleryExecutor on Astronomer hosted, using astronomer-cosmos==1.2.5, even after setting AIRFLOW__COSMOS__PROPAGATE_LOGS = "False" or AIRFLOW__COSMOS__PROPAGATE_LOGS=false.

This issue might be due to the logger not correctly picking up the propagate_logs configuration from the Airflow settings. The get_logger function in the Cosmos codebase is trying to read the propagate_logs configuration from the cosmos section of the Airflow configuration. If the configuration is not found, it defaults to True, which means the logs will be propagated to the parent loggers, potentially causing duplicate log lines. You can find this in the cosmos/log.py file.

To prevent duplicate log lines, you need to ensure that the propagate_logs configuration is correctly set in the Airflow configuration. However, you mentioned that you have already tried setting AIRFLOW__COSMOS__PROPAGATE_LOGS = "False" or AIRFLOW__COSMOS__PROPAGATE_LOGS=false, but it didn't work.

This might be due to a mismatch between the environment variable and the configuration option that the get_logger function is trying to read. The get_logger function is looking for propagate_logs in the cosmos section, but the environment variable you're setting is AIRFLOW__COSMOS__PROPAGATE_LOGS.

To resolve this issue, you can try setting the propagate_logs configuration directly in the airflow.cfg file under the cosmos section:

[cosmos]
propagate_logs = False

If this doesn't work, there might be an issue with the way the get_logger function is reading the configuration. You can try modifying the get_logger function to print out the value of propagateLogs after it's read from the configuration to see if it's correctly picking up the setting:

def get_logger(name: str | None = None) -> logging.Logger:
    propagateLogs: bool = True
    if conf.has_option("cosmos", "propagate_logs"):
        propagateLogs = conf.getboolean("cosmos", "propagate_logs")
    print(f"propagateLogs: {propagateLogs}")  # Add this line
    logger = logging.getLogger(name)
    formatter: logging.Formatter = CustomTTYColoredFormatter(fmt=LOG_FORMAT)  # type: ignore
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.propagate = propagateLogs
    return logger

This will help you debug whether the propagate_logs configuration is being correctly read from the Airflow configuration.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

from astronomer-cosmos.

adammarples avatar adammarples commented on June 12, 2024 1

Hi @tatiana, I am just investigating it. It's my bad, it's not a bug, these log propagation changes work fine in main branch but are not included in version 1.2.5, so I'll wait for the update.

from astronomer-cosmos.

tatiana avatar tatiana commented on June 12, 2024 1

@adammarples Sorry - we are really lacking versioned docs, I logged #750 so we don't lose track of this issue.

from astronomer-cosmos.

tatiana avatar tatiana commented on June 12, 2024

@adammarples, thanks for reporting the issue!

This may be a bug, and the robot suggested using the configuration file as a workaround. Could you confirm this works?

A possible fix could be done along these lines:

if not conf.has_section("cosmos"):
conf.add_section("cosmos")
conf.set("cosmos", "propagate_logs", "False")

And we could add a test to make sure things work with the env vars:

def test_propagate_logs_conf():
if not conf.has_section("cosmos"):
conf.add_section("cosmos")
conf.set("cosmos", "propagate_logs", "False")
custom_logger = get_logger("cosmos-log")
assert custom_logger.propagate is False

Would you like to make this contribution?

from astronomer-cosmos.

tatiana avatar tatiana commented on June 12, 2024

@adammarples this change is available in the release 1.3.0a2, in case you'd like to try it out:
https://pypi.org/project/astronomer-cosmos/1.3.0a2/

Since it is a new feature, we didn't release as part of a 1.2 micro release. For some reason we missed to include it in our release notes, I'll fix this:
https://github.com/astronomer/astronomer-cosmos/releases/tag/astronomer-cosmos-v1.3.0a2

from astronomer-cosmos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.