Debian Codegraph @

valkey/commands/timeseries/info.py

raw
1 from ..helpers import nativestr
2 from .utils import list_to_dict
3
4
5 class TSInfo:
6 """
7 Hold information and statistics on the time-series.
8 Can be created using ``tsinfo`` command
9 https://oss.valkey.com/valkeytimeseries/commands/#tsinfo.
10 """
11
12 rules = []
13 labels = []
14 sourceKey = None
15 chunk_count = None
16 memory_usage = None
17 total_samples = None
18 retention_msecs = None
19 last_time_stamp = None
20 first_time_stamp = None
21
22 max_samples_per_chunk = None
23 chunk_size = None
24 duplicate_policy = None
25
26 def __init__(self, args):
27 """
28 Hold information and statistics on the time-series.
29
30 The supported params that can be passed as args:
31
32 rules:
33 A list of compaction rules of the time series.
34 sourceKey:
35 Key name for source time series in case the current series
36 is a target of a rule.
37 chunkCount:
38 Number of Memory Chunks used for the time series.
39 memoryUsage:
40 Total number of bytes allocated for the time series.
41 totalSamples:
42 Total number of samples in the time series.
43 labels:
44 A list of label-value pairs that represent the metadata
45 labels of the time series.
46 retentionTime:
47 Retention time, in milliseconds, for the time series.
48 lastTimestamp:
49 Last timestamp present in the time series.
50 firstTimestamp:
51 First timestamp present in the time series.
52 maxSamplesPerChunk:
53 Deprecated.
54 chunkSize:
55 Amount of memory, in bytes, allocated for data.
56 duplicatePolicy:
57 Policy that will define handling of duplicate samples.
58
59 Can read more about on
60 https://oss.valkey.com/valkeytimeseries/configuration/#duplicate_policy
61 """
62 response = dict(zip(map(nativestr, args[::2]), args[1::2]))
63 self.rules = response.get("rules")
64 self.source_key = response.get("sourceKey")
65 self.chunk_count = response.get("chunkCount")
66 self.memory_usage = response.get("memoryUsage")
67 self.total_samples = response.get("totalSamples")
68 self.labels = list_to_dict(response.get("labels"))
69 self.retention_msecs = response.get("retentionTime")
70 self.last_timestamp = response.get("lastTimestamp")
71 self.first_timestamp = response.get("firstTimestamp")
72 if "maxSamplesPerChunk" in response:
73 self.max_samples_per_chunk = response["maxSamplesPerChunk"]
74 self.chunk_size = (
75 self.max_samples_per_chunk * 16
76 ) # backward compatible changes
77 if "chunkSize" in response:
78 self.chunk_size = response["chunkSize"]
79 if "duplicatePolicy" in response:
80 self.duplicate_policy = response["duplicatePolicy"]
81 if isinstance(self.duplicate_policy, bytes):
82 self.duplicate_policy = self.duplicate_policy.decode()
83
84 def get(self, item):
85 try:
86 return self.__getitem__(item)
87 except AttributeError:
88 return None
89
90 def __getitem__(self, item):
91 return getattr(self, item)