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

Missing LogUri from emr describe-cluster API when executing EmrCreateJobFlowOperator #31480

Closed
2 tasks done
Lee-W opened this issue May 23, 2023 · 2 comments · Fixed by #31482
Closed
2 tasks done

Missing LogUri from emr describe-cluster API when executing EmrCreateJobFlowOperator #31480

Lee-W opened this issue May 23, 2023 · 2 comments · Fixed by #31482
Labels
area:providers kind:bug This is a clearly a bug provider:amazon-aws AWS/Amazon - related issues

Comments

@Lee-W
Copy link
Member

Lee-W commented May 23, 2023

Apache Airflow version

main (development)

What happened

Encounter the following error when executing EmrCreateJobFlowOperator

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/airflow/providers/amazon/aws/operators/emr.py", line 695, in execute
    log_uri=get_log_uri(emr_client=self._emr_hook.conn, job_flow_id=self._job_flow_id),
  File "/usr/local/lib/python3.10/site-packages/airflow/providers/amazon/aws/links/emr.py", line 61, in get_log_uri
    log_uri = S3Hook.parse_s3_url(response["Cluster"]["LogUri"])
KeyError: 'LogUri'

According to the this document, it seems we might not always be able to get ["Cluster"]["LogUri"] and we encounter errors after the release in #31322.

What you think should happen instead

The EmrCreateJobFlowOperator should finish execution without error.

How to reproduce

  1. git clone github.com/apache/airflow/
  2. cd airflow
  3. git checkout c082aec089405ed0399cfee548011b0520be0011 (the main branch when I found this issue)
  4. Add the following DAG to files/dags/ and name it as example_emr.py
import os
from datetime import datetime, timedelta

from airflow import DAG
from airflow.providers.amazon.aws.operators.emr import EmrCreateJobFlowOperator, EmrTerminateJobFlowOperator


JOB_FLOW_OVERRIDES = {
    "Name": "example_emr_sensor_cluster",
    "ReleaseLabel": "emr-5.29.0",
    "Applications": [{"Name": "Spark"}],
    "Instances": {
        "InstanceGroups": [
            {
                "Name": "Primary node",
                "Market": "ON_DEMAND",
                "InstanceRole": "MASTER",
                "InstanceType": "m4.large",
                "InstanceCount": 1,
            },
        ],
        "KeepJobFlowAliveWhenNoSteps": False,
        "TerminationProtected": False,
    },
    "JobFlowRole": "EMR_EC2_DefaultRole"
    "ServiceRole": "EMR_DefaultRole",
}

DEFAULT_ARGS = {
    "execution_timeout": timedelta(hours=6),
    "retries": 2,
    "retry_delay": 60,
}


with DAG(
    dag_id="example_emr_sensor",
    schedule=None,
    start_date=datetime(2022, 1, 1),
    default_args=DEFAULT_ARGS,
    catchup=False,
) as dag:
    create_job_flow = EmrCreateJobFlowOperator(
        task_id="create_job_flow",
        job_flow_overrides=JOB_FLOW_OVERRIDES,
        aws_conn_id="aws_default",
    )

    remove_job_flow = EmrTerminateJobFlowOperator(
        task_id="remove_job_flow",
        job_flow_id=create_job_flow.output,
        aws_conn_id="aws_default",
        trigger_rule="all_done",
    )

    create_job_flow >> remove_job_flow
  1. breeze --python 3.8 --backend sqlite start-airflow
  2. Trigger the DAG from web UI

Operating System

mac OS 13.4

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

No response

Anything else

#31322 (comment)

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@Lee-W Lee-W added area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels May 23, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented May 23, 2023

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

potiuk added a commit to potiuk/airflow that referenced this issue May 23, 2023
When EMR describe-cluster, does not have LogURI information, we
should silently skip persisting the link to XCom rather than fail
on KeyError.

Fixes: apache#31480
Lee-W added a commit to astronomer/astronomer-providers that referenced this issue May 24, 2023
… of EmrCreateJobFlowOperator

EmrCreateJobFlowOperator now fails due to apache/airflow#31480

#1120, #1121, #1123
Lee-W added a commit to astronomer/astronomer-providers that referenced this issue May 24, 2023
… of EmrCreateJobFlowOperator

EmrCreateJobFlowOperator now fails due to apache/airflow#31480

#1120, #1121, #1123
Lee-W added a commit to astronomer/astronomer-providers that referenced this issue May 24, 2023
… of EmrCreateJobFlowOperator

EmrCreateJobFlowOperator now fails due to apache/airflow#31480

#1120, #1121, #1123
@hussein-awala hussein-awala added provider:amazon-aws AWS/Amazon - related issues area:providers and removed area:core needs-triage label for new issues that we didn't triage yet labels May 24, 2023
@hussein-awala
Copy link
Member

According to the this document, it seems we might not always be able to get ["Cluster"]["LogUri"]

The LogUri is returned only when logging option is enabled in the cluster, but the users can keep it disabled, in this case they will get an exception as yours

Lee-W added a commit to astronomer/astronomer-providers that referenced this issue May 24, 2023
Lee-W added a commit to astronomer/astronomer-providers that referenced this issue May 24, 2023
pankajkoti pushed a commit to astronomer/astronomer-providers that referenced this issue May 25, 2023
…1480 (#1140)

Note that this loguri is a fake s3 bucket which doesn't exist and is used only for bypassing this issue

Closes: #1120, #1121, #1123
Lee-W added a commit to astronomer/airflow that referenced this issue May 31, 2023
hussein-awala pushed a commit that referenced this issue May 31, 2023
* fix(providers/amazon): handle missing LogUri in emr describe_cluster API response

#31480

* fix(providers/amazon): disable EMR cluster log link if the log_uri is not found

* fix(providers.amazon): add test cases to get_log_uri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers kind:bug This is a clearly a bug provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
2 participants