Improve docker-related query test failure avoidance

This commit is contained in:
2025-06-18 17:39:16 -04:00
parent def6bab7f4
commit ea397ef889
2 changed files with 18 additions and 17 deletions

View File

@@ -656,15 +656,24 @@ def test_queries():
# If the metric has arguments to use while testing, grab those
args = metric.get("test_args", {})
print("Testing {} [{}]".format(name, ", ".join(["{}={}".format(key, value) for key, value in args.items()])))
# Run the query with the ability to retry, mostly because the PostgreSQL
# docker image restarts during its initialization phase. If the health
# check passes during the first phase, the agent will start testing too
# early and will break when PostgreSQL restarts.
try:
res = sample_metric(dbname, name, args, retry=True)
except MetricVersionError:
print("{} -> Unsupported for this version".format(name))
continue
# When testing against a docker container, we may end up connecting
# before the service is truly up (it restarts during the initialization
# phase). To cope with this, we'll allow a few connection failures.
tries = 5
while True:
# Run the query without the ability to retry
try:
res = sample_metric(dbname, name, args, retry=False)
break
except MetricVersionError:
res = "Unsupported for this version"
break
except psycopg2.OperationalError as e:
print("Error encountered, {} tries left: {}".format(tries, e))
if tries <= 0:
raise
time.sleep(1)
tries -= 1
# Compare the result to the provided sample results
# TODO
print("{} -> {}".format(name, res))