Skip to content

No clear celery configuration example using sqs #22863

Closed

Description

@don1uppa

What do you see as an issue?

https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#celery-broker-transport-options

This section is for specifying options which can be passed to the underlying celery broker transport. See: http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-broker_transport_options

So I want to use sqs (fifo) for my celery queue , I can't determine how to fill out this section.
Tried this:

[celery_broker_transport_options]
predefined_queues = { "default": { "region": "us-east-1", "url": "https://sqs.us-east-1.amazonaws.com/xxxx/asg-airflow-dev-queue.fifo", "MessageGroupId": "1", "MessageDeduplicationId": "123" }}

The https://docs.celeryq.dev/en/latest/getting-started/backends-and-brokers/sqs.html document shows this:

broker_transport_options = {
'predefined_queues': {
'my-q': {
'url': 'https://ap-southeast-2.queue.amazonaws.com/123456/my-q',
'access_key_id': 'xxx',
'secret_access_key': 'xxx',
'backoff_policy': {1: 10, 2: 20, 3: 40, 4: 80, 5: 320, 6: 640},
'backoff_tasks': ['svc.tasks.tasks.task1']
}
},
'sts_role_arn': 'arn:aws:iam:::role/STSTest', # optional
'sts_token_timeout': 900 # optional,
message_properties = {
'MessageGroupId': '',
'MessageDeduplicationId': ''
}
}

The closest think I can find is in this but it uses AIRFLOW__CELERY__CELERY_CONFIG_OPTIONS which is also not explained.
#20947

Solving the problem

