-
Notifications
You must be signed in to change notification settings - Fork 4
/
metric.py
39 lines (33 loc) · 894 Bytes
/
metric.py
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
import dataclasses
import datetime
import json
@dataclasses.dataclass(frozen=True)
class ExceptionMetric:
service: str
stacktrace: list[str]
request: str
params: str
creation_date: str
@staticmethod
def create(
service: str,
stacktrace: list[str],
request: dict | None=None,
params: dict | None=None,
) -> 'ExceptionMetric':
'''
convenience method to create a `ExceptionMetric`
'''
return ExceptionMetric(
creation_date=datetime.datetime.now().isoformat(),
service=service,
stacktrace=stacktrace,
request=json.dumps(request),
params=json.dumps(params),
)
def index_name(
obj: ExceptionMetric,
) -> str:
if isinstance(obj, ExceptionMetric):
return 'cicd_services_exception'
raise NotImplementedError(obj)