-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19744 from jan--f/mgr-prometheus-standby-mondown
pybind/mgr/prometheus: add StandbyModule and handle failed MON cluster Reviewed-by: John Spray <john.spray@redhat.com>
- Loading branch information
Showing
2 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
|
||
from mgr_test_case import MgrTestCase | ||
|
||
import logging | ||
import requests | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class TestPrometheus(MgrTestCase): | ||
MGRS_REQUIRED = 3 | ||
|
||
def test_standby(self): | ||
self._assign_ports("prometheus", "server_port") | ||
self._load_module("prometheus") | ||
|
||
original_active = self.mgr_cluster.get_active_id() | ||
|
||
original_uri = self._get_uri("prometheus") | ||
log.info("Originally running at {0}".format(original_uri)) | ||
|
||
self.mgr_cluster.mgr_fail(original_active) | ||
|
||
failed_over_uri = self._get_uri("prometheus") | ||
log.info("After failover running at {0}".format(failed_over_uri)) | ||
|
||
self.assertNotEqual(original_uri, failed_over_uri) | ||
|
||
# The original active daemon should have come back up as a standby | ||
# and serve some html under "/" and an empty answer under /metrics | ||
r = requests.get(original_uri, allow_redirects=False) | ||
self.assertEqual(r.status_code, 200) | ||
r = requests.get(original_uri + "metrics", allow_redirects=False) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.headers["content-type"], "text/plain;charset=utf-8") | ||
|
||
def test_urls(self): | ||
self._assign_ports("prometheus", "server_port") | ||
self._load_module("prometheus") | ||
|
||
base_uri = self._get_uri("prometheus") | ||
|
||
# This is a very simple smoke test to check that the module can | ||
# give us a 200 response to requests. We're not testing that | ||
# the content is correct or even renders! | ||
|
||
urls = [ | ||
"/", | ||
"/metrics" | ||
] | ||
|
||
failures = [] | ||
|
||
for url in urls: | ||
r = requests.get(base_uri + url, allow_redirects=False) | ||
if r.status_code != 200: | ||
failures.append(url) | ||
|
||
log.info("{0}: {1} ({2} bytes)".format( | ||
url, r.status_code, len(r.content) | ||
)) | ||
|
||
self.assertListEqual(failures, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters