Repository navigation
Expand file tree
/
Copy pathsamples.py
More file actions
77 lines (58 loc) · 2.3 KB
/
Copy pathsamples.py
File metadata and controls
77 lines (58 loc) · 2.3 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from __future__ import annotations
from collections.abc import Sequence
from typing import NamedTuple
class Timestamp:
"""A nanosecond-resolution timestamp."""
def __init__(self, sec: float, nsec: float) -> None:
if nsec < 0 or nsec >= 1e9:
raise ValueError(f"Invalid value for nanoseconds in Timestamp: {nsec}")
if sec < 0:
nsec = -nsec
self.sec: int = int(sec)
self.nsec: int = int(nsec)
def __str__(self) -> str:
return f"{self.sec}.{self.nsec:09d}"
def __repr__(self) -> str:
return f"Timestamp({self.sec}, {self.nsec})"
def __float__(self) -> float:
return float(self.sec) + float(self.nsec) / 1e9
def __eq__(self, other: object) -> bool:
return isinstance(other, Timestamp) and self.sec == other.sec and self.nsec == other.nsec
def __ne__(self, other: object) -> bool:
return not self == other
def __gt__(self, other: Timestamp) -> bool:
return self.nsec > other.nsec if self.sec == other.sec else self.sec > other.sec
def __lt__(self, other: Timestamp) -> bool:
return self.nsec < other.nsec if self.sec == other.sec else self.sec < other.sec
# BucketSpan is experimental and subject to change at any time.
class BucketSpan(NamedTuple):
offset: int
length: int
# Timestamp and exemplar are optional.
# Value can be an int or a float.
# Timestamp can be a float containing a unixtime in seconds,
# a Timestamp object, or None.
# Exemplar can be an Exemplar object, or None.
class Exemplar(NamedTuple):
labels: dict[str, str]
value: float
timestamp: float | Timestamp | None = None
# NativeHistogram is experimental and subject to change at any time.
class NativeHistogram(NamedTuple):
count_value: float
sum_value: float
schema: int
zero_threshold: float
zero_count: float
pos_spans: Sequence[BucketSpan] | None = None
neg_spans: Sequence[BucketSpan] | None = None
pos_deltas: Sequence[int] | None = None
neg_deltas: Sequence[int] | None = None
nh_exemplars: Sequence[Exemplar] | None = None
class Sample(NamedTuple):
name: str
labels: dict[str, str] | None
value: float | None
timestamp: float | Timestamp | None = None
exemplar: Exemplar | None = None
native_histogram: NativeHistogram | None = None