]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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_METRIC_TYPES_H | |
5 | #define CEPH_MGR_METRIC_TYPES_H | |
6 | ||
7 | #include <boost/variant.hpp> | |
8 | #include "include/denc.h" | |
f67539c2 | 9 | #include "include/ceph_features.h" |
9f95a23c | 10 | #include "mgr/OSDPerfMetricTypes.h" |
f67539c2 | 11 | #include "mgr/MDSPerfMetricTypes.h" |
9f95a23c TL |
12 | |
13 | enum class MetricReportType { | |
14 | METRIC_REPORT_TYPE_OSD = 0, | |
f67539c2 | 15 | METRIC_REPORT_TYPE_MDS = 1, |
9f95a23c TL |
16 | }; |
17 | ||
18 | struct OSDMetricPayload { | |
19 | static const MetricReportType METRIC_REPORT_TYPE = MetricReportType::METRIC_REPORT_TYPE_OSD; | |
20 | std::map<OSDPerfMetricQuery, OSDPerfMetricReport> report; | |
21 | ||
22 | OSDMetricPayload() { | |
23 | } | |
24 | OSDMetricPayload(const std::map<OSDPerfMetricQuery, OSDPerfMetricReport> &report) | |
25 | : report(report) { | |
26 | } | |
27 | ||
28 | DENC(OSDMetricPayload, v, p) { | |
29 | DENC_START(1, 1, p); | |
30 | denc(v.report, p); | |
31 | DENC_FINISH(p); | |
32 | } | |
33 | }; | |
34 | ||
f67539c2 TL |
35 | struct MDSMetricPayload { |
36 | static const MetricReportType METRIC_REPORT_TYPE = MetricReportType::METRIC_REPORT_TYPE_MDS; | |
37 | MDSPerfMetricReport metric_report; | |
38 | ||
39 | MDSMetricPayload() { | |
40 | } | |
41 | MDSMetricPayload(const MDSPerfMetricReport &metric_report) | |
42 | : metric_report(metric_report) { | |
43 | } | |
44 | ||
45 | DENC(MDSMetricPayload, v, p) { | |
46 | DENC_START(1, 1, p); | |
47 | denc(v.metric_report, p); | |
48 | DENC_FINISH(p); | |
49 | } | |
50 | }; | |
51 | ||
9f95a23c TL |
52 | struct UnknownMetricPayload { |
53 | static const MetricReportType METRIC_REPORT_TYPE = static_cast<MetricReportType>(-1); | |
54 | ||
55 | UnknownMetricPayload() { } | |
56 | ||
57 | DENC(UnknownMetricPayload, v, p) { | |
58 | ceph_abort(); | |
59 | } | |
60 | }; | |
61 | ||
62 | WRITE_CLASS_DENC(OSDMetricPayload) | |
f67539c2 | 63 | WRITE_CLASS_DENC(MDSMetricPayload) |
9f95a23c TL |
64 | WRITE_CLASS_DENC(UnknownMetricPayload) |
65 | ||
66 | typedef boost::variant<OSDMetricPayload, | |
f67539c2 | 67 | MDSMetricPayload, |
9f95a23c TL |
68 | UnknownMetricPayload> MetricPayload; |
69 | ||
70 | class EncodeMetricPayloadVisitor : public boost::static_visitor<void> { | |
71 | public: | |
f67539c2 | 72 | explicit EncodeMetricPayloadVisitor(ceph::buffer::list &bl) : m_bl(bl) { |
9f95a23c TL |
73 | } |
74 | ||
75 | template <typename MetricPayload> | |
76 | inline void operator()(const MetricPayload &payload) const { | |
77 | using ceph::encode; | |
78 | encode(static_cast<uint32_t>(MetricPayload::METRIC_REPORT_TYPE), m_bl); | |
79 | encode(payload, m_bl); | |
80 | } | |
81 | ||
82 | private: | |
f67539c2 | 83 | ceph::buffer::list &m_bl; |
9f95a23c TL |
84 | }; |
85 | ||
86 | class DecodeMetricPayloadVisitor : public boost::static_visitor<void> { | |
87 | public: | |
f67539c2 | 88 | DecodeMetricPayloadVisitor(ceph::buffer::list::const_iterator &iter) : m_iter(iter) { |
9f95a23c TL |
89 | } |
90 | ||
91 | template <typename MetricPayload> | |
92 | inline void operator()(MetricPayload &payload) const { | |
93 | using ceph::decode; | |
94 | decode(payload, m_iter); | |
95 | } | |
96 | ||
97 | private: | |
f67539c2 | 98 | ceph::buffer::list::const_iterator &m_iter; |
9f95a23c TL |
99 | }; |
100 | ||
101 | struct MetricReportMessage { | |
102 | MetricPayload payload; | |
103 | ||
104 | MetricReportMessage(const MetricPayload &payload = UnknownMetricPayload()) | |
105 | : payload(payload) { | |
106 | } | |
107 | ||
f67539c2 TL |
108 | bool should_encode(uint64_t features) const { |
109 | if (!HAVE_FEATURE(features, SERVER_PACIFIC) && | |
110 | boost::get<MDSMetricPayload>(&payload)) { | |
111 | return false; | |
112 | } | |
113 | return true; | |
114 | } | |
115 | ||
116 | void encode(ceph::buffer::list &bl) const { | |
9f95a23c TL |
117 | boost::apply_visitor(EncodeMetricPayloadVisitor(bl), payload); |
118 | } | |
119 | ||
f67539c2 | 120 | void decode(ceph::buffer::list::const_iterator &iter) { |
9f95a23c TL |
121 | using ceph::decode; |
122 | ||
123 | uint32_t metric_report_type; | |
124 | decode(metric_report_type, iter); | |
125 | ||
126 | switch (static_cast<MetricReportType>(metric_report_type)) { | |
127 | case MetricReportType::METRIC_REPORT_TYPE_OSD: | |
128 | payload = OSDMetricPayload(); | |
129 | break; | |
f67539c2 TL |
130 | case MetricReportType::METRIC_REPORT_TYPE_MDS: |
131 | payload = MDSMetricPayload(); | |
132 | break; | |
9f95a23c TL |
133 | default: |
134 | payload = UnknownMetricPayload(); | |
135 | break; | |
136 | } | |
137 | ||
138 | boost::apply_visitor(DecodeMetricPayloadVisitor(iter), payload); | |
139 | } | |
140 | }; | |
141 | ||
142 | WRITE_CLASS_ENCODER(MetricReportMessage); | |
143 | ||
144 | // variant for sending configure message to mgr clients | |
145 | ||
146 | enum MetricConfigType { | |
147 | METRIC_CONFIG_TYPE_OSD = 0, | |
f67539c2 | 148 | METRIC_CONFIG_TYPE_MDS = 1, |
9f95a23c TL |
149 | }; |
150 | ||
151 | struct OSDConfigPayload { | |
152 | static const MetricConfigType METRIC_CONFIG_TYPE = MetricConfigType::METRIC_CONFIG_TYPE_OSD; | |
153 | std::map<OSDPerfMetricQuery, OSDPerfMetricLimits> config; | |
154 | ||
155 | OSDConfigPayload() { | |
156 | } | |
157 | OSDConfigPayload(const std::map<OSDPerfMetricQuery, OSDPerfMetricLimits> &config) | |
158 | : config(config) { | |
159 | } | |
160 | ||
161 | DENC(OSDConfigPayload, v, p) { | |
162 | DENC_START(1, 1, p); | |
163 | denc(v.config, p); | |
164 | DENC_FINISH(p); | |
165 | } | |
166 | }; | |
167 | ||
f67539c2 TL |
168 | struct MDSConfigPayload { |
169 | static const MetricConfigType METRIC_CONFIG_TYPE = MetricConfigType::METRIC_CONFIG_TYPE_MDS; | |
170 | std::map<MDSPerfMetricQuery, MDSPerfMetricLimits> config; | |
171 | ||
172 | MDSConfigPayload() { | |
173 | } | |
174 | MDSConfigPayload(const std::map<MDSPerfMetricQuery, MDSPerfMetricLimits> &config) | |
175 | : config(config) { | |
176 | } | |
177 | ||
178 | DENC(MDSConfigPayload, v, p) { | |
179 | DENC_START(1, 1, p); | |
180 | denc(v.config, p); | |
181 | DENC_FINISH(p); | |
182 | } | |
183 | }; | |
184 | ||
9f95a23c TL |
185 | struct UnknownConfigPayload { |
186 | static const MetricConfigType METRIC_CONFIG_TYPE = static_cast<MetricConfigType>(-1); | |
187 | ||
188 | UnknownConfigPayload() { } | |
189 | ||
190 | DENC(UnknownConfigPayload, v, p) { | |
191 | ceph_abort(); | |
192 | } | |
193 | }; | |
194 | ||
195 | WRITE_CLASS_DENC(OSDConfigPayload) | |
f67539c2 | 196 | WRITE_CLASS_DENC(MDSConfigPayload) |
9f95a23c TL |
197 | WRITE_CLASS_DENC(UnknownConfigPayload) |
198 | ||
199 | typedef boost::variant<OSDConfigPayload, | |
f67539c2 | 200 | MDSConfigPayload, |
9f95a23c TL |
201 | UnknownConfigPayload> ConfigPayload; |
202 | ||
203 | class EncodeConfigPayloadVisitor : public boost::static_visitor<void> { | |
204 | public: | |
f67539c2 | 205 | explicit EncodeConfigPayloadVisitor(ceph::buffer::list &bl) : m_bl(bl) { |
9f95a23c TL |
206 | } |
207 | ||
208 | template <typename ConfigPayload> | |
209 | inline void operator()(const ConfigPayload &payload) const { | |
210 | using ceph::encode; | |
211 | encode(static_cast<uint32_t>(ConfigPayload::METRIC_CONFIG_TYPE), m_bl); | |
212 | encode(payload, m_bl); | |
213 | } | |
214 | ||
215 | private: | |
f67539c2 | 216 | ceph::buffer::list &m_bl; |
9f95a23c TL |
217 | }; |
218 | ||
219 | class DecodeConfigPayloadVisitor : public boost::static_visitor<void> { | |
220 | public: | |
f67539c2 | 221 | DecodeConfigPayloadVisitor(ceph::buffer::list::const_iterator &iter) : m_iter(iter) { |
9f95a23c TL |
222 | } |
223 | ||
224 | template <typename ConfigPayload> | |
225 | inline void operator()(ConfigPayload &payload) const { | |
226 | using ceph::decode; | |
227 | decode(payload, m_iter); | |
228 | } | |
229 | ||
230 | private: | |
f67539c2 | 231 | ceph::buffer::list::const_iterator &m_iter; |
9f95a23c TL |
232 | }; |
233 | ||
234 | struct MetricConfigMessage { | |
235 | ConfigPayload payload; | |
236 | ||
237 | MetricConfigMessage(const ConfigPayload &payload = UnknownConfigPayload()) | |
238 | : payload(payload) { | |
239 | } | |
240 | ||
f67539c2 TL |
241 | bool should_encode(uint64_t features) const { |
242 | if (!HAVE_FEATURE(features, SERVER_PACIFIC) && | |
243 | boost::get<MDSConfigPayload>(&payload)) { | |
244 | return false; | |
245 | } | |
246 | return true; | |
247 | } | |
248 | ||
249 | void encode(ceph::buffer::list &bl) const { | |
9f95a23c TL |
250 | boost::apply_visitor(EncodeConfigPayloadVisitor(bl), payload); |
251 | } | |
252 | ||
f67539c2 | 253 | void decode(ceph::buffer::list::const_iterator &iter) { |
9f95a23c TL |
254 | using ceph::decode; |
255 | ||
256 | uint32_t metric_config_type; | |
257 | decode(metric_config_type, iter); | |
258 | ||
259 | switch (metric_config_type) { | |
260 | case MetricConfigType::METRIC_CONFIG_TYPE_OSD: | |
261 | payload = OSDConfigPayload(); | |
262 | break; | |
f67539c2 TL |
263 | case MetricConfigType::METRIC_CONFIG_TYPE_MDS: |
264 | payload = MDSConfigPayload(); | |
265 | break; | |
9f95a23c TL |
266 | default: |
267 | payload = UnknownConfigPayload(); | |
268 | break; | |
269 | } | |
270 | ||
271 | boost::apply_visitor(DecodeConfigPayloadVisitor(iter), payload); | |
272 | } | |
273 | }; | |
274 | ||
275 | WRITE_CLASS_ENCODER(MetricConfigMessage); | |
276 | ||
277 | #endif // CEPH_MGR_METRIC_TYPES_H |