Merge ~seyeongkim/charm-prometheus2:functional_tests into charm-prometheus2:master

Proposed by Seyeong Kim
Status: Merged
Approved by: Eric Chen
Approved revision: 771506be9ff0a0a7ca6fdde408fc851f489d1678
Merged at revision: 1c23e272189b5bd5386b8eb00093fc90ab1a3d3e
Proposed branch: ~seyeongkim/charm-prometheus2:functional_tests
Merge into: charm-prometheus2:master
Diff against target: 64 lines (+26/-6)
1 file modified
src/tests/functional/tests/tests_prometheus.py (+26/-6)
Reviewer Review Type Date Requested Status
JamesLin Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Erhan Sunar (community) Approve
Eric Chen Needs Information
BootStack Reviewers Pending
Review via email: mp+439359@code.launchpad.net

Commit message

fix functional test in case dns_name has IP

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Eric Chen (eric-chen) wrote :

Why the dns_name sometimes is hostname, sometimes is IP?

review: Needs Information
Revision history for this message
Seyeong Kim (seyeongkim) wrote :

I'm not sure.. for now I checked below function in reactive/prometheus.py

def update_prometheus_targets(target):

in this function dns_name is inserted with lookup(unit['hostname']) ( unit is from service["hosts"] )

and I printed that services["hosts"] , it is already includes IP instead of host.

lookup just returns IP I guess it can't find proper domain name in some circumstances.

Revision history for this message
Erhan Sunar (esunar) :
review: Approve
Revision history for this message
JamesLin (jneo8) wrote :

The target is a http interface.

According to the source code of http interface layer: https://github.com/juju-solutions/interface-http/blob/632131b1f122daf6fb601fd4c9f1e4dbb1a92e09/provides.py#L25

The target is possible to be either ip or hostname.
But it's better to explain this inside the code comment or doc-string.

review: Needs Information
Revision history for this message
JamesLin (jneo8) wrote :

Need small fix. Please see my inline comments.

review: Needs Fixing
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
JamesLin (jneo8) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 1c23e272189b5bd5386b8eb00093fc90ab1a3d3e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/tests/functional/tests/tests_prometheus.py b/src/tests/functional/tests/tests_prometheus.py
2index f54e314..0915978 100644
3--- a/src/tests/functional/tests/tests_prometheus.py
4+++ b/src/tests/functional/tests/tests_prometheus.py
5@@ -96,8 +96,15 @@ class BasicPrometheusCharmTest(PrometheusCharmTestBase):
6 with attempt:
7 new_unit = model.get_units("ubuntu")[-1]
8
9- action = model.run_on_unit(new_unit.data["name"], "hostname -f")
10- new_target = action["Stdout"].strip()
11+ # As http interface layer source code,
12+ # https://github.com/juju-solutions/interface-http/
13+ # blob/632131b1f122daf6fb601fd4c9f1e4dbb1a92e09/provides.py#L25
14+ # dns_name has IP or DNS. so checking both of them
15+ action_host = model.run_on_unit(new_unit.data["name"], "hostname -f")
16+ new_target_host = action_host["Stdout"].strip()
17+
18+ action_ip = model.run_on_unit(new_unit.data["name"], "hostname -I")
19+ new_target_ip = action_ip["Stdout"].strip()
20
21 prom_ip = model.get_lead_unit_ip("prometheus2")
22 prom_port = 9090
23@@ -107,7 +114,10 @@ class BasicPrometheusCharmTest(PrometheusCharmTestBase):
24
25 target_found = False
26 for targets in content["data"]["activeTargets"]:
27- if targets["labels"].get("dns_name", None) == new_target:
28+ if targets["labels"].get("dns_name") == new_target_host:
29+ target_found = True
30+
31+ if targets["labels"].get("dns_name") == new_target_ip:
32 target_found = True
33
34 self.assertTrue(target_found)
35@@ -204,8 +214,15 @@ class TlsPrometheusCharmTest(PrometheusCharmTestBase):
36
37 new_unit = model.get_units("ubuntu")[-1]
38
39- action = model.run_on_unit(new_unit.data["name"], "hostname -f")
40- new_target = action["Stdout"].strip()
41+ # As http interface layer source code,
42+ # https://github.com/juju-solutions/interface-http/
43+ # blob/632131b1f122daf6fb601fd4c9f1e4dbb1a92e09/provides.py#L25
44+ # dns_name has IP or DNS. so checking both of them
45+ action_host = model.run_on_unit(new_unit.data["name"], "hostname -f")
46+ new_target_host = action_host["Stdout"].strip()
47+
48+ action_ip = model.run_on_unit(new_unit.data["name"], "hostname -I")
49+ new_target_ip = action_ip["Stdout"].strip()
50
51 prom_ip = model.get_lead_unit_ip("prometheus2")
52 prom_port = 9090
53@@ -216,7 +233,10 @@ class TlsPrometheusCharmTest(PrometheusCharmTestBase):
54 target_found = False
55 all_targets_healthy = 0
56 for targets in content["data"]["activeTargets"]:
57- if targets["labels"].get("dns_name", None) == new_target:
58+ if targets["labels"].get("dns_name") == new_target_host:
59+ target_found = True
60+
61+ if targets["labels"].get("dns_name") == new_target_ip:
62 target_found = True
63
64 if targets["health"] == "up":

Subscribers

People subscribed via source and target branches

to all changes: