|
3 | 3 | # Licensed under a 3-clause BSD style license (see LICENSE) |
4 | 4 | import pytest |
5 | 5 |
|
| 6 | +from datadog_checks.dev.docker import CONTAINER_STABILITY_LOG_PATTERNS, assert_all_discovery_candidates_stable |
6 | 7 | from datadog_checks.flink import FlinkCheck |
7 | 8 |
|
8 | 9 | pytestmark = [pytest.mark.e2e] |
9 | 10 |
|
| 11 | +# Flink logs a harmless startup notice ("Hadoop FS is not available ...: NoClassDefFoundError") |
| 12 | +# with the vanilla `flink` image. Exclude only that known-benign substring so a real error is |
| 13 | +# still caught. |
| 14 | +DISCOVERY_STABILITY_LOG_PATTERNS = tuple( |
| 15 | + pattern if pattern != r'error' else r'(?<!NoClassDefFound)error' for pattern in CONTAINER_STABILITY_LOG_PATTERNS |
| 16 | +) |
| 17 | + |
10 | 18 | # Core metrics that should be present on a freshly-started JobManager, |
11 | 19 | # regardless of whether any Flink job has been submitted. JVM and cluster |
12 | 20 | # metrics are reported as soon as the reporter starts. |
|
20 | 28 | "flink.jobmanager.taskSlotsTotal", |
21 | 29 | ] |
22 | 30 |
|
| 31 | +# Core metrics that should be present on a freshly-started TaskManager, mirroring |
| 32 | +# EXPECTED_CORE_METRICS above but for the other role sharing the same container image. |
| 33 | +EXPECTED_TASKMANAGER_CORE_METRICS = [ |
| 34 | + "flink.taskmanager.Status.JVM.CPU.Load", |
| 35 | + "flink.taskmanager.Status.JVM.Memory.Heap.Used", |
| 36 | + "flink.taskmanager.Status.JVM.Threads.Count", |
| 37 | +] |
| 38 | + |
23 | 39 |
|
24 | 40 | def test_e2e_jobmanager_metrics(dd_agent_check, dd_environment): |
25 | 41 | aggregator = dd_agent_check(dd_environment, rate=True) |
26 | 42 | for metric in EXPECTED_CORE_METRICS: |
27 | 43 | aggregator.assert_metric(metric, at_least=1) |
28 | 44 | aggregator.assert_service_check('flink.openmetrics.health', FlinkCheck.OK) |
| 45 | + |
| 46 | + |
| 47 | +def test_e2e_discovery(dd_agent_check_discovery): |
| 48 | + # Both the jobmanager and taskmanager containers share the same `flink` image, so |
| 49 | + # Autodiscovery finds and configures one instance per container. |
| 50 | + aggregator = dd_agent_check_discovery(rate=True, discovery_min_instances=2) |
| 51 | + |
| 52 | + for metric in EXPECTED_CORE_METRICS: |
| 53 | + aggregator.assert_metric(metric, at_least=1) |
| 54 | + for metric in EXPECTED_TASKMANAGER_CORE_METRICS: |
| 55 | + aggregator.assert_metric(metric, at_least=1) |
| 56 | + aggregator.assert_service_check('flink.openmetrics.health', FlinkCheck.OK) |
| 57 | + |
| 58 | + |
| 59 | +def test_e2e_discovery_all_candidates(dd_agent_check): |
| 60 | + assert_all_discovery_candidates_stable( |
| 61 | + dd_agent_check, FlinkCheck, compose_service='jobmanager', log_patterns=DISCOVERY_STABILITY_LOG_PATTERNS |
| 62 | + ) |
0 commit comments