You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "pubudu91 (via GitHub)" <gi...@apache.org> on 2023/11/03 05:53:54 UTC
[PR] Add Jira Notifier implementation [airflow]
pubudu91 opened a new pull request, #35397:
URL: https://github.com/apache/airflow/pull/35397
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
Fixes #35261
Sample usage:
```python
from datetime import datetime
from airflow import DAG
from airflow.operators.bash import BashOperator
from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
with DAG(
"test-dag",
start_date=datetime(2023, 11, 3),
):
BashOperator(
task_id="mytask",
on_failure_callback=[
send_jira_notification(jira_conn_id="my-jira-conn",
description="The task failed",
summary="Airflow Issue 1",
project_id=10000,
issue_type_id=10003,
labels=["airflow-dag-failure"]
)
],
bash_command="fail",
retries=0
)
```
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on PR #35397:
URL: https://github.com/apache/airflow/pull/35397#issuecomment-1793790042
Locally built docs:


A small concern. We added a note saying the feature is only available from >=2.6.0. But in the above screenshots, in the left navigation the version says 2.2.0?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1388924796
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
Pattern aside.. this is an example that we publish in docs so we can change it if we wish.
Isn't `on_failure_callback=ChimeNotifier(...) ` Works the same and is more intuitive?
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
Pattern aside.. this is an example that we publish in docs so we can change it if we wish.
Isn't `on_failure_callback=ChimeNotifier(...)` Works the same and is more intuitive?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on PR #35397:
URL: https://github.com/apache/airflow/pull/35397#issuecomment-1793782902
> Some NIT which might make it better
>
> In general looks good, also check documentation locally
Built and checked the new docs locally. There weren't any issues. Will check again with the suggestions applied.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1382547115
##########
airflow/providers/atlassian/jira/notifications/jira.py:
##########
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from functools import cached_property
+from typing import Any
+
+from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.providers.atlassian.jira.hooks.jira import JiraHook
+
+try:
+ from airflow.notifications.basenotifier import BaseNotifier
+except ImportError:
+ raise AirflowOptionalProviderFeatureException(
+ "Failed to import BaseNotifier. This feature is only available in Airflow versions >= 2.6.0"
+ )
+
+
+class JiraNotifier(BaseNotifier):
+ """
+ Jira notifier for creating Jira issues upon failures.
+
+ :param jira_conn_id: The HTTP connection ID for the Jira instance.
+ :param description: The content for the body of the issue
Review Comment:
```suggestion
:param proxies: Proxies to make the Jira REST API call. Optional
:param description: The content for the body of the issue
```
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG",
Review Comment:
Let's add templates into the example
```suggestion
description="Failure in the DAG {{ dag.dag_id }}",
```
##########
airflow/providers/atlassian/jira/notifications/jira.py:
##########
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from functools import cached_property
+from typing import Any
+
+from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.providers.atlassian.jira.hooks.jira import JiraHook
+
+try:
+ from airflow.notifications.basenotifier import BaseNotifier
+except ImportError:
+ raise AirflowOptionalProviderFeatureException(
+ "Failed to import BaseNotifier. This feature is only available in Airflow versions >= 2.6.0"
+ )
+
+
+class JiraNotifier(BaseNotifier):
+ """
+ Jira notifier for creating Jira issues upon failures.
+
+ :param jira_conn_id: The HTTP connection ID for the Jira instance.
+ :param description: The content for the body of the issue
+ :param summary: The title of the issue
+ :param project_id: The ID of the project under which the issue will be created
+ :param issue_type_id: The ID of the issue category
+ :param labels: The labels to be applied to the issue
+ """
+
+ template_fields = ("description", "summary", "project_id", "issue_type_id", "labels")
+
+ def __init__(
+ self,
+ *,
+ jira_conn_id: str = JiraHook.default_conn_name,
+ proxies: Any | None = None,
+ description: str,
+ summary: str,
+ project_id: int,
+ issue_type_id: int,
+ labels: list[str] = [],
+ ):
+ super().__init__()
+ self.jira_conn_id = jira_conn_id
+ self.proxies = proxies
+ self.description = description
+ self.summary = summary
+ self.project_id = project_id
+ self.issue_type_id = issue_type_id
+ self.labels = labels
Review Comment:
```suggestion
self.labels = labels or []
```
##########
docs/apache-airflow-providers-atlassian-jira/notifications/index.rst:
##########
@@ -0,0 +1,27 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Atlassian Jira Notifications
+============================
+
Review Comment:
Let's add information that it is not available in Airflow below 2.6
```suggestion
.. important:: This feature is only available in Airflow versions >= 2.6.0
```
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="The task failed",
Review Comment:
```suggestion
description="The task {{ ti.task_id }} failed",
```
##########
airflow/providers/atlassian/jira/notifications/jira.py:
##########
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from functools import cached_property
+from typing import Any
+
+from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.providers.atlassian.jira.hooks.jira import JiraHook
+
+try:
+ from airflow.notifications.basenotifier import BaseNotifier
+except ImportError:
+ raise AirflowOptionalProviderFeatureException(
+ "Failed to import BaseNotifier. This feature is only available in Airflow versions >= 2.6.0"
+ )
+
+
+class JiraNotifier(BaseNotifier):
+ """
+ Jira notifier for creating Jira issues upon failures.
+
+ :param jira_conn_id: The HTTP connection ID for the Jira instance.
+ :param description: The content for the body of the issue
+ :param summary: The title of the issue
+ :param project_id: The ID of the project under which the issue will be created
+ :param issue_type_id: The ID of the issue category
+ :param labels: The labels to be applied to the issue
+ """
+
+ template_fields = ("description", "summary", "project_id", "issue_type_id", "labels")
+
+ def __init__(
+ self,
+ *,
+ jira_conn_id: str = JiraHook.default_conn_name,
+ proxies: Any | None = None,
+ description: str,
+ summary: str,
+ project_id: int,
+ issue_type_id: int,
+ labels: list[str] = [],
Review Comment:
Better avoid assign mutable as default arguments
```suggestion
labels: list[str] | None = None,
```
Usual it is edge cases, however better to avoid it, some example about side effect
```python
from __future__ import annotations
class DefaultMutable:
def __init__(self, a: list[str] = []):
self.a = a
class DefaultNone:
def __init__(self, a: list[str] | None = None):
self.a = a or []
x1 = DefaultMutable()
x2 = DefaultMutable()
x3 = DefaultNone()
x4 = DefaultNone()
assert x1 is not x2
x1.a.append("42")
assert x1.a == ["42"]
assert x2.a == ["42"]
assert x3 is not x4
x3.a.append("42")
assert x3.a == ["42"]
assert x4.a == []
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1388950665
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
> Pattern aside.. this is an example that we publish in docs so we can change it if we wish.
Yes, can use either approach. But then it'll look inconsistent with the existing examples in other notifier docs though. e.g., https://airflow.apache.org/docs/apache-airflow-providers-amazon/8.6.0/notifications/chime_notifier_howto_guide.html
> Isn't `on_failure_callback=ChimeNotifier(...)` Works the same and is more intuitive?
Functionally, exactly the same. Personally for me, having an action verb in the name reads better in this context though. Like, on failure, send this notification.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1388924796
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
Pattern aside.. this is an example that we publish in docs so we can change it if we wish.
Isn't `on_failure_callback=ChimeNotifier(...) `Works the same and is more intuitive?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1384405364
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
All the notifiers seem to have followed this pattern. e.g., https://github.com/apache/airflow/blob/ca27772f0aea1c98aa2367d4450bf477ca851d23/airflow/providers/amazon/aws/notifications/chime.py#L64
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1381531187
##########
airflow/providers/atlassian/jira/notifications/jira.py:
##########
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from functools import cached_property
+
+from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.providers.atlassian.jira.hooks.jira import JiraHook
+
+try:
+ from airflow.notifications.basenotifier import BaseNotifier
+except ImportError:
+ raise AirflowOptionalProviderFeatureException(
+ "Failed to import BaseNotifier. This feature is only available in Airflow versions >= 2.6.0"
+ )
+
+
+class JiraNotifier(BaseNotifier):
+ """
+ Jira notifier for creating Jira issues upon failures.
+
+ :param jira_conn_id: The HTTP connection ID for the Jira instance.
+ :param description: The content for the body of the issue
+ :param summary: The title of the issue
+ :param project_id: The ID of the project under which the issue will be created
+ :param issue_type_id: The ID of the issue category
+ :param labels: The labels to be applied to the issue
+ """
+
+ template_fields = ("description", "summary", "project_id", "issue_type_id", "labels")
+
+ def __init__(
+ self,
+ *,
+ jira_conn_id: str = JiraHook.default_conn_name,
+ description: str,
+ summary: str,
+ project_id: int,
+ issue_type_id: int,
+ labels: list[str] = [],
+ ):
+ super().__init__()
+ self.jira_conn_id = jira_conn_id
+ self.description = description
+ self.summary = summary
+ self.project_id = project_id
+ self.issue_type_id = issue_type_id
+ self.labels = labels
+
+ @cached_property
+ def hook(self) -> JiraHook:
+ return JiraHook(self.jira_conn_id)
Review Comment:
IMO, better use keyword arguments
```suggestion
return JiraHook(jira_conn_id=self.jira_conn_id)
```
##########
airflow/providers/atlassian/jira/notifications/jira.py:
##########
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from functools import cached_property
+
+from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.providers.atlassian.jira.hooks.jira import JiraHook
+
+try:
+ from airflow.notifications.basenotifier import BaseNotifier
+except ImportError:
+ raise AirflowOptionalProviderFeatureException(
+ "Failed to import BaseNotifier. This feature is only available in Airflow versions >= 2.6.0"
+ )
+
+
+class JiraNotifier(BaseNotifier):
+ """
+ Jira notifier for creating Jira issues upon failures.
+
+ :param jira_conn_id: The HTTP connection ID for the Jira instance.
+ :param description: The content for the body of the issue
+ :param summary: The title of the issue
+ :param project_id: The ID of the project under which the issue will be created
+ :param issue_type_id: The ID of the issue category
+ :param labels: The labels to be applied to the issue
+ """
+
+ template_fields = ("description", "summary", "project_id", "issue_type_id", "labels")
+
+ def __init__(
+ self,
+ *,
+ jira_conn_id: str = JiraHook.default_conn_name,
+ description: str,
+ summary: str,
+ project_id: int,
+ issue_type_id: int,
+ labels: list[str] = [],
+ ):
+ super().__init__()
+ self.jira_conn_id = jira_conn_id
+ self.description = description
+ self.summary = summary
+ self.project_id = project_id
+ self.issue_type_id = issue_type_id
+ self.labels = labels
+
+ @cached_property
+ def hook(self) -> JiraHook:
+ return JiraHook(self.jira_conn_id)
Review Comment:
[JiraHook](https://github.com/apache/airflow/blob/660cf0678e13ea08a42adabdbbcae56e01fc132b/airflow/providers/atlassian/jira/hooks/jira.py#L41) also supports `proxies` parameter, would be nice if we add it also to the Notifier
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #35397:
URL: https://github.com/apache/airflow/pull/35397#issuecomment-1793580399
Documentation should be pretty simple: copy from one of existed provider, replace by new example (you have in description of PR), change reference to the Notifier classes, build it locally by run `breeze build-docs atlassian.jira` and check it, see:
https://github.com/apache/airflow/blob/main/BREEZE.rst#building-the-documentation
And if you need any help you might ask the questions in the [Slack](https://s.apache.org/airflow-slack) channel `#development-first-pr-support`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1384389827
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
Shouodn't this be `JiraNotifier(...)` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #35397:
URL: https://github.com/apache/airflow/pull/35397#issuecomment-1793866976
> the left navigation the version says 2.2.0?
That is provider version. Providers release cycle are different then Airflow itself
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on PR #35397:
URL: https://github.com/apache/airflow/pull/35397#issuecomment-1793318243
@Taragolis Addressed the above mentioned suggestions. Still working on the tests and the docs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1385706929
##########
docs/apache-airflow-providers-atlassian-jira/notifications/jira-notifier-howto-guide.rst:
##########
@@ -0,0 +1,65 @@
+
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+How-to guide for Atlassian Jira notifications
+=============================================
+
+Introduction
+------------
+The Atlassian Jira notifier (:class:`airflow.providers.atlassian.jira.notifications.jira.JiraNotifier`) allows users to create
+issues in a Jira instance using the various ``on_*_callbacks`` available at both the DAG level and Task level
+
+Example Code
+------------
+
+.. code-block:: python
+
+ from datetime import datetime
+ from airflow import DAG
+ from airflow.operators.bash import BashOperator
+ from airflow.providers.atlassian.jira.notifications.jira import send_jira_notification
+
+ with DAG(
+ "test-dag",
+ start_date=datetime(2023, 11, 3),
+ on_failure_callback=[
+ send_jira_notification(
+ jira_conn_id="my-jira-conn",
+ description="Failure in the DAG {{ dag.dag_id }}",
+ summary="Airflow DAG Issue",
+ project_id=10000,
+ issue_type_id=10003,
+ labels=["airflow-dag-failure"],
+ )
+ ],
+ ):
+ BashOperator(
+ task_id="mytask",
+ on_failure_callback=[
+ send_jira_notification(
Review Comment:
Yeah, this pattern exists from the very first notifier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on code in PR #35397:
URL: https://github.com/apache/airflow/pull/35397#discussion_r1382605196
##########
airflow/providers/atlassian/jira/notifications/jira.py:
##########
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from functools import cached_property
+from typing import Any
+
+from airflow.exceptions import AirflowOptionalProviderFeatureException
+from airflow.providers.atlassian.jira.hooks.jira import JiraHook
+
+try:
+ from airflow.notifications.basenotifier import BaseNotifier
+except ImportError:
+ raise AirflowOptionalProviderFeatureException(
+ "Failed to import BaseNotifier. This feature is only available in Airflow versions >= 2.6.0"
+ )
+
+
+class JiraNotifier(BaseNotifier):
+ """
+ Jira notifier for creating Jira issues upon failures.
+
+ :param jira_conn_id: The HTTP connection ID for the Jira instance.
+ :param description: The content for the body of the issue
+ :param summary: The title of the issue
+ :param project_id: The ID of the project under which the issue will be created
+ :param issue_type_id: The ID of the issue category
+ :param labels: The labels to be applied to the issue
+ """
+
+ template_fields = ("description", "summary", "project_id", "issue_type_id", "labels")
+
+ def __init__(
+ self,
+ *,
+ jira_conn_id: str = JiraHook.default_conn_name,
+ proxies: Any | None = None,
+ description: str,
+ summary: str,
+ project_id: int,
+ issue_type_id: int,
+ labels: list[str] = [],
Review Comment:
Ack. Added it since the labels list is not getting modified within the notifier. But I guess avoiding it altogether and assigning an empty list as you've suggested is better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal merged PR #35397:
URL: https://github.com/apache/airflow/pull/35397
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Jira Notifier implementation [airflow]
Posted by "pubudu91 (via GitHub)" <gi...@apache.org>.
pubudu91 commented on PR #35397:
URL: https://github.com/apache/airflow/pull/35397#issuecomment-1811777632
A kind reminder on this. Are we good to merge?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org