Coverage for src/prisma/_metrics.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-08-27 18:25 +0000

1# copied from https://github.com/prisma/prisma/blob/23d5ef0672372035a84552b6b457197ca19f486d/packages/client/src/runtime/core/engines/common/types/Metrics.ts 

2from __future__ import annotations 

3 

4from typing import Dict, List, Generic, TypeVar, NamedTuple 

5 

6from pydantic import BaseModel 

7 

8from ._compat import GenericModel, model_rebuild 

9 

10__all__ = ( 

11 'Metrics', 

12 'Metric', 

13 'MetricHistogram', 

14) 

15 

16 

17_T = TypeVar('_T') 

18 

19 

20# TODO: check if int / float is right 

21 

22 

23class Metrics(BaseModel): 

24 counters: List[Metric[int]] 

25 gauges: List[Metric[float]] 

26 histograms: List[Metric[MetricHistogram]] 

27 

28 

29class Metric(GenericModel, Generic[_T]): 

30 key: str 

31 value: _T 

32 labels: Dict[str, str] 

33 description: str 

34 

35 

36class MetricHistogram(BaseModel): 

37 sum: float 

38 count: int 

39 buckets: List[HistogramBucket] 

40 

41 

42class HistogramBucket(NamedTuple): 

43 max_value: float 

44 total_count: int 

45 

46 

47model_rebuild(Metric) 

48model_rebuild(Metrics) 

49model_rebuild(MetricHistogram)