vnai 2.1.0__tar.gz → 2.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vnai-2.1.0 → vnai-2.1.1}/PKG-INFO +1 -1
- {vnai-2.1.0 → vnai-2.1.1}/pyproject.toml +1 -1
- {vnai-2.1.0 → vnai-2.1.1}/vnai/beam/metrics.py +28 -20
- {vnai-2.1.0 → vnai-2.1.1}/vnai.egg-info/PKG-INFO +1 -1
- {vnai-2.1.0 → vnai-2.1.1}/README.md +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/setup.cfg +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/__init__.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/beam/__init__.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/beam/pulse.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/beam/quota.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/flow/__init__.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/flow/queue.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/flow/relay.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/scope/__init__.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/scope/profile.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/scope/promo.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai/scope/state.py +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai.egg-info/SOURCES.txt +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai.egg-info/dependency_links.txt +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai.egg-info/requires.txt +0 -0
- {vnai-2.1.0 → vnai-2.1.1}/vnai.egg-info/top_level.txt +0 -0
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
_L='success'
|
2
|
+
_K='buffer_size'
|
3
|
+
_J='request'
|
4
|
+
_I='rate_limit'
|
5
|
+
_H='args'
|
5
6
|
_G='execution_time'
|
6
7
|
_F='timestamp'
|
7
|
-
_E=
|
8
|
-
_D=
|
9
|
-
_C=
|
8
|
+
_E=True
|
9
|
+
_D=False
|
10
|
+
_C='error'
|
10
11
|
_B=None
|
11
12
|
_A='function'
|
12
13
|
import sys,time,threading
|
@@ -18,7 +19,7 @@ class Collector:
|
|
18
19
|
with cls._lock:
|
19
20
|
if cls._instance is _B:cls._instance=super(Collector,cls).__new__(cls);cls._instance._initialize()
|
20
21
|
return cls._instance
|
21
|
-
def _initialize(self):self.metrics={_A:[],
|
22
|
+
def _initialize(self):self.metrics={_A:[],_I:[],_J:[],_C:[]};self.thresholds={_K:50,'error_threshold':.1,'performance_threshold':5.};self.function_count=0;self.colab_auth_triggered=_D;self.max_metric_length=200;self._last_record_time={};self.min_interval_per_type=.5;self._recent_hashes=[];self._sending_metrics=_D
|
22
23
|
def record(self,metric_type,data,priority=_B):
|
23
24
|
A='high'
|
24
25
|
if not isinstance(data,dict):data={'value':str(data)}
|
@@ -26,7 +27,7 @@ class Collector:
|
|
26
27
|
if metric_type!='system_info':data.pop('system',_B);from vnai.scope.profile import inspector;data['machine_id']=inspector.fingerprint()
|
27
28
|
now=time.time();last_time=self._last_record_time.get(metric_type,0)
|
28
29
|
if now-last_time<self.min_interval_per_type and priority!=A:return
|
29
|
-
self._last_record_time[metric_type]=now;data_hash=hashlib.md5(json.dumps(data,sort_keys=
|
30
|
+
self._last_record_time[metric_type]=now;data_hash=hashlib.md5(json.dumps(data,sort_keys=_E).encode()).hexdigest()
|
30
31
|
if data_hash in self._recent_hashes and priority!=A:return
|
31
32
|
self._recent_hashes.append(data_hash)
|
32
33
|
if metric_type in self.metrics:
|
@@ -35,31 +36,38 @@ class Collector:
|
|
35
36
|
else:self.metrics[_A].append(data)
|
36
37
|
if metric_type==_A:
|
37
38
|
self.function_count+=1
|
38
|
-
if self.function_count>10 and not self.colab_auth_triggered and'google.colab'in sys.modules:self.colab_auth_triggered=
|
39
|
-
if sum(len(metric_list)for metric_list in self.metrics.values())>=self.thresholds[
|
40
|
-
if priority==A or metric_type==
|
39
|
+
if self.function_count>10 and not self.colab_auth_triggered and'google.colab'in sys.modules:self.colab_auth_triggered=_E;threading.Thread(target=self._trigger_colab_auth,daemon=_E).start()
|
40
|
+
if sum(len(metric_list)for metric_list in self.metrics.values())>=self.thresholds[_K]:self._send_metrics()
|
41
|
+
if priority==A or metric_type==_C:self._send_metrics()
|
41
42
|
def _trigger_colab_auth(self):
|
42
43
|
try:from vnai.scope.profile import inspector;inspector.get_or_create_user_id()
|
43
44
|
except:pass
|
44
45
|
def _send_metrics(self):
|
45
|
-
C='vnai';B='source';A='unknown'
|
46
|
+
C='vnai';B='source';A='unknown'
|
47
|
+
if self._sending_metrics:return
|
48
|
+
self._sending_metrics=_E
|
49
|
+
try:from vnai.flow.relay import track_function_call,track_rate_limit,track_api_request
|
50
|
+
except ImportError:
|
51
|
+
for metric_type in self.metrics:self.metrics[metric_type]=[]
|
52
|
+
self._sending_metrics=_D;return
|
46
53
|
for(metric_type,data_list)in self.metrics.items():
|
47
54
|
if not data_list:continue
|
48
55
|
for data in data_list:
|
49
56
|
try:
|
50
|
-
if metric_type==_A:track_function_call(function_name=data.get(_A,A),source=data.get(B,C),execution_time=data.get(_G,0),success=data.get(
|
51
|
-
elif metric_type==
|
52
|
-
elif metric_type==
|
57
|
+
if metric_type==_A:track_function_call(function_name=data.get(_A,A),source=data.get(B,C),execution_time=data.get(_G,0),success=data.get(_L,_E),error=data.get(_C),args=data.get(_H))
|
58
|
+
elif metric_type==_I:track_rate_limit(source=data.get(B,C),limit_type=data.get('limit_type',A),limit_value=data.get('limit_value',0),current_usage=data.get('current_usage',0),is_exceeded=data.get('is_exceeded',_D))
|
59
|
+
elif metric_type==_J:track_api_request(endpoint=data.get('endpoint',A),source=data.get(B,C),method=data.get('method','GET'),status_code=data.get('status_code',200),execution_time=data.get(_G,0),request_size=data.get('request_size',0),response_size=data.get('response_size',0))
|
53
60
|
except Exception as e:continue
|
54
61
|
self.metrics[metric_type]=[]
|
62
|
+
self._sending_metrics=_D
|
55
63
|
def get_metrics_summary(self):return{metric_type:len(data_list)for(metric_type,data_list)in self.metrics.items()}
|
56
64
|
collector=Collector()
|
57
65
|
def capture(module_type=_A):
|
58
66
|
def decorator(func):
|
59
67
|
def wrapper(*args,**kwargs):
|
60
|
-
start_time=time.time();success=
|
61
|
-
try:result=func(*args,**kwargs);success=
|
62
|
-
except Exception as e:error=str(e);raise
|
63
|
-
finally:execution_time=time.time()-start_time;collector.record(module_type,{_A:func.__name__,_G:execution_time,
|
68
|
+
start_time=time.time();success=_D;error=_B
|
69
|
+
try:result=func(*args,**kwargs);success=_E;return result
|
70
|
+
except Exception as e:error=str(e);collector.record(_C,{_A:func.__name__,_C:error,_H:str(args)[:100]if args else _B});raise
|
71
|
+
finally:execution_time=time.time()-start_time;collector.record(module_type,{_A:func.__name__,_G:execution_time,_L:success,_C:error,_F:datetime.now().isoformat(),_H:str(args)[:100]if args else _B})
|
64
72
|
return wrapper
|
65
73
|
return decorator
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|