]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/MDSPerfMetricTypes.h
import ceph quincy 17.2.1
[ceph.git] / ceph / src / mgr / MDSPerfMetricTypes.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_MGR_MDS_PERF_METRIC_TYPES_H
5 #define CEPH_MGR_MDS_PERF_METRIC_TYPES_H
6
7 #include <regex>
8 #include <vector>
9 #include <iostream>
10
11 #include "include/denc.h"
12 #include "include/stringify.h"
13
14 #include "mds/mdstypes.h"
15 #include "mgr/Types.h"
16
17 typedef std::vector<std::string> MDSPerfMetricSubKey; // array of regex match
18 typedef std::vector<MDSPerfMetricSubKey> MDSPerfMetricKey;
19
20 enum class MDSPerfMetricSubKeyType : uint8_t {
21 MDS_RANK = 0,
22 CLIENT_ID = 1,
23 };
24
25 struct MDSPerfMetricSubKeyDescriptor {
26 MDSPerfMetricSubKeyType type = static_cast<MDSPerfMetricSubKeyType>(-1);
27 std::string regex_str;
28 std::regex regex;
29
30 bool is_supported() const {
31 switch (type) {
32 case MDSPerfMetricSubKeyType::MDS_RANK:
33 case MDSPerfMetricSubKeyType::CLIENT_ID:
34 return true;
35 default:
36 return false;
37 }
38 }
39
40 MDSPerfMetricSubKeyDescriptor() {
41 }
42 MDSPerfMetricSubKeyDescriptor(MDSPerfMetricSubKeyType type, const std::string &regex_str)
43 : type(type), regex_str(regex_str) {
44 }
45
46 bool operator<(const MDSPerfMetricSubKeyDescriptor &other) const {
47 if (type < other.type) {
48 return true;
49 }
50 if (type > other.type) {
51 return false;
52 }
53 return regex_str < other.regex_str;
54 }
55
56 DENC(MDSPerfMetricSubKeyDescriptor, v, p) {
57 DENC_START(1, 1, p);
58 denc(v.type, p);
59 denc(v.regex_str, p);
60 DENC_FINISH(p);
61 }
62 };
63 WRITE_CLASS_DENC(MDSPerfMetricSubKeyDescriptor)
64
65 std::ostream& operator<<(std::ostream& os, const MDSPerfMetricSubKeyDescriptor &d);
66 typedef std::vector<MDSPerfMetricSubKeyDescriptor> MDSPerfMetricKeyDescriptor;
67
68 template<>
69 struct denc_traits<MDSPerfMetricKeyDescriptor> {
70 static constexpr bool supported = true;
71 static constexpr bool bounded = false;
72 static constexpr bool featured = false;
73 static constexpr bool need_contiguous = true;
74 static void bound_encode(const MDSPerfMetricKeyDescriptor& v, size_t& p) {
75 p += sizeof(uint32_t);
76 const auto size = v.size();
77 if (size) {
78 size_t per = 0;
79 denc(v.front(), per);
80 p += per * size;
81 }
82 }
83 static void encode(const MDSPerfMetricKeyDescriptor& v,
84 ceph::buffer::list::contiguous_appender& p) {
85 denc_varint(v.size(), p);
86 for (auto& i : v) {
87 denc(i, p);
88 }
89 }
90 static void decode(MDSPerfMetricKeyDescriptor& v,
91 ceph::buffer::ptr::const_iterator& p) {
92 unsigned num;
93 denc_varint(num, p);
94 v.clear();
95 v.reserve(num);
96 for (unsigned i=0; i < num; ++i) {
97 MDSPerfMetricSubKeyDescriptor d;
98 denc(d, p);
99 if (!d.is_supported()) {
100 v.clear();
101 return;
102 }
103 try {
104 d.regex = d.regex_str.c_str();
105 } catch (const std::regex_error& e) {
106 v.clear();
107 return;
108 }
109 if (d.regex.mark_count() == 0) {
110 v.clear();
111 return;
112 }
113 v.push_back(std::move(d));
114 }
115 }
116 };
117
118 enum class MDSPerformanceCounterType : uint8_t {
119 CAP_HIT_METRIC = 0,
120 READ_LATENCY_METRIC = 1,
121 WRITE_LATENCY_METRIC = 2,
122 METADATA_LATENCY_METRIC = 3,
123 DENTRY_LEASE_METRIC = 4,
124 OPENED_FILES_METRIC = 5,
125 PINNED_ICAPS_METRIC = 6,
126 OPENED_INODES_METRIC = 7,
127 READ_IO_SIZES_METRIC = 8,
128 WRITE_IO_SIZES_METRIC = 9,
129 };
130
131 struct MDSPerformanceCounterDescriptor {
132 MDSPerformanceCounterType type = static_cast<MDSPerformanceCounterType>(-1);
133
134 bool is_supported() const {
135 switch(type) {
136 case MDSPerformanceCounterType::CAP_HIT_METRIC:
137 case MDSPerformanceCounterType::READ_LATENCY_METRIC:
138 case MDSPerformanceCounterType::WRITE_LATENCY_METRIC:
139 case MDSPerformanceCounterType::METADATA_LATENCY_METRIC:
140 case MDSPerformanceCounterType::DENTRY_LEASE_METRIC:
141 case MDSPerformanceCounterType::OPENED_FILES_METRIC:
142 case MDSPerformanceCounterType::PINNED_ICAPS_METRIC:
143 case MDSPerformanceCounterType::OPENED_INODES_METRIC:
144 case MDSPerformanceCounterType::READ_IO_SIZES_METRIC:
145 case MDSPerformanceCounterType::WRITE_IO_SIZES_METRIC:
146 return true;
147 default:
148 return false;
149 }
150 }
151
152 MDSPerformanceCounterDescriptor() {
153 }
154 MDSPerformanceCounterDescriptor(MDSPerformanceCounterType type) : type(type) {
155 }
156
157 bool operator<(const MDSPerformanceCounterDescriptor &other) const {
158 return type < other.type;
159 }
160
161 bool operator==(const MDSPerformanceCounterDescriptor &other) const {
162 return type == other.type;
163 }
164
165 bool operator!=(const MDSPerformanceCounterDescriptor &other) const {
166 return type != other.type;
167 }
168
169 DENC(MDSPerformanceCounterDescriptor, v, p) {
170 DENC_START(1, 1, p);
171 denc(v.type, p);
172 DENC_FINISH(p);
173 }
174
175 void pack_counter(const PerformanceCounter &c, ceph::buffer::list *bl) const;
176 void unpack_counter(ceph::buffer::list::const_iterator& bl, PerformanceCounter *c) const;
177 };
178 WRITE_CLASS_DENC(MDSPerformanceCounterDescriptor)
179
180 std::ostream& operator<<(std::ostream &os, const MDSPerformanceCounterDescriptor &d);
181 typedef std::vector<MDSPerformanceCounterDescriptor> MDSPerformanceCounterDescriptors;
182
183 template<>
184 struct denc_traits<MDSPerformanceCounterDescriptors> {
185 static constexpr bool supported = true;
186 static constexpr bool bounded = false;
187 static constexpr bool featured = false;
188 static constexpr bool need_contiguous = true;
189 static void bound_encode(const MDSPerformanceCounterDescriptors& v, size_t& p) {
190 p += sizeof(uint32_t);
191 const auto size = v.size();
192 if (size) {
193 size_t per = 0;
194 denc(v.front(), per);
195 p += per * size;
196 }
197 }
198 static void encode(const MDSPerformanceCounterDescriptors& v,
199 ceph::buffer::list::contiguous_appender& p) {
200 denc_varint(v.size(), p);
201 for (auto& i : v) {
202 denc(i, p);
203 }
204 }
205 static void decode(MDSPerformanceCounterDescriptors& v,
206 ceph::buffer::ptr::const_iterator& p) {
207 unsigned num;
208 denc_varint(num, p);
209 v.clear();
210 v.reserve(num);
211 for (unsigned i=0; i < num; ++i) {
212 MDSPerformanceCounterDescriptor d;
213 denc(d, p);
214 if (d.is_supported()) {
215 v.push_back(std::move(d));
216 }
217 }
218 }
219 };
220
221 struct MDSPerfMetricLimit {
222 MDSPerformanceCounterDescriptor order_by;
223 uint64_t max_count;
224
225 MDSPerfMetricLimit() {
226 }
227 MDSPerfMetricLimit(const MDSPerformanceCounterDescriptor &order_by, uint64_t max_count)
228 : order_by(order_by), max_count(max_count) {
229 }
230
231 bool operator<(const MDSPerfMetricLimit &other) const {
232 if (order_by != other.order_by) {
233 return order_by < other.order_by;
234 }
235
236 return max_count < other.max_count;
237 }
238
239 DENC(MDSPerfMetricLimit, v, p) {
240 DENC_START(1, 1, p);
241 denc(v.order_by, p);
242 denc(v.max_count, p);
243 DENC_FINISH(p);
244 }
245 };
246 WRITE_CLASS_DENC(MDSPerfMetricLimit)
247
248 std::ostream &operator<<(std::ostream &os, const MDSPerfMetricLimit &limit);
249 typedef std::set<MDSPerfMetricLimit> MDSPerfMetricLimits;
250
251 struct MDSPerfMetricQuery {
252 MDSPerfMetricKeyDescriptor key_descriptor;
253 MDSPerformanceCounterDescriptors performance_counter_descriptors;
254
255 MDSPerfMetricQuery() {
256 }
257 MDSPerfMetricQuery(const MDSPerfMetricKeyDescriptor &key_descriptor,
258 const MDSPerformanceCounterDescriptors &performance_counter_descriptors)
259 : key_descriptor(key_descriptor),
260 performance_counter_descriptors(performance_counter_descriptors)
261 {
262 }
263
264 bool operator<(const MDSPerfMetricQuery &other) const {
265 if (key_descriptor < other.key_descriptor) {
266 return true;
267 }
268 if (key_descriptor > other.key_descriptor) {
269 return false;
270 }
271 return performance_counter_descriptors < other.performance_counter_descriptors;
272 }
273
274 template <typename L>
275 bool get_key(L&& get_sub_key, MDSPerfMetricKey *key) const {
276 for (auto &sub_key_descriptor : key_descriptor) {
277 MDSPerfMetricSubKey sub_key;
278 if (!get_sub_key(sub_key_descriptor, &sub_key)) {
279 return false;
280 }
281 key->push_back(sub_key);
282 }
283 return true;
284 }
285
286 void get_performance_counter_descriptors(MDSPerformanceCounterDescriptors *descriptors) const {
287 *descriptors = performance_counter_descriptors;
288 }
289
290 template <typename L>
291 void update_counters(L &&update_counter, PerformanceCounters *counters) const {
292 auto it = counters->begin();
293 for (auto &descriptor : performance_counter_descriptors) {
294 // TODO: optimize
295 if (it == counters->end()) {
296 counters->push_back(PerformanceCounter());
297 it = std::prev(counters->end());
298 }
299 update_counter(descriptor, &(*it));
300 it++;
301 }
302 }
303
304 DENC(MDSPerfMetricQuery, v, p) {
305 DENC_START(1, 1, p);
306 denc(v.key_descriptor, p);
307 denc(v.performance_counter_descriptors, p);
308 DENC_FINISH(p);
309 }
310
311 void pack_counters(const PerformanceCounters &counters, ceph::buffer::list *bl) const;
312 };
313 WRITE_CLASS_DENC(MDSPerfMetricQuery)
314
315 std::ostream &operator<<(std::ostream &os, const MDSPerfMetricQuery &query);
316
317 struct MDSPerfCollector : PerfCollector {
318 std::map<MDSPerfMetricKey, PerformanceCounters> counters;
319 std::set<mds_rank_t> delayed_ranks;
320 utime_t last_updated_mono;
321
322 MDSPerfCollector(MetricQueryID query_id)
323 : PerfCollector(query_id) {
324 }
325 };
326
327 struct MDSPerfMetrics {
328 MDSPerformanceCounterDescriptors performance_counter_descriptors;
329 std::map<MDSPerfMetricKey, ceph::buffer::list> group_packed_performance_counters;
330
331 DENC(MDSPerfMetrics, v, p) {
332 DENC_START(1, 1, p);
333 denc(v.performance_counter_descriptors, p);
334 denc(v.group_packed_performance_counters, p);
335 DENC_FINISH(p);
336 }
337 };
338
339 struct MDSPerfMetricReport {
340 std::map<MDSPerfMetricQuery, MDSPerfMetrics> reports;
341 // set of active ranks that have delayed (stale) metrics
342 std::set<mds_rank_t> rank_metrics_delayed;
343
344 DENC(MDSPerfMetricReport, v, p) {
345 DENC_START(1, 1, p);
346 denc(v.reports, p);
347 denc(v.rank_metrics_delayed, p);
348 DENC_FINISH(p);
349 }
350 };
351
352 WRITE_CLASS_DENC(MDSPerfMetrics)
353 WRITE_CLASS_DENC(MDSPerfMetricReport)
354
355 #endif // CEPH_MGR_MDS_PERF_METRIC_TYPES_H