Added telemetry system to get information about issues.
This commit is contained in:
@@ -13,6 +13,7 @@ import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
import threading
|
||||
import time
|
||||
from typing import Callable, Mapping, Protocol
|
||||
from urllib.error import HTTPError
|
||||
from urllib.request import Request, urlopen
|
||||
@@ -20,6 +21,11 @@ import zipfile
|
||||
|
||||
from . import __version__
|
||||
from .paths import AppPaths
|
||||
from .telemetry import (
|
||||
classify_network_failure,
|
||||
current_telemetry,
|
||||
network_http_status,
|
||||
)
|
||||
|
||||
|
||||
UMU_LAUNCHER_VERSION = "1.4.4"
|
||||
@@ -156,11 +162,64 @@ def ensure_managed_umu(
|
||||
|
||||
archive = paths.managed_umu_archive(UMU_LAUNCHER_VERSION)
|
||||
if not _verified_archive(archive):
|
||||
_download_archive(
|
||||
archive,
|
||||
timeout_seconds=timeout_seconds,
|
||||
opener=opener,
|
||||
)
|
||||
telemetry = current_telemetry()
|
||||
download_started_at = time.monotonic()
|
||||
if telemetry is not None:
|
||||
telemetry.send_event(
|
||||
"download_started",
|
||||
metadata={
|
||||
"resource_type": "runtime",
|
||||
"mirror_id": "github.com",
|
||||
},
|
||||
context={"operation": "runtime_install", "stage": "download"},
|
||||
)
|
||||
try:
|
||||
_download_archive(
|
||||
archive,
|
||||
timeout_seconds=timeout_seconds,
|
||||
opener=opener,
|
||||
)
|
||||
except BaseException as exc:
|
||||
if telemetry is not None:
|
||||
telemetry.send_event(
|
||||
"download_failed",
|
||||
severity="error",
|
||||
message=str(exc),
|
||||
metadata={
|
||||
"resource_type": "runtime",
|
||||
"duration_ms": round(
|
||||
(time.monotonic() - download_started_at) * 1000
|
||||
),
|
||||
"failure_type": classify_network_failure(exc),
|
||||
"http_status": network_http_status(exc),
|
||||
"retry_count": 0,
|
||||
"resume_used": False,
|
||||
"mirror_id": "github.com",
|
||||
},
|
||||
context={"operation": "runtime_install", "stage": "download"},
|
||||
)
|
||||
raise
|
||||
download_duration = max(0.0, time.monotonic() - download_started_at)
|
||||
download_bytes = archive.stat().st_size
|
||||
if telemetry is not None:
|
||||
telemetry.send_event(
|
||||
"download_completed",
|
||||
metadata={
|
||||
"resource_type": "runtime",
|
||||
"download_bytes": download_bytes,
|
||||
"content_bytes": download_bytes,
|
||||
"duration_ms": round(download_duration * 1000),
|
||||
"average_mbps": _average_mbps(
|
||||
download_bytes,
|
||||
download_duration,
|
||||
),
|
||||
"retry_count": 0,
|
||||
"resume_used": False,
|
||||
"http_status": 200,
|
||||
"mirror_id": "github.com",
|
||||
},
|
||||
context={"operation": "runtime_install", "stage": "download"},
|
||||
)
|
||||
_install_zipapp(archive, destination)
|
||||
result = _result(destination, changed=True)
|
||||
_write_json(
|
||||
@@ -236,6 +295,12 @@ def _download_archive(
|
||||
raise
|
||||
|
||||
|
||||
def _average_mbps(download_bytes: int, duration_seconds: float) -> float | None:
|
||||
if download_bytes <= 0 or duration_seconds <= 0:
|
||||
return None
|
||||
return round((download_bytes * 8) / duration_seconds / 1_000_000, 3)
|
||||
|
||||
|
||||
def _install_zipapp(archive: Path, destination: Path) -> None:
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
temporary = _temporary_path(destination, "tmp")
|
||||
|
||||
Reference in New Issue
Block a user