Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MMgrReport.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2016 John Spray <john.spray@redhat.com>
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  */
13
14
15 #ifndef CEPH_MMGRREPORT_H_
16 #define CEPH_MMGRREPORT_H_
17
18 #include <boost/optional.hpp>
19
20 #include "msg/Message.h"
21
22 #include "common/perf_counters.h"
23
24 class PerfCounterType
25 {
26 public:
27   std::string path;
28   std::string description;
29   std::string nick;
30   enum perfcounter_type_d type;
31
32   // For older clients that did not send priority, pretend everything
33   // is "useful" so that mgr plugins filtering on prio will get some
34   // data (albeit probably more than they wanted)
35   uint8_t priority = PerfCountersBuilder::PRIO_USEFUL;
36
37   void encode(bufferlist &bl) const
38   {
39     // TODO: decide whether to drop the per-type
40     // encoding here, we could rely on the MgrReport
41     // verisoning instead.
42     ENCODE_START(2, 1, bl);
43     ::encode(path, bl);
44     ::encode(description, bl);
45     ::encode(nick, bl);
46     static_assert(sizeof(type) == 1, "perfcounter_type_d must be one byte");
47     ::encode((uint8_t)type, bl);
48     ::encode(priority, bl);
49     ENCODE_FINISH(bl);
50   }
51   
52   void decode(bufferlist::iterator &p)
53   {
54     DECODE_START(2, p);
55     ::decode(path, p);
56     ::decode(description, p);
57     ::decode(nick, p);
58     ::decode((uint8_t&)type, p);
59     if (struct_v >= 2) {
60       ::decode(priority, p);
61     }
62     DECODE_FINISH(p);
63   }
64 };
65 WRITE_CLASS_ENCODER(PerfCounterType)
66
67 class MMgrReport : public Message
68 {
69   static const int HEAD_VERSION = 4;
70   static const int COMPAT_VERSION = 1;
71
72 public:
73   /**
74    * Client is responsible for remembering whether it has introduced
75    * each perf counter to the server.  When first sending a particular
76    * counter, it must inline the counter's schema here.
77    */
78   std::vector<PerfCounterType> declare_types;
79   std::vector<std::string> undeclare_types;
80
81   // For all counters present, sorted by idx, output
82   // as many bytes as are needed to represent them
83
84   // Decode: iterate over the types we know about, sorted by idx,
85   // and use the current type's type to decide how to decode
86   // the next bytes from the bufferlist.
87   bufferlist packed;
88
89   std::string daemon_name;
90   std::string service_name;  // optional; otherwise infer from entity type
91
92   // for service registration
93   boost::optional<std::map<std::string,std::string>> daemon_status;
94
95   void decode_payload() override
96   {
97     bufferlist::iterator p = payload.begin();
98     ::decode(daemon_name, p);
99     ::decode(declare_types, p);
100     ::decode(packed, p);
101     if (header.version >= 2)
102       ::decode(undeclare_types, p);
103     if (header.version >= 3) {
104       ::decode(service_name, p);
105       ::decode(daemon_status, p);
106     }
107   }
108
109   void encode_payload(uint64_t features) override {
110     ::encode(daemon_name, payload);
111     ::encode(declare_types, payload);
112     ::encode(packed, payload);
113     ::encode(undeclare_types, payload);
114     ::encode(service_name, payload);
115     ::encode(daemon_status, payload);
116   }
117
118   const char *get_type_name() const override { return "mgrreport"; }
119   void print(ostream& out) const override {
120     out << get_type_name() << "(";
121     if (service_name.length()) {
122       out << service_name;
123     } else {
124       out << ceph_entity_type_name(get_source().type());
125     }
126     out << "." << daemon_name
127         << " +" << declare_types.size()
128         << "-" << undeclare_types.size()
129         << " packed " << packed.length();
130     if (daemon_status) {
131       out << " status=" << daemon_status->size();
132     }
133     out << ")";
134   }
135
136   MMgrReport()
137     : Message(MSG_MGR_REPORT, HEAD_VERSION, COMPAT_VERSION)
138   {}
139 };
140
141 #endif
142