Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion airflow/providers/datadog/hooks/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -72,7 +77,7 @@ def send_metric(
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
Expand Down Expand Up @@ -152,3 +157,25 @@ def post_event(

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"},
}
4 changes: 4 additions & 0 deletions airflow/providers/datadog/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 46 additions & 0 deletions docs/apache-airflow-providers-datadog/connections/datadog.rst
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 6 additions & 0 deletions docs/apache-airflow-providers-datadog/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
Content
-------

.. toctree::
:maxdepth: 1
:caption: Guides

Connection types <connections/datadog>

.. toctree::
:maxdepth: 1
:caption: References
Expand Down