add necessary example

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. boring-cyborg commented on Apr 8, 2022

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template!

  2. tsugumi-sys commented on May 20, 2022

    @tsugumi-sys

    @don1uppa
    In my case, I need to re-install pycurl and set environment variables like below.

    When I try to use SQS, a worker instance caused errors like ImportError: The curl client requires the pycurl library.
    Next, I try to re-install pycurl and Permission denied error caused (curl-config), so I run pip install pycurl as root and airflow seems to be working in my laptop.

    I also feel it is so haed to understand how to use SQS in airflow from the documents. I am not sure why this settings works for now but this might help?

    Dockerfile

    FROM apache/airflow:2.3.0
    
    ENV AIRFLOW_HOME=/opt/airflow
    ENV ENTRYPOINT_CONTAINER_FILE_PATH=/tmp/entrypoint.sh
    
    ARG ENTRYPOINT_FILE_PATH
    
    USER root
    
    RUN apt-get update && apt-get install -y python3-pip \
        libcurl4-gnutls-dev \
        librtmp-dev \
        python3-dev \
        libpq-dev
    
    COPY ${ENTRYPOINT_FILE_PATH} ${ENTRYPOINT_CONTAINER_FILE_PATH}
    
    RUN chmod +x /tmp/entrypoint.sh
    RUN chown -R airflow: ${AIRFLOW_HOME}
    
    RUN echo "airflow ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
    
    USER airflow
    
    RUN pip uninstall pycurl
    RUN sudo pip install pycurl
    
    WORKDIR ${AIRFLOW_HOME}
    
    ENTRYPOINT [ "/tmp/entrypoint.sh" ]

    .env

    # Airflow envs
    AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres/airflow
    AIRFLOW__CELERY__RESULT_BACKEND=db+postgresql://airflow:airflow@postgres/airflow
    AIRFLOW__CELERY__BROKER_URL=sqs://@<your-sqs-host>
    
    AIRFLOW__CORE__EXECUTOR=CeleryExecutor
    
    AIRFLOW_DAGS_FOLDER_PATH=./dags
    
    AIRFLOW_ADMIN_PASS=test1234
    [email protected]
    
    # AWS
    AWS_ACCESS_KEY_ID=***
    AWS_SECRET_ACCESS_KEY=***
    AWS_DEFAULT_REGION=***
    
    

    docker-compose.yml

    version: '3'
    services:
      postgres:
        image: postgres:13
        environment:
          - POSTGRES_USER=airflow
          - POSTGRES_PASSWORD=airflow
          - POSTGRES_DB=airflow
        volumes:
          - postgres-db-volume:/var/lib/postgresql/data
      airflow-webserver:
        build:
          context: .
          dockerfile: ./Dockerfile
          args:
            - ENTRYPOINT_FILE_PATH=./webserver-entrypoint.sh
        env_file:
          - ./.env
        ports:
          - 8080:8080
        restart: always
        volumes:
          - ${AIRFLOW_DAGS_FOLDER_PATH}:/opt/airflow/dags
      airflow-scheduler:
        build:
          context: .
          dockerfile: ./Dockerfile
          args:
            - ENTRYPOINT_FILE_PATH=./scheduler-entrypoint.sh
        env_file:
          - ./.env
        restart: always
        volumes:
          - ${AIRFLOW_DAGS_FOLDER_PATH}:/opt/airflow/dags
      airflow-worker:
        build:
          context: .
          dockerfile: ./Dockerfile
          args:
            - ENTRYPOINT_FILE_PATH=./worker-entrypoint.sh
        env_file:
          - ./.env
        restart: always
        volumes:
          - ${AIRFLOW_DAGS_FOLDER_PATH}:/opt/airflow/dags
    
    volumes:
      postgres-db-volume:
  3. potiuk commented on May 22, 2022

    @potiuk
    Member

    Can either of you make a PR to documentation with those instructions if you get them working please? @don1uppa and @tsugumi-sys ? This is an easy way to become one of the more than 2000 contributors to Airflow (and basically this is how the documentation is often added - by the users who can not only test it, but also describe it in the way that will be easy for other users to digest. Can I assign one of you to it ?

  4. added
    kind:feature
    and removed
    kind:bug
    on May 22, 2022
  5. tsugumi-sys commented on May 22, 2022

    @tsugumi-sys

    @potiuk
    I’ll do this :) please assign me

  6. potiuk commented on May 22, 2022

    @potiuk
    Member

    @potiuk I’ll do this :) please assign me

    Fantastic! Assigned you!

  7. don1uppa commented on May 22, 2022

    @don1uppa
    Author
  8. added
    contributors-workshop
    on May 27, 2022
  9. brettpalmberg commented on Jun 3, 2022

    @brettpalmberg
    Contributor

    @don1uppa In my case, I need to re-install pycurl and set environment variables like below.

    When I try to use SQS, a worker instance caused errors like ImportError: The curl client requires the pycurl library. Next, I try to re-install pycurl and Permission denied error caused (curl-config), so I run pip install pycurl as root and airflow seems to be working in my laptop.

    I also feel it is so haed to understand how to use SQS in airflow from the documents. I am not sure why this settings works for now but this might help?

    Hello @tsugumi-sys, @don1uppa. I am seeing the same error as @tsugumi-sys related to pycurl with airflow:2.3.1 and SQS as a message broker. Is the pycurl, Permission denied: 'curl-config' error captured in another Issue? (I looked but did not see one).

    PR #24019 provides documentation, but I think there is still an underlying issue with pycurl to support sqs near "out of the box" in apache/airflow Docker images. Here is a trace I see when using image apache/airflow:2.3.1-python3.8 (or -python3.9, I tried both to be sure).

    2022-06-03 00:38:41    [2022-06-03 05:38:41 +0000] [21] [INFO] Handling signal: term
    2022-06-03 00:38:40    [2022-06-03 05:38:40,933: CRITICAL/MainProcess] Unrecoverable error: ImportError('The curl client requires the pycurl library.')
    2022-06-03 00:38:40    Traceback (most recent call last):
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/http/__init__.py", line 18, in get_client
    2022-06-03 00:38:40    return hub._current_http_client
    2022-06-03 00:38:40    AttributeError: 'Hub' object has no attribute '_current_http_client'
    2022-06-03 00:38:40    During handling of the above exception, another exception occurred:
    2022-06-03 00:38:40    Traceback (most recent call last):
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/worker/worker.py", line 203, in start
    2022-06-03 00:38:40    self.blueprint.start(self)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
    2022-06-03 00:38:40    step.start(parent)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/bootsteps.py", line 365, in start
    2022-06-03 00:38:40    return self.obj.start()
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 332, in start
    2022-06-03 00:38:40    blueprint.start(self)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
    2022-06-03 00:38:40    step.start(parent)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 628, in start
    2022-06-03 00:38:40    c.loop(*c.loop_args())
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/celery/worker/loops.py", line 97, in asynloop
    2022-06-03 00:38:40    next(loop)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/hub.py", line 299, in create_loop
    2022-06-03 00:38:40    item()
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/vine/promises.py", line 160, in __call__
    2022-06-03 00:38:40    return self.throw()
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/vine/promises.py", line 157, in __call__
    2022-06-03 00:38:40    retval = fun(*final_args, **final_kwargs)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/transport/SQS.py", line 541, in _schedule_queue
    2022-06-03 00:38:40    self._get_bulk_async(
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/transport/SQS.py", line 558, in _get_bulk_async
    2022-06-03 00:38:40    return self._get_async(queue, maxcount, callback=callback)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/transport/SQS.py", line 568, in _get_async
    2022-06-03 00:38:40    qname, count=count, connection=self.asynsqs(queue=qname),
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/transport/SQS.py", line 771, in asynsqs
    2022-06-03 00:38:40    c = self._asynsqs = AsyncSQSConnection(
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/aws/sqs/connection.py", line 20, in __init__
    2022-06-03 00:38:40    super().__init__(
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/aws/connection.py", line 180, in __init__
    2022-06-03 00:38:40    super().__init__(sqs_connection, http_client,
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/aws/connection.py", line 134, in __init__
    2022-06-03 00:38:40    self._httpclient = http_client or get_client()
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/http/__init__.py", line 20, in get_client
    2022-06-03 00:38:40    client = hub._current_http_client = Client(hub, **kwargs)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/http/__init__.py", line 11, in Client
    2022-06-03 00:38:40    return CurlClient(hub, **kwargs)
    2022-06-03 00:38:40    File "/home/airflow/.local/lib/python3.9/site-packages/kombu/asynchronous/http/curl.py", line 41, in __init__
    2022-06-03 00:38:40    raise ImportError('The curl client requires the pycurl library.')
    2022-06-03 00:38:40    ImportError: The curl client requires the pycurl library.
    

    I tried a few alternatives to fix:

    • Set Environment Variable _PIP_ADDITIONAL_REQUIREMENTS="celery[sqs]". This fails because pip installs as user airflow and install of dependency pycurl requires root permissions to run curl-config, which is part of the pip install.
    • Extend production docker image using steps outlined here. Switching to USER root before the pip install also seemed problematic.

    I would be happy to help, but do not know if/where a fix should be applied. Thank you.

  10. brettpalmberg commented on Jun 6, 2022

    @brettpalmberg
    Contributor

    PR #24019 provides documentation, but I think there is still an underlying issue with pycurl to support sqs near "out of the box" in apache/airflow Docker images. Here is a trace I see when using image apache/airflow:2.3.1-python3.8 (or -python3.9, I tried both to be sure).

    Was able to resolve this by switching to the new recommended method for building customized images post Airflow 2.3.0 using BuildKit (https://airflow.apache.org/docs/docker-stack/build.html#customizing-the-image). Specifically by providing the following --build-arg to the docker build command:

      --build-arg ADDITIONAL_DEV_APT_DEPS="libcurl4-openssl-dev libssl-dev" \
      --build-arg ADDITIONAL_PYTHON_DEPS="celery[sqs]" \
    
  11. potiuk commented on Jun 6, 2022

    @potiuk
    Member

    --build-arg ADDITIONAL_DEV_APT_DEPS="libcurl4-openssl-dev libssl-dev"
    --build-arg ADDITIONAL_PYTHON_DEPS="celery[sqs]" \

    Yeah that 's also part of the docs (the SQS part). We should not add SQS into the image. However it might be a good idea to add liubrcurl*openssl /libssl - so you can add them to a Dockerfile (both Dockerfile and Dockerfile.ci I think would make sense.

  12. tsugumi-sys commented on Jul 3, 2022

    @tsugumi-sys

    @brettpalmberg
    Is this work if you don't use --build-arg ADDITIONAL_PYTHON_DEPS="celery[sqs]" ? And installing libcurl4-openssl-dev libssl-dev throws still the same error ImportError: The curl client requires the pycurl library..

  13. potiuk commented on Sep 20, 2022

    @potiuk
    Member

    This one should be closed as in #24019 we discussed that SQS is not going to be supported unless we made a conscious effort and testing to make it works.

  14. don1uppa commented on Sep 20, 2022

    @don1uppa
    Author
  15. potiuk commented on Sep 20, 2022

    @potiuk
    Member

    It works I use it everyday

    Let me correct this statement

    It works for You and in Your case and in the very exact version of Airlfow, Celery, Kombu that You have installed and in the limited set of cases that Your installation covers. It might or might not work if any of those change. We have no tests to verify that.

    By choosing SQS you take ("with great powers come great responsibilities") responsibilty on your shoulders that you will have to fix any problems that can arise with using SQS - on your own. For example, because we do not have tests, when we release a new version of Airflow we might make it stop working. Or when Amazon makes changes in how SQS works.

    It's quite a huge risks you are taking, because when it will stop workiong, this is not a bug that you can raise and hope that community will fix it. Until we have tests and can easily reproduce and plug-in and automate tests for SQS, any problem with it is your problem and you will have to deal with it.

    You can see an example problem #26521 and if you have any similar problem, it will not be considered a bug, but at most an interesting discussion to have, and you will have to fix it on your own/

  16. don1uppa commented on Sep 20, 2022

    @don1uppa
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

contributors-workshopgood first issuekind:documentationkind:feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions