def test_prometheus_service_api_error_response(self, mock_get): mock_get.return_value.ok = False # Call the service, which will send a request to the server. try: data_from_prom("http://localhost:9090", "{__name__=\".+\"}") self.fail("This should have caused an exception to be thrown!") except RuntimeError: pass
def test_query_resolution_can_be_changed(self, mock_get): metrics_data_high_res = \ data_from_prom(url=PROMETHEUS_URL, query="up", start_time=TEST_TIME - timedelta(minutes=5), end_time=TEST_TIME, resolution="15s") metrics_data_low_res = \ data_from_prom(url=PROMETHEUS_URL, query="up", start_time=TEST_TIME - timedelta(minutes=5), end_time=TEST_TIME, resolution="30s") self.assertLess(metrics_data_low_res['up'].sum(), metrics_data_high_res['up'].sum())
def test_prometheus_service_api_empty_response(self, mock_get): mock_get.return_value.ok = True # Call the service, which will send a request to the server. response = data_from_prom("http://localhost:9090", "{__name__=\".+\"}") # If the request is sent successfully, then I expect a response to be returned. self.assertIsNotNone(response)
def query(args, query, start, end, resolution="1s", slice_size="10min"): """ Get data from Prometheus. Uses: https://goettl79.github.io/parides/ """ dfs = data_from_prom(url=args.prom_url, query=query, start_time=dateutil.parser.parse(start), end_time=dateutil.parser.parse(end), resolution=resolution, freq=slice_size) LOG.debug("Prometheus returned {} data frames".format(len(dfs))) # cocatinate to a single DF rdf = pd.concat(dfs) LOG.debug("Created result data frame with size {} (row, col)".format( rdf.shape)) return rdf
def test_queries_are_not_splitted_for_open_intervals(self, mock): dfs = data_from_prom(url="http://localhost", query="tralala", start_time=datetime(year=2017, month=7, day=14, hour=4, minute=0), end_time=datetime(year=2017, month=7, day=14, hour=4, minute=5), freq="10min") self.assertEqual(1, len(dfs))
def test_query_is_not_splitted_for_default(self, mock): dfs = data_from_prom(url="http://localhost", query="tralala") self.assertEqual(1, len(dfs))
def test_query_is_splitted_with_freq(self, mock): dfs = data_from_prom(url="http://localhost", query="tralala", start_time=datetime(year=2017, month=7, day=14, hour=4, minute=0), end_time=datetime(year=2017, month=7, day=14, hour=4, minute=5), freq="1min") self.assertEqual(5, len(dfs))