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

[AIRFLOW-1526] Add dingding hook and operator #4895

Merged
merged 1 commit into from
Mar 29, 2019

Conversation

zhongjiajie
Copy link
Member

@zhongjiajie zhongjiajie commented Mar 11, 2019

Dingding is popular team collaboration tools talk
just like Slack. This PR is add it to master, could
help us easy send message to Dingding.

Change db.py add conn dingding_webhook_default, could
easy configure dingding message due the host is constant

Add how to operator dingding section tell users
how to send different kind of dingding message or
how to use dingding as callback funtion in DAG
and add example to show how to use.

Set operator UI color as dingding icon color

Make sure you have checked all steps below.

Jira

  • My PR addresses the following Airflow Jira issues and references them in the PR title. For example, "[AIRFLOW-XXX] My Airflow PR"
    • In case you are fixing a typo in the documentation you can prepend your commit with [AIRFLOW-XXX], code changes always need a Jira issue.
    • https://issues.apache.org/jira/browse/AIRFLOW-1526
    • In case you are proposing a fundamental code change, you need to create an Airflow Improvement Proposal(AIP).

Description

  • Here are some details about my PR, including screenshots of any UI changes:

Add dingding (popular team collaboration tools in China) hook and operator to master,

Tests

  • My PR adds the following unit tests :

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • When adding new operators/hooks/sensors, the autoclass documentation generation needs to be added.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

Code Quality

  • Passes flake8

@mik-laj
Copy link
Member

mik-laj commented Mar 11, 2019

Do you think it is a good idea to allow tokens to be passed as an operator parameter? For me it is not safe.
First, operator parameters are not stored securely. Connection use a fernet
Reference: https://airflow.readthedocs.io/en/latest/howto/secure-connections.html#rotating-encryption-keys
Second: operators parameters is available in UI. This extends the group of people who have access to the token.
0 0 0 0_8009_task_execution_date=2019-03-09T00%3A00%3A00%2B00%3A00 dag_id=example_bash_operator task_id=runme_0

Similar comment from today: https://github.com/apache/airflow/pull/4891/files#r264048383

@zhongjiajie
Copy link
Member Author

@mik-laj This PR have to way to pass token, One is pass token by Operator, another is set it in dingding_webhook_default connection.
Second way have no safe problem, allow pass to operator just provide other way to send message.

@mik-laj
Copy link
Member

mik-laj commented Mar 11, 2019

I know there are two ways but I think one of them is not safe and should not be supported. First, security should be a standard, not an option to choose from. people are too lazy and therefore do not make good choices about security. Second, the code of operators that is in the core is used to learning and therefore it should not have security flaws.

I develop a operators for GCP Transfer Service. and I intentionally blocked the passing of passwords as parameters to limit the misuse of the operator.
https://github.com/apache/airflow/pull/4792/files#diff-1f5fe79c9bd42285838bf61cf696ea2bR136

@zhongjiajie
Copy link
Member Author

@mik-laj Ok, your right, I will remove pass token from operator. do you think I should add some docs to describe in howto let people know how to use this hook or operator?

@XD-DENG
Copy link
Member

XD-DENG commented Mar 11, 2019

