This is an automated email from the ASF dual-hosted git repository.

joshfell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 297f4b349c Support creating Datadog connection from the UI and add 
documentation for this conn (#30059)
297f4b349c is described below

commit 297f4b349cea5b63e151fb8dc6defee2073468e3
Author: Hussein Awala <[email protected]>
AuthorDate: Wed Mar 15 14:43:28 2023 +0100

    Support creating Datadog connection from the UI and add documentation for 
this conn (#30059)
    
    * Add datadog connection to the UI connections list
    
    * customize Datadog connection UI
    
    * Add datadog connection documentation
    
    * Apply suggestions from code review
    
    Co-authored-by: Josh Fell <[email protected]>
    
    * Fix static checks
    
    ---------
    
    Co-authored-by: Josh Fell <[email protected]>
---
 airflow/providers/datadog/hooks/datadog.py         | 29 +++++++++++++-
 airflow/providers/datadog/provider.yaml            |  4 ++
 .../connections/datadog.rst                        | 46 ++++++++++++++++++++++
 docs/apache-airflow-providers-datadog/index.rst    |  6 +++
 4 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/datadog/hooks/datadog.py 
b/airflow/providers/datadog/hooks/datadog.py
index 14f2b664d0..670a81594e 100644
--- a/airflow/providers/datadog/hooks/datadog.py
+++ b/airflow/providers/datadog/hooks/datadog.py
@@ -39,6 +39,11 @@ class DatadogHook(BaseHook, LoggingMixin):
     :param datadog_conn_id: The connection to datadog, containing metadata for 
api keys.
     """
 
+    conn_name_attr = "datadog_conn_id"
+    default_conn_name = "datadog_default"
+    conn_type = "datadog"
+    hook_name = "Datadog"
+
     def __init__(self, datadog_conn_id: str = "datadog_default") -> None:
         super().__init__()
         conn = self.get_connection(datadog_conn_id)
@@ -72,7 +77,7 @@ class DatadogHook(BaseHook, LoggingMixin):
         interval: int | None = None,
     ) -> dict[str, Any]:
         """
-        Sends a single datapoint metric to DataDog
+        Sends a single datapoint metric to Datadog
 
         :param metric_name: The name of the metric
         :param datapoint: A single integer or float related to the metric
@@ -152,3 +157,25 @@ class DatadogHook(BaseHook, LoggingMixin):
 
         self.validate_response(response)
         return response
+
+    @staticmethod
+    def get_connection_form_widgets() -> dict[str, Any]:
+        """Returns connection widgets to add to connection form"""
+        from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
+        from flask_babel import lazy_gettext
+        from wtforms import StringField
+
+        return {
+            "api_host": StringField(lazy_gettext("API endpoint"), 
widget=BS3TextFieldWidget()),
+            "api_key": StringField(lazy_gettext("API key"), 
widget=BS3TextFieldWidget()),
+            "app_key": StringField(lazy_gettext("Application key"), 
widget=BS3TextFieldWidget()),
+            "source_type_name": StringField(lazy_gettext("Source type name"), 
widget=BS3TextFieldWidget()),
+        }
+
+    @staticmethod
+    def get_ui_field_behaviour() -> dict[str, Any]:
+        """Returns custom field behaviour"""
+        return {
+            "hidden_fields": ["schema", "login", "password", "port", "extra"],
+            "relabeling": {"host": "Events host name"},
+        }
diff --git a/airflow/providers/datadog/provider.yaml 
b/airflow/providers/datadog/provider.yaml
index 3bd1734a53..f933708d03 100644
--- a/airflow/providers/datadog/provider.yaml
+++ b/airflow/providers/datadog/provider.yaml
@@ -51,3 +51,7 @@ hooks:
   - integration-name: Datadog
     python-modules:
       - airflow.providers.datadog.hooks.datadog
+
+connection-types:
+  - hook-class-name: airflow.providers.datadog.hooks.datadog.DatadogHook
+    connection-type: datadog
diff --git a/docs/apache-airflow-providers-datadog/connections/datadog.rst 
b/docs/apache-airflow-providers-datadog/connections/datadog.rst
new file mode 100644
index 0000000000..dccc1caf68
--- /dev/null
+++ b/docs/apache-airflow-providers-datadog/connections/datadog.rst
@@ -0,0 +1,46 @@
+ .. 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.
+
+.. _howto/connection:kubernetes:
+
+Datadog Connection
+=============================
+
+The Datadog Connection type enables integrations with the Datadog API client.
+
+
+Default Connection IDs
+----------------------
+
+Hooks and sensors related to Datadog use ``datadog_default`` by default.
+
+Configuring the Connection
+--------------------------
+Host
+    Host name to associate with the sent events.
+
+Extra
+    Specify the extra parameters (as a JSON dictionary) that can be used in 
Datadog
+    connection.
+
+    ``api_host``: Datadog `API endpoint 
<https://docs.datadoghq.com/getting_started/site/#access-the-datadog-site>`__
+
+    ``api_key``: Datadog `API key 
<https://docs.datadoghq.com/account_management/api-app-keys/#api-keys>`__
+
+    ``app_key``: Datadog `application key 
<https://docs.datadoghq.com/account_management/api-app-keys/#application-keys>`__
+
+    ``source_type_name``: Datadog `source type name 
<https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value/>`__
 (defaults to my_apps).
diff --git a/docs/apache-airflow-providers-datadog/index.rst 
b/docs/apache-airflow-providers-datadog/index.rst
index 9581b5b587..72aa448133 100644
--- a/docs/apache-airflow-providers-datadog/index.rst
+++ b/docs/apache-airflow-providers-datadog/index.rst
@@ -22,6 +22,12 @@
 Content
 -------
 
+.. toctree::
+    :maxdepth: 1
+    :caption: Guides
+
+    Connection types <connections/datadog>
+
 .. toctree::
     :maxdepth: 1
     :caption: References

Reply via email to