1 #pragma once
2
3 #include "types/collection_duration.hpp"
4 #include "types/collection_time_scope.hpp"
5 #include "types/operation_type.hpp"
6
7 #include <chrono>
8 #include <cstdint>
9 #include <ostream>
10 #include <string>
11 #include <vector>
12
13 class MetricParams final
14 {
15 public:
operationType(OperationType val)16 MetricParams& operationType(OperationType val)
17 {
18 operationTypeProperty = val;
19 return *this;
20 }
21
operationType() const22 const OperationType& operationType() const
23 {
24 return operationTypeProperty;
25 }
26
collectionTimeScope(CollectionTimeScope val)27 MetricParams& collectionTimeScope(CollectionTimeScope val)
28 {
29 collectionTimeScopeProperty = val;
30 return *this;
31 }
32
collectionTimeScope() const33 const CollectionTimeScope& collectionTimeScope() const
34 {
35 return collectionTimeScopeProperty;
36 }
37
collectionDuration(CollectionDuration val)38 MetricParams& collectionDuration(CollectionDuration val)
39 {
40 collectionDurationProperty = val;
41 return *this;
42 }
43
collectionDuration() const44 const CollectionDuration& collectionDuration() const
45 {
46 return collectionDurationProperty;
47 }
48
readings(std::vector<std::pair<Milliseconds,double>> value)49 MetricParams& readings(std::vector<std::pair<Milliseconds, double>> value)
50 {
51 readingsProperty = std::move(value);
52 return *this;
53 }
54
readings() const55 const std::vector<std::pair<Milliseconds, double>>& readings() const
56 {
57 return readingsProperty;
58 }
59
expectedReading(Milliseconds delta,double reading)60 MetricParams& expectedReading(Milliseconds delta, double reading)
61 {
62 expectedReadingProperty = std::make_pair(delta, reading);
63 return *this;
64 }
65
expectedReading() const66 const std::pair<Milliseconds, double>& expectedReading() const
67 {
68 return expectedReadingProperty;
69 }
70
expectedIsTimerRequired() const71 bool expectedIsTimerRequired() const
72 {
73 return expectedIsTimerRequiredProperty;
74 }
75
expectedIsTimerRequired(bool value)76 MetricParams& expectedIsTimerRequired(bool value)
77 {
78 expectedIsTimerRequiredProperty = value;
79 return *this;
80 }
81
82 private:
83 OperationType operationTypeProperty = {};
84 CollectionTimeScope collectionTimeScopeProperty = {};
85 CollectionDuration collectionDurationProperty =
86 CollectionDuration(Milliseconds(0u));
87 std::vector<std::pair<Milliseconds, double>> readingsProperty = {};
88 std::pair<Milliseconds, double> expectedReadingProperty = {};
89 bool expectedIsTimerRequiredProperty = true;
90 };
91
operator <<(std::ostream & os,const MetricParams & mp)92 inline std::ostream& operator<<(std::ostream& os, const MetricParams& mp)
93 {
94 using utils::enumToString;
95
96 os << "{ op: " << enumToString(mp.operationType())
97 << ", timeScope: " << enumToString(mp.collectionTimeScope())
98 << ", duration: " << mp.collectionDuration().t.count()
99 << ", readings: { ";
100 for (auto [timestamp, reading] : mp.readings())
101 {
102 os << reading << "(" << timestamp.count() << "ms), ";
103 }
104
105 auto [timestamp, reading] = mp.expectedReading();
106 os << " }, expectedReading: " << reading << "(" << timestamp.count()
107 << "ms), expectedIsTimerRequired: " << std::boolalpha
108 << mp.expectedIsTimerRequired() << " }";
109 return os;
110 }
111