Skip to content

Commit

Permalink
Remove Duckdb dependency (#19400)
Browse files Browse the repository at this point in the history
* Update datadog_checks_base/CHANGELOG.md

Co-authored-by: Ilia Kurenkov <[email protected]>

* remove duckdb python

* dep

* readme

* readme

* remove duckdb

* remove duckdb

* remove duckdb

* commit

* commit

* commit

* remove duckdb

---------

Co-authored-by: Ilia Kurenkov <[email protected]>
  • Loading branch information
HadhemiDD and iliakur authored Jan 16, 2025
1 parent 5dc1c5c commit fdf1f78
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 24 deletions.
1 change: 0 additions & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ cryptography,PyPI,BSD-3-Clause,Copyright (c) Individual contributors.
cryptography,PyPI,PSF,Copyright (c) Individual contributors.
ddtrace,PyPI,BSD-3-Clause,"Copyright 2016 Datadog, Inc."
dnspython,PyPI,ISC,Copyright (C) Dnspython Contributors
duckdb,PyPI,MIT,Copyright (c) Hannes Muehleisen
flup,Vendor,BSD-3-Clause,Copyright (c) 2005 Allan Saddi. All Rights Reserved.
flup-py3,Vendor,BSD-3-Clause,"Copyright (c) 2005, 2006 Allan Saddi <[email protected]> All rights reserved."
foundationdb,PyPI,Apache-2.0,Copyright 2017 FoundationDB
Expand Down
1 change: 0 additions & 1 deletion agent_requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ confluent-kafka==2.8.0
cryptography==43.0.1
ddtrace==2.10.6
dnspython==2.6.1
duckdb==1.1.1
foundationdb==6.3.24
hazelcast-python-client==5.4.0
in-toto==2.0.0
Expand Down
16 changes: 16 additions & 0 deletions duckdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Follow the instructions below to install and configure this check for an Agent r
The DuckDB check is included in the [Datadog Agent][2] package.
No additional installation is needed on your server.

#### Dependencies

The [duckdb][10] client library is required. To install it, ensure you have a working compiler and run:

##### Unix

```text
sudo -Hu dd-agent /opt/datadog-agent/embedded/bin/pip install duckdb==1.1.1
```
##### Windows

```text
"C:\Program Files\Datadog\Datadog Agent\embedded3\python.exe" -m pip install duckdb==1.1.1
```

### Configuration

1. Edit the `duckdb.d/conf.yaml` file, in the `conf.d/` folder at the root of your Agent's configuration directory to start collecting your duckdb performance data. See the [sample duckdb.d/conf.yaml][4] for all available configuration options.
Expand Down Expand Up @@ -65,3 +80,4 @@ Need help? Contact [Datadog support][8].
[7]: https://github.com/DataDog/integrations-core/blob/master/duckdb/metadata.csv
[8]: https://docs.datadoghq.com/help/
[9]: https://duckdb.org/docs/
[10]: https://pypi.org/project/duckdb/
50 changes: 34 additions & 16 deletions duckdb/datadog_checks/duckdb/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
from contextlib import closing, contextmanager
from copy import deepcopy

import duckdb
from datadog_checks.base.errors import CheckException

try:
import duckdb

dk_import_error = None
except ImportError as e:
duckdb = None
dk_import_error = e
raise CheckException(
"Duckdb was not imported correctly, make sure the library is installed."
"Please refer to datadog documentation for more details. Error is %s" % dk_import_error
)

from datadog_checks.base import AgentCheck
from datadog_checks.base.utils.db import QueryManager
Expand Down Expand Up @@ -46,21 +58,27 @@ def __init__(self, name, init_config, instances):
self.check_initializations.append(self._query_manager.compile_queries)

def check(self, _):
retry_delay = 5
max_retries = self.connection_attempt
for attempt in range(1, max_retries + 1):
try:
with self.connect() as conn:
if conn:
self._connection = conn
self._query_manager.execute()
break
except Exception as e:
self.log.warning('Unable to connect to the database: "%s" , retrying...', e)
if attempt < max_retries:
time.sleep(retry_delay)
else:
self.log.error('Max connection retries reached')
if duckdb is None:
raise CheckException(
"Duckdb was not imported correctly, make sure the library is installed."
"Please refer to datadog documentation for more details. Error is %s" % dk_import_error
)
else:
retry_delay = 5
max_retries = self.connection_attempt
for attempt in range(1, max_retries + 1):
try:
with self.connect() as conn:
if conn:
self._connection = conn
self._query_manager.execute()
break
except Exception as e:
self.log.warning('Unable to connect to the database: "%s" , retrying...', e)
if attempt < max_retries:
time.sleep(retry_delay)
else:
self.log.error('Max connection retries reached')

def _execute_query_raw(self, query):
with closing(self._connection.cursor()) as cursor:
Expand Down
5 changes: 5 additions & 0 deletions duckdb/hatch.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[env.collectors.datadog-checks]

[envs.default]
dependencies = [
"duckdb==1.1.1",
]

[[envs.default.matrix]]
python = ["3.12"]
version = ["1.1.1"]
Expand Down
4 changes: 1 addition & 3 deletions duckdb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ dynamic = [
]

[project.optional-dependencies]
deps = [
"duckdb==1.1.1",
]
deps = []

[project.urls]
Source = "https://github.com/DataDog/integrations-core"
Expand Down
8 changes: 7 additions & 1 deletion duckdb/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

from . import common

E2E_METADATA = {
'start_commands': [
'pip install duckdb==1.1.1',
]
}


@pytest.fixture(scope='session')
def dd_environment():
yield common.DEFAULT_INSTANCE
yield common.DEFAULT_INSTANCE, E2E_METADATA


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions duckdb/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@


@pytest.mark.e2e
def test_e2e(dd_agent_check):
aggregator = dd_agent_check()
def test_e2e(dd_agent_check, instance):
aggregator = dd_agent_check(instance)
aggregator.assert_all_metrics_covered()

0 comments on commit fdf1f78

Please sign in to comment.