def test_https_metrics( self, prometheus_secret_setup, ingress_controller_endpoint, ingress_controller, expected_metrics, ingress_setup, ): # assert http fails req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" ensure_connection(req_url, 400) resp = requests.get(req_url, verify=False) assert ( "Client sent an HTTP request to an HTTPS server" in resp.text and resp.status_code == 400, f"Expected 400 code for http request to /metrics and got {resp.status_code}" ) # assert https succeeds req_url = f"https://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" ensure_response_from_backend(req_url, ingress_setup.ingress_host) resp = requests.get(req_url, verify=False) assert resp.status_code == 200, f"Expected 200 code for /metrics but got {resp.status_code}" resp_content = resp.content.decode("utf-8") for item in expected_metrics: assert item in resp_content
def test_response_code(self, ingress_controller_endpoint, ingress_controller, expected_responses): for uri in expected_responses: req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.port}{uri}" ensure_connection(req_url, expected_responses[uri]) resp = requests.get(req_url) assert resp.status_code == expected_responses[uri],\ f"Expected {expected_responses[uri]} code for {uri} but got {resp.status_code}"
def test_metrics(self, ingress_controller_endpoint, ingress_controller, enable_exporter_port, expected_metrics): req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" ensure_connection(req_url, 200) resp = requests.get(req_url) assert resp.status_code == 200, f"Expected 200 code for /metrics but got {resp.status_code}" resp_content = resp.content.decode('utf-8') for item in expected_metrics: assert item in resp_content
def test_latency_metrics( self, ingress_controller_endpoint, ingress_controller, expected_metrics, ingress_setup, ): ensure_connection(ingress_setup.req_url, 200, {"host": ingress_setup.ingress_host}) resp = requests.get(ingress_setup.req_url, headers={"host": ingress_setup.ingress_host}, verify=False) assert resp.status_code == 200 req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" ensure_connection(req_url, 200) resp = requests.get(req_url) assert resp.status_code == 200, f"Expected 200 code for /metrics but got {resp.status_code}" resp_content = resp.content.decode("utf-8") for item in expected_metrics: assert item in resp_content
def default_server_setup(ingress_controller_endpoint, ingress_controller): ensure_connection( f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.port}/" )