Skip to content

Commit 737232b

Browse files
committed
remove service check and pin docker version for testing
1 parent 0da1bdd commit 737232b

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

n8n/datadog_checks/n8n/check.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from datadog_checks.n8n.metrics import METRIC_MAP
99

1010
DEFAULT_READY_ENDPOINT = '/healthz/readiness'
11-
DEFAULT_HEALTH_ENDPOINT = '/healthz'
1211
DEFAULT_VERSION_ENDPOINT = '/rest/settings'
1312

1413

@@ -25,7 +24,6 @@ def __init__(self, name, init_config, instances=None):
2524
self.openmetrics_endpoint = self.instance["openmetrics_endpoint"]
2625
self.tags = self.instance.get('tags', [])
2726
self._ready_endpoint = DEFAULT_READY_ENDPOINT
28-
self._health_endpoint = DEFAULT_HEALTH_ENDPOINT
2927
self._version_endpoint = DEFAULT_VERSION_ENDPOINT
3028
# Get the N8N API port if specified, otherwise use the default 5678.
3129
self.server_port = str(self.instance.get('server_port', 5678))
@@ -69,33 +67,20 @@ def _submit_version_metadata(self):
6967
except Exception as e:
7068
self.log.debug("Error retrieving version metadata: %s", e)
7169

72-
def _check_n8n_health(self):
73-
endpoint = urljoin(self.openmetrics_endpoint, self._health_endpoint)
74-
response = self.http.get(endpoint)
75-
76-
# Any 4xx or 5xx response from the API endpoint (/healthz) means the n8n process is not responding
77-
if 400 <= response.status_code and response.status_code < 600:
78-
self.service_check('health.status', AgentCheck.CRITICAL, self.tags)
79-
if response.status_code == 200:
80-
self.service_check('health.status', AgentCheck.OK, self.tags)
81-
else:
82-
self.service_check('health.status', AgentCheck.UNKNOWN, self.tags)
83-
8470
def _check_n8n_readiness(self):
8571
endpoint = urljoin(self.openmetrics_endpoint, self._ready_endpoint)
8672
response = self.http.get(endpoint)
8773

88-
# Any 4xx or 5xx response from the API endpoint (/healthz/readiness)
89-
# means the n8n Database is not ready to accept requests
90-
if 400 <= response.status_code and response.status_code < 600:
91-
self.service_check('health.status', AgentCheck.CRITICAL, self.tags)
92-
if response.status_code == 200:
93-
self.service_check('health.status', AgentCheck.OK, self.tags)
74+
# Check if status_code is available
75+
if response.status_code is None:
76+
self.log.warning("The readiness endpoint did not return a status code")
9477
else:
95-
self.service_check('health.status', AgentCheck.UNKNOWN, self.tags)
78+
metric_tags = self.tags + [f'status_code:{response.status_code}']
79+
80+
# Submit metric with value 1 and status_code as tag
81+
self.gauge('readiness.check', 1, tags=metric_tags)
9682

9783
def check(self, instance):
9884
super().check(instance)
9985
self._submit_version_metadata()
100-
self._check_n8n_health()
10186
self._check_n8n_readiness()

n8n/hatch.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22

33
[[envs.default.matrix]]
44
python = ["3.13"]
5+
6+
version = ["118.1"]
7+
8+
[envs.default.overrides]
9+
matrix.version.env-vars = [
10+
{ key = "N8N_VERSION", value = "118.1", if = ["118.1"] },
11+
]

n8n/metadata.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ n8n.queue.job.waiting.total,gauge,,,,Number of jobs currently waiting in the que
6666
n8n.queue.jobs.count,count,,,,Total number of queue jobs,0,n8n,,,
6767
n8n.queue.jobs.duration.seconds.count,count,,,,The count of job duration in seconds,0,n8n,,,
6868
n8n.queue.jobs.duration.seconds.sum,count,,,,The sum of job duration in seconds,0,n8n,,,
69+
n8n.readiness.check,gauge,,,,Readiness check metric with status code as tag,0,n8n,,,status_code
6970
n8n.version.info,gauge,,,,n8n version info.,0,n8n,,,
7071
n8n.workflow.executions.active,gauge,,,,Number of active workflow executions,0,n8n,,,
7172
n8n.workflow.executions.count,count,,,,Total number of workflow executions,0,n8n,,,

n8n/tests/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM docker.n8n.io/n8nio/n8n:latest
1+
FROM docker.n8n.io/n8nio/n8n:${N8N_VERSION}
22

33
# Set environment variables to enable metrics and logging
44
ENV N8N_METRICS=true \

n8n/tests/test_e2e.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,18 @@
1111
def test_check_n8n_e2e(dd_agent_check, instance):
1212
aggregator = dd_agent_check(instance, rate=True)
1313
aggregator.assert_service_check('n8n.openmetrics.health', ServiceCheck.OK, count=2)
14+
15+
# Assert the readiness check metric is present with status_code tag
16+
aggregator.assert_metric('n8n.readiness.check', value=1, count=1)
17+
18+
# Verify the metric has a status_code tag
19+
metrics = aggregator.metrics('n8n.readiness.check')
20+
assert len(metrics) > 0, "n8n.readiness.check metric not found"
21+
22+
# Check that status_code tag is present
23+
tags = metrics[0].tags
24+
status_code_tags = [tag for tag in tags if tag.startswith('status_code:')]
25+
assert len(status_code_tags) == 1, f"Expected exactly one status_code tag, got {len(status_code_tags)}"
26+
assert status_code_tags[0] == 'status_code:200', f"Expected status_code:200, got {status_code_tags[0]}"
27+
1428
assert_service_checks(aggregator)

n8n/tests/test_unit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

55
from datadog_checks.n8n import N8nCheck
6+
from datadog_checks.dev.utils import get_metadata_metrics
67

78
from . import common
89

@@ -15,6 +16,7 @@ def test_unit_metrics(dd_run_check, instance, aggregator, mock_http_response):
1516
for metric in common.TEST_METRICS:
1617
aggregator.assert_metric(metric)
1718
aggregator.assert_all_metrics_covered()
19+
aggregator.assert_metrics_using_metadata(get_metadata_metrics())
1820

1921

2022
def test_metrics_custom_prefx(dd_run_check, aggregator, mock_http_response):
@@ -29,3 +31,4 @@ def test_metrics_custom_prefx(dd_run_check, aggregator, mock_http_response):
2931
for metric in common.TEST_METRICS:
3032
aggregator.assert_metric(metric)
3133
aggregator.assert_all_metrics_covered()
34+
aggregator.assert_metrics_using_metadata(get_metadata_metrics())

0 commit comments

Comments
 (0)