summaryrefslogtreecommitdiff
path: root/src/collector/healthcheck.py
blob: 7d336fd87dc56ae766cc7427dfd76879ecc264b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Send a healthcheck request
"""
import sys
import time
import json

import requests


def check_collector() -> bool:
    """Check our collector using /info

    :return: bool
    """
    time.sleep(2)  # Prevent race condition with redis container healthcheck

    req = requests.get(
        "http://localhost:8000/info",
        timeout=3,
        # verify="./rootCA.crt",
    )

    if req.status_code != 200:
        return False

    data = json.loads(req.text)
    if isinstance(data["estimated document count"], int) and data["estimated document count"] >= 0:
        return req.status_code == 200

    return False


if __name__ == "__main__":
    if sys.argv[1] == "COLLECTOR":
        if check_collector():
            sys.exit(0)
    sys.exit(1)