The implementation is a bit tricky to me. It's dependent on the Dingtalk's single API endpoint (https://oapi.dingtalk.com).

The scope of this PR itself is similar to Slack-related hooks/operators. However, they were implemented on top of slackclient (https://github.com/apache/airflow/blob/master/airflow/hooks/slack_hook.py)

@mik-laj
Copy link
Member

mik-laj commented Mar 11, 2019

@mik-laj
Copy link
Member

mik-laj commented Mar 11, 2019

@zhongjiajie The howto documentation is recommended, but not required. If you have the time and desire then I will be happy when you write.
The guide should contain such sections:

  • short description of service,
  • the scenario - not required
  • prerequisite tasks,
  • how to use.

Good example is: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-creating-buckets.html

Fragment of the code should be attached using the literalinclude directive. It allows its automatic validation and allows to add link to full file ( #4894 )

Currently, the guides do not contain all sections, but I plan to develop them.

@zhongjiajie
Copy link
Member Author

zhongjiajie commented Mar 11, 2019

The implementation is a bit tricky to me. It's dependent on the Dingtalk's single API endpoint (https://oapi.dingtalk.com).

The scope of this PR itself is similar to Slack-related hooks/operators. However, they were implemented on top of slackclient (https://github.com/apache/airflow/blob/master/airflow/hooks/slack_hook.py)

@XD-DENG slack have officail client, but dingtalk not, as @mik-laj said we have two slack hook, one is base on slackclient another are on webhook.

@zhongjiajie
Copy link
Member Author

CI failed unrelated

@zhongjiajie zhongjiajie force-pushed the hooks_add_dingding_hooks_op branch 2 times, most recently from e7cfb72 to aeb055a Compare March 13, 2019 12:04
@zhongjiajie zhongjiajie changed the title [AIRFLOW-1526] Add dingding hook and operator [WIP][AIRFLOW-1526] Add dingding hook and operator Mar 14, 2019
@zhongjiajie zhongjiajie changed the title [WIP][AIRFLOW-1526] Add dingding hook and operator [AIRFLOW-1526] Add dingding hook and operator Mar 16, 2019
@zhongjiajie
Copy link
Member Author

After today work, I think this PR is ready to review. PTAL @XD-DENG @Fokko thanks.

@zhongjiajie zhongjiajie force-pushed the hooks_add_dingding_hooks_op branch 4 times, most recently from 1c54cbb to fd7c2e5 Compare March 17, 2019 03:52
@codecov-io
Copy link

codecov-io commented Mar 17, 2019

Codecov Report

Merging #4895 into master will decrease coverage by 0.12%.
The diff coverage is 57.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4895      +/-   ##
==========================================
- Coverage   75.81%   75.69%   -0.13%     
==========================================
  Files         458      461       +3     
  Lines       29882    29935      +53     
==========================================
+ Hits        22655    22658       +3     
- Misses       7227     7277      +50
Impacted Files Coverage Δ
.../contrib/example_dags/example_dingding_operator.py 0% <0%> (ø)
airflow/contrib/operators/dingding_operator.py 100% <100%> (ø)
airflow/utils/db.py 90.29% <100%> (+0.09%) ⬆️
airflow/contrib/hooks/dingding_hook.py 66.66% <66.66%> (ø)
airflow/contrib/kubernetes/secret.py 25% <0%> (-44.24%) ⬇️
airflow/contrib/hooks/aws_athena_hook.py 60% <0%> (-5.46%) ⬇️
airflow/contrib/operators/aws_athena_operator.py 70.45% <0%> (-3.02%) ⬇️
airflow/stats.py 68.18% <0%> (-1.52%) ⬇️
airflow/jobs.py 77.49% <0%> (-1.35%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4e24e3...372c6ce. Read the comment docs.

@zhongjiajie
Copy link
Member Author

@mik-laj Add prerequisites,
@XD-DENG PTAL, Thanks.

airflow/contrib/operators/dingding_webhook_operator.py Outdated Show resolved Hide resolved
airflow/contrib/operators/dingding_webhook_operator.py Outdated Show resolved Hide resolved
airflow/utils/db.py Outdated Show resolved Hide resolved
airflow/contrib/hooks/dingding_webhook_hook.py Outdated Show resolved Hide resolved
airflow/contrib/hooks/dingding_webhook_hook.py Outdated Show resolved Hide resolved
@zhongjiajie zhongjiajie force-pushed the hooks_add_dingding_hooks_op branch 2 times, most recently from 5d2d7d9 to ccb4f21 Compare March 22, 2019 19:12
@ashb
Copy link
Member

ashb commented Mar 24, 2019

I edited the docs a bit directly on your branch to improve the English a bit (some of the tenses and plurals were a bit wrong) and to update the instructions about setting up the hook: 19133bc

(We don't need to set the host anymore do we?)

@zhongjiajie
Copy link
Member Author

@ashb Thank for you improvement. About the host, we still have code in
https://github.com/apache/airflow/pull/4895/files#diff-0ddca7f4132e6c4a5dc1ee70d4008085R108
so I think we should let user know their could manual pass host to connection. WDYT?

@zhongjiajie
Copy link
Member Author

zhongjiajie commented Mar 24, 2019

BTW, I am trying improve my English recently 😭

@ashb
Copy link
Member

ashb commented Mar 24, 2019

so I think we should let user know their could manual pass host to connection. WDYT?

Sounds good.

@zhongjiajie
Copy link
Member Author

so I think we should let user know their could manual pass host to connection. WDYT?

Sounds good.

So should I revert describe in https://github.com/apache/airflow/pull/4895/files#diff-a46bd26d7b5231c209f6fa37d2622cc5R29 to tell user could pass host to connection?

@ashb
Copy link
Member

ashb commented Mar 24, 2019

Not revert, but say something like "if you need to change the host used you can set the host field of the connection". (Most people wont need to do this, so the docs shouldn't imply its a required step)

@zhongjiajie
Copy link
Member Author

I update this PR, PTAL, Thanks.

@zhongjiajie zhongjiajie force-pushed the hooks_add_dingding_hooks_op branch 2 times, most recently from f877fcc to 6c914de Compare March 25, 2019 11:08
@zhongjiajie
Copy link
Member Author

@ashb
Copy link
Member

ashb commented Mar 29, 2019

@zhongjiajie Could you rebase please?

Dingding is popular team collaboration tools talk
just like Slack. This PR is add it to master, could
help us easy send message to Dingding.

Change db.py add conn dingding_webhook_default, could
easy configure dingding message due the host is constant

Add how to operator dingding section tell users
how to send different kind of dingding message or
how to use dingding as callback funtion in DAG
and add example to show how to use.

Set operator UI color as dingding icon color
Copy link
Member Author

@zhongjiajie zhongjiajie left a comment

Choose a reason for hiding this comment

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

@ashb I not really sure about the auto api change by @mik-laj , it's that mean we no need to add any content for auto generate api doc?

@@ -28,6 +28,7 @@ information.
.. toctree::
:maxdepth: 2

python
Copy link
Member Author

Choose a reason for hiding this comment

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

Alphabetical order operator

@ashb
Copy link
Member

ashb commented Mar 29, 2019

it's that mean we no need to add any content for auto generate api doc?

Correct, it should automatically picked up from the doc comments on the module and linked.

Screen Shot 2019-03-29 at 11 41 20

@zhongjiajie
Copy link
Member Author

@ashb Thanks.

@zhongjiajie
Copy link
Member Author

@ashb FYI, CI green

@zhongjiajie
Copy link
Member Author

zhongjiajie commented Mar 29, 2019

BTW, could we cherry-pick this PR to 1.10.3 ?

@ashb ashb merged commit 6148509 into apache:master Mar 29, 2019
ashb pushed a commit to ashb/airflow that referenced this pull request Mar 29, 2019
Dingding is popular team collaboration tools talk
just like Slack. This PR is add it to master, could
help us easy send message to Dingding.

Add how to operator dingding section tell users
how to send different kind of dingding message or
how to use dingding as callback funtion in DAG
and add example to show how to use.

Set operator UI color as dingding icon color
@zhongjiajie zhongjiajie deleted the hooks_add_dingding_hooks_op branch March 29, 2019 17:08
@zhongjiajie
Copy link
Member Author

@ashb Thanks 👍

cthenderson pushed a commit to cthenderson/apache-airflow that referenced this pull request Apr 16, 2019
Dingding is popular team collaboration tools talk
just like Slack. This PR is add it to master, could
help us easy send message to Dingding.

Add how to operator dingding section tell users
how to send different kind of dingding message or
how to use dingding as callback funtion in DAG
and add example to show how to use.

Set operator UI color as dingding icon color
andriisoldatenko pushed a commit to andriisoldatenko/airflow that referenced this pull request Jul 26, 2019
Dingding is popular team collaboration tools talk
just like Slack. This PR is add it to master, could
help us easy send message to Dingding.

Add how to operator dingding section tell users
how to send different kind of dingding message or
how to use dingding as callback funtion in DAG
and add example to show how to use.

Set operator UI color as dingding icon color
wmorris75 pushed a commit to modmed/incubator-airflow that referenced this pull request Jul 29, 2019
Dingding is popular team collaboration tools talk
just like Slack. This PR is add it to master, could
help us easy send message to Dingding.

Add how to operator dingding section tell users
how to send different kind of dingding message or
how to use dingding as callback funtion in DAG
and add example to show how to use.

Set operator UI color as dingding icon color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants