diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/quota/scripts/telemetry.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/quota/scripts/telemetry.py')
-rw-r--r-- | dom/quota/scripts/telemetry.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/dom/quota/scripts/telemetry.py b/dom/quota/scripts/telemetry.py new file mode 100644 index 0000000000..a62abd62b1 --- /dev/null +++ b/dom/quota/scripts/telemetry.py @@ -0,0 +1,54 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +import requests + + +def query(key, query, p_params): + headers = {"Authorization": "Key {}".format(key)} + start_url = "https://sql.telemetry.mozilla.org/api/" "queries/{}/refresh?{}".format( + query, p_params + ) + print(start_url) + resp = requests.post(url=start_url, headers=headers) + job = resp.json()["job"] + jid = job["id"] + print("Started job {}".format(jid)) + + poll_url = "https://sql.telemetry.mozilla.org/api/" "jobs/{}".format(jid) + print(poll_url) + poll = True + status = 0 + qresultid = 0 + while poll: + print(".", end="", flush=True) + resp = requests.get(url=poll_url, headers=headers) + status = resp.json()["job"]["status"] + if status > 2: + # print(resp.json()) + poll = False + qresultid = resp.json()["job"]["query_result_id"] + else: + time.sleep(0.2) + print(".") + print("Finished with status {}".format(status)) + + if status == 3: + fetch_url = ( + "https://sql.telemetry.mozilla.org/api/" + "queries/78691/results/{}.json".format(qresultid) + ) + print(fetch_url) + resp = requests.get(url=fetch_url, headers=headers) + return resp.json() + + return {"query_result": {"data": {"rows": {}}}} + + +def getLastEventTimeAbs(rows): + if len(rows) == 0: + return 0 + return rows[len(rows) - 1]["submit_timeabs"] |