From a4b45a432b6bde9e1d49164dbfe3f1c3f12f8adb Mon Sep 17 00:00:00 2001 From: Rafal Borysionek Date: Thu, 7 Sep 2017 12:14:40 +0200 Subject: [PATCH 1/8] Updated plugin to supported level --- CMakeLists.txt | 12 + include/snap/config.h | 296 +++++----- include/snap/grpc_export.h | 39 +- include/snap/grpc_export_impl.h | 70 ++- include/snap/lib_setup_impl.h | 14 +- include/snap/metric.h | 475 +++++++++++----- include/snap/plugin.h | 569 ++++++++++++------- include/snap/proxy/collector_proxy.h | 48 +- include/snap/proxy/plugin_proxy.h | 61 +- include/snap/proxy/processor_proxy.h | 42 +- include/snap/proxy/publisher_proxy.h | 40 +- include/snap/rpc/plugin.pb.h | 817 +++++++++++++++++++++++++++ src/main.cpp | 5 +- src/medium_test.cpp | 55 +- src/rdt/rdt.cpp | 137 ++--- src/rdt/rdt.hpp | 16 +- third_party/snap-plugin-lib-cpp | 2 +- 17 files changed, 1912 insertions(+), 786 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bace710..ef38151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,12 @@ target_link_libraries(snap-plugin-collector-rdt /usr/local/lib/libgrpc++.a /usr/local/lib/libgrpc.a pthread + ssl + crypto + boost_program_options + boost_system + boost_filesystem + z ) target_link_libraries(test-medium @@ -78,6 +84,12 @@ target_link_libraries(test-medium /usr/local/lib/libgrpc++.a /usr/local/lib/libgrpc.a pthread + ssl + crypto + boost_program_options + boost_filesystem + boost_system + z ) add_custom_target(dist diff --git a/include/snap/config.h b/include/snap/config.h index ee8ec7e..19fbd57 100644 --- a/include/snap/config.h +++ b/include/snap/config.h @@ -19,145 +19,159 @@ limitations under the License. #include namespace Plugin { - -template class Rule; - -/** - * A Rule of type std::string - */ -typedef Rule StringRule; - -/** - * A Rule of type int - */ -typedef Rule IntRule; - -/** - * A Rule of type bool - */ -typedef Rule BoolRule; - -/** - * The Rule template. - * Config policy rules are made up of 2 sets of keys, and finally the structure - * describing the policy. - * Key 1: The namespace where this rule should be applied - * Key 1 is only applicable for Collectors which are also providing metric - * descriptors. - * @see ConfigPolicy. - * Key 2: The key for the rule. E.g. 'username', 'password', 'file_path', & c. - * - * Rule has a private, nested type which describes the policy. Rule stores this - * Policy via the passed-in key. The Rule constructor cascades into rule's, - * then uses the key to point to the newly constructed rule. - */ -template -class Rule final : public P { - private: - class rule final : public R { - public: - rule() = delete; - explicit rule(bool req) { - this->set_required(req); - } - rule(const T& def, bool req) { - this->set_has_default(true); - this->set_default_(def); - this->set_required(req); - } - rule(const T& def, bool req, T min, T max) { - this->set_minimum(min); - this->set_maximum(max); - this->set_has_default(true); - this->set_default_(def); - this->set_required(req); - } - rule(bool req, T min, T max) { - this->set_minimum(min); - this->set_maximum(max); - this->set_required(req); - } - - ~rule() {} - }; - - public: - Rule() = delete; - - Rule(const std::string& key, const rule& rl) { - auto rule_ptr = this->mutable_rules(); - (*rule_ptr)[key] = rl; - } - Rule(const std::string& key, bool req) { - rule rl(req); - auto rule_ptr = this->mutable_rules(); - (*rule_ptr)[key] = rl; - } - - ~Rule() {} -}; - -/** - * A ConfigPolicy describes the requirements for running a given plugin. - * This policy is used to enforce that the required configuration is delivered - * to the plugin at runtime. - */ -class ConfigPolicy final : public rpc::GetConfigPolicyReply { - public: - ConfigPolicy(); - - /** - * For Processor and Publisher plugins, there is no namespace to attach a - * rule to -- The rule is applied to the whole plugin. - * In those cases, these constructors are used. - */ - explicit ConfigPolicy(const StringRule& rule); - explicit ConfigPolicy(const IntRule& rule); - explicit ConfigPolicy(const BoolRule& rule); - - ~ConfigPolicy(); - - /** - * For Collector plugins, a config may be applied to a parent of a metric's - * namespace. Any metrics which fall underneath this prefix inherit the given - * rule. - */ - void add_rule(const std::vector& ns, const StringRule& rule); - void add_rule(const std::vector& ns, const IntRule& rule); - void add_rule(const std::vector& ns, const BoolRule& rule); -}; - -/** - * Config is the incoming configuration data which has been vetted by snapteld - * according to the plugin's ConfigPolicy. - * - */ -class Config { - public: - /** - * A config is immutable, and is always passed _to_ a Plugin Author's plugin, - * If one is constructed manually, any reads will be attempt to do `gets` - * against an unallocated pointer. Deleting this constructor will block, at - * compile time, the ability to construct and use an incomplete config. - */ - Config() = delete; - - /** - * This library controls the lifetime of not only the Plugin::Config type, - * but also the rpc::ConfigMap it contains. This allows us hold a reference to - * the contained rpc::ConfigMap without using smart pointers or explicitly - * managing memory. - */ - explicit Config(const rpc::ConfigMap&); - - ~Config(); - - bool get_bool(const std::string& key) const; - int get_int(const std::string& key) const; - std::string get_string(const std::string& key) const; - - private: - const rpc::ConfigMap& rpc_map; -}; - + template class Rule; + + /** + * A Rule of type std::string + */ + typedef Rule StringRule; + + /** + * A Rule of type int + */ + typedef Rule IntRule; + + /** + * A Rule of type bool + */ + typedef Rule BoolRule; + + /** + * The Rule template. + * Config policy rules are made up of 2 sets of keys, and finally the structure + * describing the policy. + * Key 1: The namespace where this rule should be applied + * Key 1 is only applicable for Collectors which are also providing metric + * descriptors. + * @see ConfigPolicy. + * Key 2: The key for the rule. E.g. 'username', 'password', 'file_path', & c. + * + * Rule has a private, nested type which describes the policy. Rule stores this + * Policy via the passed-in key. The Rule constructor cascades into rule's, + * then uses the key to point to the newly constructed rule. + */ + template + class Rule final : public P { + private: + class rule final : public R { + public: + rule() = delete; + explicit rule(bool req) { + this->set_required(req); + } + rule(const T& def, bool req) { + this->set_has_default(true); + this->set_default_(def); + this->set_required(req); + } + rule(const T& def, bool req, T min, T max) { + this->set_minimum(min); + this->set_has_min(true); + this->set_maximum(max); + this->set_has_max(true); + this->set_has_default(true); + this->set_default_(def); + this->set_required(req); + } + rule(bool req, T min, T max) { + this->set_minimum(min); + this->set_has_min(true); + this->set_maximum(max); + this->set_has_max(true); + this->set_required(req); + } + + ~rule() {} + }; + + public: + Rule() = delete; + + Rule(const std::string& key, const rule& rl) { + auto rule_ptr = this->mutable_rules(); + (*rule_ptr)[key] = rl; + } + Rule(const std::string& key, bool req) { + rule rl(req); + auto rule_ptr = this->mutable_rules(); + (*rule_ptr)[key] = rl; + } + + ~Rule() {} + }; + + /** + * A ConfigPolicy describes the requirements for running a given plugin. + * This policy is used to enforce that the required configuration is delivered + * to the plugin at runtime. + */ + class ConfigPolicy final : public rpc::GetConfigPolicyReply { + public: + ConfigPolicy(); + + /** + * For Processor and Publisher plugins, there is no namespace to attach a + * rule to -- The rule is applied to the whole plugin. + * In those cases, these constructors are used. + */ + explicit ConfigPolicy(const StringRule& rule); + explicit ConfigPolicy(const IntRule& rule); + explicit ConfigPolicy(const BoolRule& rule); + + ~ConfigPolicy(); + + /** + * For Collector plugins, a config may be applied to a parent of a metric's + * namespace. Any metrics which fall underneath this prefix inherit the given + * rule. + */ + void add_rule(const std::vector& ns, const StringRule& rule); + void add_rule(const std::vector& ns, const IntRule& rule); + void add_rule(const std::vector& ns, const BoolRule& rule); + }; + + /** + * Config is the incoming configuration data which has been vetted by snapteld + * according to the plugin's ConfigPolicy or generated for the needs of diagnostics + * mode. + * + */ + class Config { + public: + /** + * A config is passed _to_ a Plugin Author's plugin, + * If one is constructed manually, any reads will be attempt to do `gets` + * against an unallocated pointer. Deleting this constructor will block, at + * compile time, the ability to construct and use an incomplete config. + */ + Config() = delete; + + /** + * This library controls the lifetime of not only the Plugin::Config type, + * but also the rpc::ConfigMap it contains. This allows us hold a reference to + * the contained rpc::ConfigMap without using smart pointers or explicitly + * managing memory. + */ + explicit Config(rpc::ConfigMap&); + + ~Config(); + + Config& operator=(const Config& that); + + bool get_bool(const std::string& key) const; + int get_int(const std::string& key) const; + std::string get_string(const std::string& key) const; + + void set_int(const std::string& key, int value) ; + void set_string(const std::string& key, std::string value); + void set_bool(const std::string& key, bool value); + + /** + * Apply defaults method is used only in diagnostics mode. + */ + void apply_defaults(const ConfigPolicy& from); + + private: + rpc::ConfigMap& rpc_map; + }; }; // namespace Plugin diff --git a/include/snap/grpc_export.h b/include/snap/grpc_export.h index f6b39da..9a71519 100644 --- a/include/snap/grpc_export.h +++ b/include/snap/grpc_export.h @@ -27,24 +27,25 @@ limitations under the License. #define RPC_VERSION 1 namespace Plugin { -class GRPCExportImpl; - -/** - * Implementation of PluginExporter based on GRPC. - */ -class GRPCExporter : public PluginExporter { -public: - ~GRPCExporter() = default; - - GRPCExporter(const GRPCExporter&) = delete; - GRPCExporter& operator=(const GRPCExporter&) = delete; - - std::future ExportPlugin(std::shared_ptr plugin, const Meta* meta); - GRPCExporter(); -protected: - GRPCExportImpl* implement(); -private: - std::shared_ptr impl; -}; + class GRPCExportImpl; + /** + * Implementation of PluginExporter based on GRPC. + */ + class GRPCExporter : public PluginExporter { + public: + ~GRPCExporter() = default; + + GRPCExporter(const GRPCExporter&) = delete; + GRPCExporter& operator=(const GRPCExporter&) = delete; + + std::future ExportPlugin(std::shared_ptr plugin, const Meta* meta); + GRPCExporter(); + + protected: + GRPCExportImpl* implement(); + + private: + std::shared_ptr impl; + }; } diff --git a/include/snap/grpc_export_impl.h b/include/snap/grpc_export_impl.h index 43ec97a..95572e9 100644 --- a/include/snap/grpc_export_impl.h +++ b/include/snap/grpc_export_impl.h @@ -20,38 +20,58 @@ limitations under the License. #include #include +#include +#include #include "snap/config.h" #include "snap/metric.h" +namespace spd = spdlog; #define RPC_VERSION 1 namespace Plugin { + /* + * Implementation details for GRPC plugin exporter. + * + * Instance is supposed to be held referenced by shared pointer, to retain + * the resources (ie.: service and server). + */ + class GRPCExportImpl : public std::enable_shared_from_this { + public: + std::future DoExport(std::shared_ptr plugin, const Meta* meta); + struct handler_type; -/* - * Implementation details for GRPC plugin exporter. - * - * Instance is supposed to be held referenced by shared pointer, to retain - * the resources (ie.: service and server). - */ -class GRPCExportImpl : public std::enable_shared_from_this { -public: - std::future DoExport(std::shared_ptr plugin, const Meta* meta); -protected: - int port; - std::shared_ptr plugin; - const Meta* meta; - std::unique_ptr service; - std::unique_ptr builder; - std::unique_ptr server; - - /* steps of the export procedure */ - void doConfigure(); - void doRegister(); - void doAdvertise(); - - /* blocking method - waits for the server to finish. */ - void doJoin(); -}; + GRPCExportImpl () { + _logger = spdlog::stderr_logger_mt("gprcExportImpl"); + } + + protected: + int port; + std::shared_ptr plugin; + const Meta* meta; + std::shared_ptr credentials; + std::unique_ptr service; + std::unique_ptr builder; + std::unique_ptr server; + + std::shared_ptr configureCredentials(); + + /* steps of the export procedure */ + void doConfigure(); + void doRegister(); + nlohmann::json printPreamble(); + + /* blocking method - waits for the server to finish. */ + void doJoin(); + int start_stand_alone(const int &httpPort); + private: + bool file_exists(const std::string); + std::string readFile(std::string); + std::string read_if_exists(std::string); + std::string load_key(std::string); + std::string load_directory(std::string); + std::string load_tls_ca(std::string); + std::shared_ptr _logger; + }; } diff --git a/include/snap/lib_setup_impl.h b/include/snap/lib_setup_impl.h index 3c711a5..5bb2c99 100644 --- a/include/snap/lib_setup_impl.h +++ b/include/snap/lib_setup_impl.h @@ -24,12 +24,10 @@ limitations under the License. #define RPC_VERSION 1 namespace Plugin { - -class LibSetup { -public: - /* A provider of default PluginExporter - used only in static start_xxx methods. - * Returns independent instances per each invocation. */ - static std::function>()> exporter_provider; -}; - + class LibSetup { + public: + /* A provider of default PluginExporter - used only in static start_xxx methods. + * Returns independent instances per each invocation. */ + static std::function>()> exporter_provider; + }; }; // namespace Plugin diff --git a/include/snap/metric.h b/include/snap/metric.h index 31ea640..cca0b32 100644 --- a/include/snap/metric.h +++ b/include/snap/metric.h @@ -14,6 +14,7 @@ limitations under the License. #pragma once #include +#include #include #include #include @@ -25,164 +26,326 @@ limitations under the License. namespace Plugin { -/** - * Metric is the representation of a Metric inside Snap. - */ -class Metric final { - public: - /** - * A PODS describing an element in a metric namespace. - */ - struct NamespaceElement { - /** - * value is the static value of this node in a namespace. - * When a namespace element is _not_ dynamic, value is used. During - * metric collection, value should contain the static name for this metric. - */ - std::string value; + class NamespaceElement{ + public: + + /** + * Constructor which makes "NamespaceElement" from three strings: + * value, + * name (optional- default parameter is empty), + * description (optional- default parameter is empty). + */ + NamespaceElement(std::string val, std::string nam ="", std::string desc=""); + + /** + * Default empty constructor. + */ + NamespaceElement(); + + /** + * Default empty destructor. + */ + ~NamespaceElement(); + + /** + * Setters for value, name and description + */ + void set_value(std::string v); + void set_name(std::string n); + void set_description(std::string d); + + /** + * Getters for value, name and description + */ + const std::string get_value() const; + const std::string get_name() const; + const std::string get_description() const; + + /** + * is_dynamic returns true if the namespace element contains data. A namespace + element that has a nonempty Name field is considered dynamic. + */ + const bool is_dynamic() const; + + private: + /** + * value is the static value of this node in a namespace. + * When a namespace element is _not_ dynamic, value is used. During + * metric collection, value should contain the static name for this metric. + */ + std::string value; + /** + * name is used to describe what this dynamic element is querying against. + * E.g. in the namespace `/intel/kvm/[vm_id]/cpu_wait` the element at index + * 2 has the name "vm_id". + * @see value + */ + std::string name; + /** + * description is the description of this namespace element. + */ + std::string description; + + }; + + class Namespace { + public: + + /** + * Constructor which makes namespace elements from vector of strings. + */ + Namespace(std::vector ns); + + /** + * Default empty constructor. + */ + Namespace(); + + /** + * Default empty destructor. + */ + ~Namespace(); + + /** + * Overloaded range operators. They return "NamespaceElement" object + * from given index. + */ + const NamespaceElement operator[] (int index) const; + + const std::string get_string() const; + + NamespaceElement& operator[] (int index); + + /** + * add_static_element adds a static element to the Namespace. A static + * namespaceElement is defined by having an empty Name field. + */ + Namespace& add_static_element(std::string value); + + /** + * add_dynamic_element adds a dynamic element to the given Namespace. A dynamic + * namespaceElement is defined by having a nonempty Name field. + */ + Namespace& add_dynamic_element(std::string name ,std::string description =""); + + /** + * Getter for vector of "NamespaceElements" + */ + std::vector get_namespace_elements() const; + + /** + * is_dynamic returns bool (true when this namespace is dynamic) + * and vector of indexes which elements are dynamic inside this "Namespace". + * A dynamic component of the namespace are those elements that + * contain variable data. + */ + const bool is_dynamic() const; + + /** + * get_dynamic_indexes returns vector of indexes which elements are dynamic + * inside this "Namespace". A dynamic component of the namespace are those + * elements that + * A dynamic component of the namespace are those elements that contain variable data. + */ + const std::vector get_dynamic_indexes(); + + /** + * Clears vector of NamespaceElements. + */ + void clear(); + + /** + * Returns size of vector of NamespaceElements. + */ + unsigned int size() const; + + /** + * Adds NamespaceElement to the end of exesting vector. + */ + void push_back(NamespaceElement& element); + + /** + * Same as above but this method takes rvalue of NamespaceElement. + */ + void push_back(NamespaceElement&& element); + + /** + * Reserves some size to the existing vector. + */ + void reserve(unsigned int size); + + private: + /** + * This field holds all object's "namespace_elements" inside std::vector. + */ + std::vector namespace_elements; + + }; - /** - * name is used to describe what this dynamic element is querying against. - * E.g. in the namespace `/intel/kvm/[vm_id]/cpu_wait` the element at index - * 2 has the name "vm_id". - * @see value - */ - std::string name; /** - * description is the description of this namespace element. - */ - std::string description; - }; - - enum DataType { - String = rpc::Metric::DataCase::kStringData, - Float32 = rpc::Metric::DataCase::kFloat32Data, - Float64 = rpc::Metric::DataCase::kFloat64Data, - Int32 = rpc::Metric::DataCase::kInt32Data, - // TODO(danielscottt) - // Int64 = rpc::Metric::DataCase::kInt64Data, - // Bytes = rpc::Metric::DataCase::kBytesData, - NotSet = rpc::Metric::DataCase::DATA_NOT_SET - }; - - Metric(); - /** - * The typical metric constructor. - * @param ns The metric's namespace. - * @param unit The metric's unit. - * @param description The metric's description. - */ - Metric(std::vector ns, std::string unit, - std::string description); - - /** - * This constructor is used in the plugin proxies. - * It's used to wrap the rpc::Metric and rpc::ConfigMap types with the metric - * type from this library. - */ - explicit Metric(rpc::Metric* metric); - - Metric(const Metric& from); - - ~Metric(); - - /** - * ns returns the metric's namespace. - * If there is a memoized copy, that is returned. Else the namespace is - * copied into the cache then returned. - */ - const std::vector& ns() const; - - /** - * dynamic_ns_elements returns the indices in the metric's namespace which - * are dynamic. - */ - std::vector dynamic_ns_elements() const; - - /** - * set_ns sets the namespace of the metric in its `rpc::Metric` ptr. - * It also invalidates the memoization cache of the namespace if it is - * present. - * @see memo_ns - */ - void set_ns(std::vector); - - /** - * tags returns the metric's tags. - * If there is a memoized copy, that is returned. Else the tags are copied - * into the cache then returned. - */ - const std::map& tags() const; - - /** - * set_ns adds tags to the metric in its `rpc::Metric` ptr. - * It also invalidates the memoization cache of the tags if it is - * present. - * @see memo_tags_ptr - */ - void add_tag(std::pair); - - /** - * timestamp returns the metric's collection timestamp. - */ - std::chrono::system_clock::time_point timestamp() const; - /** - * set_timestamp sets the timestamp as now. - */ - void set_timestamp(); - - /** - * set_timestamp sets the timestamp as tp. - * @param tp The timestamp to use. - */ - void set_timestamp(std::chrono::system_clock::time_point tp); - - /** - * set_last_advertised_time sets last_advertised_time as now. - */ - void set_last_advertised_time(); - - /** - * set_last_advertised_time sets last_advertised_time as tp. - * @param tp The timestamp to use. - */ - void set_last_advertised_time(std::chrono::system_clock::time_point tp); - - DataType data_type(); - - /** - * set_data sets the metric instances data in the underlying rpc::Metric - * pointer. - */ - void set_data(int data); - void set_data(float data); - void set_data(double data); - void set_data(const std::string& data); - - /** - * Retrieve this metric's datapoint - */ - int get_int_data() const; - float get_float32_data() const; - double get_float64_data() const; - const std::string& get_string_data() const; - Config get_config() const; - const rpc::Metric* get_rpc_metric_ptr() const; - - private: - rpc::Metric* rpc_metric_ptr; - Config config; - - void inline set_ts(std::chrono::system_clock::time_point tp); - void inline set_last_advert_tm(std::chrono::system_clock::time_point tp); - - // memoized members - mutable std::vector memo_ns; - mutable std::map memo_tags; - - bool delete_metric_ptr; - DataType type; -}; + * Metric is the representation of a Metric inside Snap. + */ + class Metric final { + public: + + enum DataType { + String = rpc::Metric::DataCase::kStringData, + Float32 = rpc::Metric::DataCase::kFloat32Data, + Float64 = rpc::Metric::DataCase::kFloat64Data, + Int32 = rpc::Metric::DataCase::kInt32Data, + Int64 = rpc::Metric::DataCase::kInt64Data, + Uint32 = rpc::Metric::DataCase::kUint32Data, + Uint64 = rpc::Metric::DataCase::kUint64Data, + Bool = rpc::Metric::DataCase::kBoolData, + NotSet = rpc::Metric::DataCase::DATA_NOT_SET, + }; + + friend std::ostream& operator<<(std::ostream& lhs, DataType e) { + switch(e) { + case String : lhs << "string"; break; + case Float32 : lhs << "float32"; break; + case Float64 : lhs << "float64"; break; + case Int32 : lhs << "int32"; break; + case Int64 : lhs << "int64"; break; + case Uint32 : lhs << "uint32"; break; + case Uint64 : lhs << "uint64"; break; + case Bool : lhs << "bool"; break; + default : lhs << "notset"; break; + } + return lhs; + } + + Metric(); + /** + * The typical metric constructor. + * @param ns The metric's namespace. + * @param unit The metric's unit. + * @param description The metric's description. + */ + Metric(Namespace &ns, std::string unit, + std::string description); + + /** + * Constructor same as above but takes lvalue of "Namespace" + */ + Metric(Namespace &&ns, std::string unit, + std::string description); + + /** + * This constructor is used in the plugin proxies. + * It's used to wrap the rpc::Metric and rpc::ConfigMap types with the metric + * type from this library. + */ + explicit Metric(rpc::Metric* metric); + + Metric(const Metric& from); + + ~Metric(); + + /** + * ns returns the metric's namespace. + * If there is a memoized copy, that is returned. Else the namespace is + * copied into the cache then returned. + */ + const Namespace& ns() const; + + /** + * set_ns sets the namespace of the metric in its `rpc::Metric` ptr. + * It also invalidates the memoization cache of the namespace if it is + * present. + * @see memo_ns + */ + void set_ns(Namespace &ns); + + /** + * tags returns the metric's tags. + * If there is a memoized copy, that is returned. Else the tags are copied + * into the cache then returned. + */ + const std::map& tags() const; + + /** + * set_ns adds tags to the metric in its `rpc::Metric` ptr. + * It also invalidates the memoization cache of the tags if it is + * present. + * @see memo_tags_ptr + */ + void add_tag(std::pair); + + /** + * timestamp returns the metric's collection timestamp. + */ + std::chrono::system_clock::time_point timestamp() const; + /** + * set_timestamp sets the timestamp as now. + */ + void set_timestamp(); + + /** + * set_timestamp sets the timestamp as tp. + * @param tp The timestamp to use. + */ + void set_timestamp(std::chrono::system_clock::time_point tp); + + /** + * set_last_advertised_time sets last_advertised_time as now. + */ + void set_last_advertised_time(); + + /** + * set_last_advertised_time sets last_advertised_time as tp. + * @param tp The timestamp to use. + */ + void set_last_advertised_time(std::chrono::system_clock::time_point tp); + + /** + * set_diagnostic_config is used to apply generated config to specific metric. + */ + void set_diagnostic_config(const Config& cfg); + + DataType data_type() const; + + /** + * set_data sets the metric instances data in the underlying rpc::Metric + * pointer. + */ + void set_data(int32_t data); + void set_data(int64_t data); + void set_data(uint32_t data); + void set_data(uint64_t data); + void set_data(float data); + void set_data(double data); + void set_data(bool data); + void set_data(const std::string& data); + + /** + * Retrieve this metric's datapoint + */ + int32_t get_int_data() const; + int64_t get_int64_data() const; + uint32_t get_uint32_data() const; + uint64_t get_uint64_data() const; + float get_float32_data() const; + double get_float64_data() const; + bool get_bool_data() const; + const std::string& get_string_data() const; + Config get_config() const; + const rpc::Metric* get_rpc_metric_ptr() const; + + private: + rpc::Metric* rpc_metric_ptr; + Config config; + + void inline set_ts(std::chrono::system_clock::time_point tp); + void inline set_last_advert_tm(std::chrono::system_clock::time_point tp); + + // memoized members + mutable Namespace memo_ns; + mutable std::map memo_tags; + + bool delete_metric_ptr; + DataType type; + }; } // namespace Plugin diff --git a/include/snap/plugin.h b/include/snap/plugin.h index 701ad21..57ff90d 100644 --- a/include/snap/plugin.h +++ b/include/snap/plugin.h @@ -21,224 +21,361 @@ limitations under the License. #include "snap/config.h" #include "snap/metric.h" +#include "snap/flags.h" #define RPC_VERSION 1 namespace Plugin { - -class CollectorInterface; -class ProcessorInterface; -class PublisherInterface; - -/** - * Type is the plugin type - */ -enum Type { - Collector, - Processor, - Publisher -}; - -/** - * RpcType is the rpc protocol the plugin should use. - * Only GRPC is supported for C++. - */ -enum RpcType { - GRPC = 2, -}; - -/** - * Strategy is the routing and caching strategy this plugin requires. - * A routing and caching Strategy is the method which snapteld uses to cache - * metrics, and select the correct running instance of a plugin. - */ -enum Strategy { - /** - * LRU: Least Recently Used. - * The default strategy. - */ - LRU, - - /** - * Sticky: Sticky Running plugins have a 1:1 relationship to Tasks. - */ - Sticky, - - /** ConfigBased: Bases routing decisions on the incoming config. - * The config based strategy hashes the incoming config data and - * uses it as a key to select a running plugin. It can be useful for plugins - * which maintain a connection to a database, for instance. - */ - ConfigBased -}; - -/** - * Meta is the metadata about the plugin. - */ -struct Meta final { - public: - Meta(Type type, std::string name, int version); - - Type type; - std::string name; - int version; - - /** - * The RpcType in use, defaults to RpcType::GRPC. There should be no need to change - * it. - */ - RpcType rpc_type; - - /** - * concurrency_count is the max number of concurrent calls the plugin - * should take. For example: - * If there are 5 tasks using the plugin and its concurrency count is 2, - * snapteld will keep 3 plugin instances running. - * Using concurrency_count overwrites the default value of (5). - */ - int concurrency_count; - - /** - * exclusive == true results in a single instance of the plugin running - * regardless of the number of tasks using the plugin. - * Using exclusive overwrites the default value of (false). - */ - bool exclusive; - /** - * snapteld caches metrics on the daemon side for a default of 500ms. - * CacheTTL overwrites the default value of (500ms). - */ - std::chrono::milliseconds cache_ttl; - - /** - * Strategy will override the routing strategy this plugin requires. - * The default routing strategy is Least Recently Used. - * Strategy overwrites the default value of (LRU). - */ - Strategy strategy; -}; - -/** - * Base class for exceptions indicated by plugins. - * - * When thrown from any kind of plugin, the exception will be - * propagated to and reported by Snap framework. - */ -class PluginException : public std::runtime_error { - public: - PluginException(const std::string& message); -}; - -/** - * PluginInterface is the interface implemented by ALL plugins. - * Every plugin must implement get_config_policy. - */ -class PluginInterface { -public: - virtual ~PluginInterface() {} - virtual Type GetType() const = 0; - virtual CollectorInterface* IsCollector(); - virtual ProcessorInterface* IsProcessor(); - virtual PublisherInterface* IsPublisher(); - - virtual const ConfigPolicy get_config_policy() = 0; -protected: - PluginInterface() = default; - -}; - -/** - * PluginExporter is the driver for exporting plugin as a service (e.g.: via - * GRPC). It's supposed to export a single instance of a plugin - should not be - * reused. - * - * PluginExporter can block waiting for plugin termination. Any resources - * associated with export operation are retained until the blocking wait - * completes or exporter instance is destroyed. - * - * Plugin Library offers default plugin export implementation based on GRPC, if - * the static start_xxx methods are used. - */ -class PluginExporter { -public: - virtual ~PluginExporter() = default; - - PluginExporter(const PluginExporter &) = delete; - PluginExporter& operator=(const PluginExporter &) = delete; - - /** Export plugin as a service, allow waiting for termination (via future). */ - virtual std::future ExportPlugin(std::shared_ptr plugin, const Meta* meta) = 0; -protected: - PluginExporter() = default; -}; - -/** - * The interface for a collector plugin. - * A Collector is the source. - * It is responsible for collecting metrics in the Snap pipeline. - */ -class CollectorInterface : public PluginInterface { -public: - Type GetType() const final; - CollectorInterface* IsCollector() final; - - /* - * (inherited from PluginInterface) - */ - virtual const ConfigPolicy get_config_policy() = 0; - - /* - * get_metric_types should report all the metrics this plugin can collect. - */ - virtual std::vector get_metric_types(Config cfg) = 0; - - /* - * collect_metrics is given a list of metrics to collect. - * It should collect and annotate each metric with the apropos context. - */ - virtual void collect_metrics(std::vector &metrics) = 0; - -}; - -/** - * The interface for a Processor plugin. - * A Processor is an intermediary in the pipeline. It may decorate, filter, or - * derive as data passes through Snap's pipeline. - */ -class ProcessorInterface : public PluginInterface { -public: - Type GetType() const final; - ProcessorInterface* IsProcessor() final; - - virtual void process_metrics(std::vector &metrics, - const Config& config) = 0; -}; - -/** - * The interface for a Publisher plugin. - * A Publisher is the sink. - * It sinks data into some external system. - */ -class PublisherInterface : public PluginInterface { -public: - Type GetType() const final; - PublisherInterface* IsPublisher() final; - - virtual void publish_metrics(std::vector &metrics, - const Config& config) = 0; -}; - -/** - * These functions are called to start a plugin. - * They export plugin using default PluginExporter based on GRPC: - * construct the gRPC service and server, start them, and then - * block forever. - * - * These functions do not manage the plugin instance passed as parameter - - * caller's responsible for releasing the resources. - */ -void start_collector(CollectorInterface* plg, const Meta& meta); -void start_processor(ProcessorInterface* plg, const Meta& meta); -void start_publisher(PublisherInterface* plg, const Meta& meta); - + class CollectorInterface; + class ProcessorInterface; + class PublisherInterface; + + /** + * Type is the plugin type + */ + enum Type { + Collector, + Processor, + Publisher + }; + + /** + * RpcType is the rpc protocol the plugin should use. + * Only GRPC is supported for C++. + */ + enum RpcType { + GRPC = 2, + GRPCStream = 3 + }; + + /** + * Strategy is the routing and caching strategy this plugin requires. + * A routing and caching Strategy is the method which snapteld uses to cache + * metrics, and select the correct running instance of a plugin. + */ + enum Strategy { + /** + * LRU: Least Recently Used. + * The default strategy. + */ + LRU, + + /** + * Sticky: Sticky Running plugins have a 1:1 relationship to Tasks. + */ + Sticky, + + /** ConfigBased: Bases routing decisions on the incoming config. + * The config based strategy hashes the incoming config data and + * uses it as a key to select a running plugin. It can be useful for plugins + * which maintain a connection to a database, for instance. + */ + ConfigBased + }; + + /** + * Meta is the metadata about the plugin. + */ + class Meta final { + public: + Meta(Type type, std::string name, int version); + Meta(Type type, std::string name, int version, Flags *flags); + + Type type; + std::string name; + int version; + int rpc_version; + + /** + * The RpcType in use, defaults to RpcType::GRPC. There should be no need to change + * it. + */ + RpcType rpc_type; + + /** + * concurrency_count is the max number of concurrent calls the plugin + * should take. For example: + * If there are 5 tasks using the plugin and its concurrency count is 2, + * snapteld will keep 3 plugin instances running. + * Using concurrency_count overwrites the default value of (5). + */ + int concurrency_count; + + /** + * exclusive == true results in a single instance of the plugin running + * regardless of the number of tasks using the plugin. + * Using exclusive overwrites the default value of (false). + */ + bool exclusive; + + /** + * Unsecure is a legacy value not used for grpc, but needed to avoid + * calling SetKey needlessly. + */ + bool unsecure; + + /** + * snapteld caches metrics on the daemon side for a default of 500ms. + * CacheTTL overwrites the default value of (500ms). + */ + std::chrono::milliseconds cache_ttl; + + /** + * Strategy will override the routing strategy this plugin requires. + * The default routing strategy is Least Recently Used. + * Strategy overwrites the default value of (LRU). + */ + Strategy strategy; + + /** + * Port GRPC will listen on + */ + std::string listen_port; + + /** + * Address GRPC will listen on + */ + std::string listen_addr; + + /** + * Enables pprof + */ + bool pprof_enabled; + + /** + * Enables TLS + */ + bool tls_enabled; + + /** + * Necessary to provide when TLS enabled + */ + std::string tls_certificate_crt_path; + + /** + * Necessary to provide when TLS enabled + */ + std::string tls_certificate_key_path; + + /** + * Neccessary to proivide when TLS Enabled. + */ + std::string tls_certificate_authority_paths; + + /** + * Enable stand-alone plugin + */ + bool stand_alone; + + /** + * Enable diagnostic mode + */ + bool diagnostic_enabled; + /** + * Specify http port when stand-alone plugin is enabled + */ + int stand_alone_port; + + /** + * sets the maximum duration (always greater than 0s) between collections + * before metrics are sent. Defaults to 10s what means that after 10 seconds + * no new metrics are received, the plugin should send whatever data it has + * in the buffer instead of waiting longer. (e.g. 5s) + */ + std::chrono::seconds max_collect_duration; + + /** + * maximum number of metrics the plugin is buffering before sending metrics. + * Defaults to zero what means send metrics immediately + */ + int64_t max_metrics_buffer; + + /** + * use_cli_args updates plugin meta using arguments from cli + */ + void use_cli_args(Flags *flags); + }; + + /** + * Base class for exceptions indicated by plugins. + * + * When thrown from any kind of plugin, the exception will be + * propagated to and reported by Snap framework. + */ + class PluginException : public std::runtime_error { + public: + PluginException(const std::string& message); + }; + + /** + * PluginInterface is the interface implemented by ALL plugins. + * Every plugin must implement get_config_policy. + */ + class PluginInterface { + public: + virtual ~PluginInterface() {} + virtual Type GetType() const = 0; + virtual CollectorInterface* IsCollector(); + virtual ProcessorInterface* IsProcessor(); + virtual PublisherInterface* IsPublisher(); + + virtual const ConfigPolicy get_config_policy() = 0; + protected: + PluginInterface() = default; + }; + + /** + * PluginExporter is the driver for exporting plugin as a service (e.g.: via + * GRPC). It's supposed to export a single instance of a plugin - should not be + * reused. + * + * PluginExporter can block waiting for plugin termination. Any resources + * associated with export operation are retained until the blocking wait + * completes or exporter instance is destroyed. + * + * Plugin Library offers default plugin export implementation based on GRPC, if + * the static start_xxx methods are used. + */ + class PluginExporter { + public: + virtual ~PluginExporter() = default; + + PluginExporter(const PluginExporter &) = delete; + PluginExporter& operator=(const PluginExporter &) = delete; + + /** Export plugin as a service, allow waiting for termination (via future). */ + virtual std::future ExportPlugin(std::shared_ptr plugin, const Meta* meta) = 0; + protected: + PluginExporter() = default; + }; + + /** + * The interface for a collector plugin. + * A Collector is the source. + * It is responsible for collecting metrics in the Snap pipeline. + */ + class CollectorInterface : public PluginInterface { + public: + Type GetType() const final; + CollectorInterface* IsCollector() final; + + /* + * (inherited from PluginInterface) + */ + virtual const ConfigPolicy get_config_policy() = 0; + + /* + * get_metric_types should report all the metrics this plugin can collect. + */ + virtual std::vector get_metric_types(Config cfg) = 0; + + /* + * collect_metrics is given a list of metrics to collect. + * It should collect and annotate each metric with the apropos context. + */ + virtual std::vector collect_metrics(std::vector &metrics) = 0; + }; + + /** + * The interface for a Processor plugin. + * A Processor is an intermediary in the pipeline. It may decorate, filter, or + * derive as data passes through Snap's pipeline. + */ + class ProcessorInterface : public PluginInterface { + public: + Type GetType() const final; + ProcessorInterface* IsProcessor() final; + + virtual void process_metrics(std::vector &metrics, + const Config& config) = 0; + }; + + /** + * The interface for a Publisher plugin. + * A Publisher is the sink. + * It sinks data into some external system. + */ + class PublisherInterface : public PluginInterface { + public: + Type GetType() const final; + PublisherInterface* IsPublisher() final; + + virtual void publish_metrics(std::vector &metrics, + const Config& config) = 0; + }; + + + class DiagnosticPrinter { + private: + /** + * Small Stopwatch class to simplify measuring time when printing diagnostics. + */ + class Stopwatch { + public: + Stopwatch(std::ostream& os = std::cout); + ~Stopwatch(); + void start(); + void stop(); + void print_elapsed(std::string message_before = "", std::string message_after = ""); + + private: + bool started; + bool stopped; + std::string unit; + std::chrono::high_resolution_clock::time_point begin; + std::chrono::high_resolution_clock::time_point end; + std::ostream& os; + }; // End of private stopwatch class. + + public: + DiagnosticPrinter(CollectorInterface* collector, const Meta& meta, Flags& cli, std::ostream& os = std::cout); + ~DiagnosticPrinter(); + /** + * Show method prints all diagnostics for collector plugin. + */ + void show(); + + private: + /** + * These methods print specific diagnostics for collector plugin and + * other information such as "contact us" and "runetime details" + */ + void print_contact_us(); + void print_runtime_details(); + void print_config_policy(); + std::vector print_metric_types(); + void print_collect_metrics(std::vector mts); + void print_string_policy(ConfigPolicy& cpolicy); + void print_integer_policy(ConfigPolicy& cpolicy); + void print_bool_policy(ConfigPolicy& cpolicy); + void check_for_missing_requirements(const std::string& key, bool hasdefault); + + std::string get_os_name(); + std::string get_architecture_name(); + + /** + * Private fields of DiagnosticPrinter class. + */ + std::string missing_config_requirements; + std::ostream& os; + CollectorInterface* collector; + const Meta& meta; + rpc::ConfigMap cfgmap; + Config config; + }; + + + + /** + * These functions are called to start a plugin. + * They export plugin using default PluginExporter based on GRPC: + * construct the gRPC service and server, start them, and then + * block forever. + * + * These functions do not manage the plugin instance passed as parameter - + * caller's responsible for releasing the resources. + */ + void start_collector(int argc, char **argv, CollectorInterface* plg, Meta& meta); + void start_processor(int argc, char **argv, ProcessorInterface* plg, Meta& meta); + void start_publisher(int argc, char **argv, PublisherInterface* plg, Meta& meta); }; // namespace Plugin diff --git a/include/snap/proxy/collector_proxy.h b/include/snap/proxy/collector_proxy.h index 42a8bb0..a25a297 100644 --- a/include/snap/proxy/collector_proxy.h +++ b/include/snap/proxy/collector_proxy.h @@ -21,36 +21,34 @@ limitations under the License. #include "snap/proxy/plugin_proxy.h" namespace Plugin { -namespace Proxy { + namespace Proxy { + class CollectorImpl final : public rpc::Collector::Service { + public: + explicit CollectorImpl(Plugin::CollectorInterface* plugin); -class CollectorImpl final : public rpc::Collector::Service { - public: - explicit CollectorImpl(Plugin::CollectorInterface* plugin); + ~CollectorImpl(); - ~CollectorImpl(); + grpc::Status CollectMetrics(grpc::ServerContext* context, + const rpc::MetricsArg* req, + rpc::MetricsReply* resp); - grpc::Status CollectMetrics(grpc::ServerContext* context, - const rpc::MetricsArg* req, - rpc::MetricsReply* resp); + grpc::Status GetMetricTypes(grpc::ServerContext* context, + const rpc::GetMetricTypesArg* request, + rpc::MetricsReply* resp); - grpc::Status GetMetricTypes(grpc::ServerContext* context, - const rpc::GetMetricTypesArg* request, - rpc::MetricsReply* resp); + grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* request, + rpc::ErrReply* response); - grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* request, - rpc::ErrReply* response); + grpc::Status GetConfigPolicy(grpc::ServerContext* context, + const rpc::Empty* request, + rpc::GetConfigPolicyReply* resp); - grpc::Status GetConfigPolicy(grpc::ServerContext* context, - const rpc::Empty* request, - rpc::GetConfigPolicyReply* resp); + grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* request, + rpc::ErrReply* resp); - grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* request, - rpc::ErrReply* resp); - - private: - Plugin::CollectorInterface* collector; - PluginImpl* plugin_impl_ptr; -}; - -} // namespace Proxy + private: + Plugin::CollectorInterface* collector; + PluginImpl* plugin_impl_ptr; + }; + } // namespace Proxy } // namespace Plugin diff --git a/include/snap/proxy/plugin_proxy.h b/include/snap/proxy/plugin_proxy.h index c708e67..caed85e 100644 --- a/include/snap/proxy/plugin_proxy.h +++ b/include/snap/proxy/plugin_proxy.h @@ -12,34 +12,61 @@ See the License for the specific language governing permissions and limitations under the License. */ #pragma once - +#include +#include +#include +#include #include #include "snap/rpc/plugin.pb.h" - #include "snap/plugin.h" namespace Plugin { -namespace Proxy { + namespace Proxy { + template + std::ostream &operator<<(std::ostream &stream, + const std::chrono::time_point &time_point) { + const time_t time = Clock::to_time_t(time_point); + #if __GNUC__ > 4 || \ + ((__GNUC__ == 4) && __GNUC_MINOR__ > 8 && __GNUC_REVISION__ > 1) + // Maybe the put_time will be implemented later? + struct tm tm; + localtime_r(&time, &tm); + return stream << std::put_time(&tm, "%c"); // Print standard date&time + #else + char buffer[26]; + ctime_r(&time, buffer); + buffer[24] = '\0'; // Removes the newline that is added + return stream << buffer; + #endif + } -class PluginImpl final { - public: - explicit PluginImpl(Plugin::PluginInterface* plugin); + class PluginImpl final { + public: + explicit PluginImpl(Plugin::PluginInterface* plugin); - grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* req, - rpc::ErrReply* resp); + grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* req, + rpc::ErrReply* resp); - grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* req, - rpc::ErrReply* response); + grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* req, + rpc::ErrReply* response); - grpc::Status GetConfigPolicy(grpc::ServerContext* context, - const rpc::Empty* req, - rpc::GetConfigPolicyReply* resp); + grpc::Status GetConfigPolicy(grpc::ServerContext* context, + const rpc::Empty* req, + rpc::GetConfigPolicyReply* resp); - private: - Plugin::PluginInterface* plugin; -}; + void HeartbeatWatch(); -} // namespace Proxy + private: + Plugin::PluginInterface* plugin; + std::chrono::system_clock::time_point _lastPing; + // PingTimeoutLimit is the number of successively missed pin health checks + // which must occur before the plugin is stopped + int _pingTimeoutLimit = 3; + // PingTimeoutDuration is the duration during which a ping healthcheck + // should be received + std::chrono::seconds _pingTimeoutDuration{3}; + }; + } // namespace Proxy } // namespace Plugin diff --git a/include/snap/proxy/processor_proxy.h b/include/snap/proxy/processor_proxy.h index 53a50e2..2115d84 100644 --- a/include/snap/proxy/processor_proxy.h +++ b/include/snap/proxy/processor_proxy.h @@ -21,32 +21,30 @@ limitations under the License. #include "snap/proxy/plugin_proxy.h" namespace Plugin { -namespace Proxy { + namespace Proxy { + class ProcessorImpl final : public rpc::Processor::Service { + public: + explicit ProcessorImpl(Plugin::ProcessorInterface* plugin); -class ProcessorImpl final : public rpc::Processor::Service { - public: - explicit ProcessorImpl(Plugin::ProcessorInterface* plugin); + ~ProcessorImpl(); - ~ProcessorImpl(); + grpc::Status Process(grpc::ServerContext* context, + const rpc::PubProcArg* req, + rpc::MetricsReply* resp); - grpc::Status Process(grpc::ServerContext* context, - const rpc::PubProcArg* req, - rpc::MetricsReply* resp); + grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* request, + rpc::ErrReply* response); - grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* request, - rpc::ErrReply* response); + grpc::Status GetConfigPolicy(grpc::ServerContext* context, + const rpc::Empty* request, + rpc::GetConfigPolicyReply* resp); - grpc::Status GetConfigPolicy(grpc::ServerContext* context, - const rpc::Empty* request, - rpc::GetConfigPolicyReply* resp); + grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* request, + rpc::ErrReply* resp); - grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* request, - rpc::ErrReply* resp); - - private: - Plugin::ProcessorInterface* processor; - PluginImpl* plugin_impl_ptr; -}; - -} // namespace Proxy + private: + Plugin::ProcessorInterface* processor; + PluginImpl* plugin_impl_ptr; + }; + } // namespace Proxy } // namespace Plugin diff --git a/include/snap/proxy/publisher_proxy.h b/include/snap/proxy/publisher_proxy.h index 6765d3f..ea10571 100644 --- a/include/snap/proxy/publisher_proxy.h +++ b/include/snap/proxy/publisher_proxy.h @@ -21,31 +21,29 @@ limitations under the License. #include "snap/proxy/plugin_proxy.h" namespace Plugin { -namespace Proxy { + namespace Proxy { + class PublisherImpl final : public rpc::Publisher::Service { + public: + explicit PublisherImpl(Plugin::PublisherInterface* plugin); -class PublisherImpl final : public rpc::Publisher::Service { - public: - explicit PublisherImpl(Plugin::PublisherInterface* plugin); + ~PublisherImpl(); - ~PublisherImpl(); + grpc::Status Publish(grpc::ServerContext* context, const rpc::PubProcArg* req, + rpc::ErrReply* resp); - grpc::Status Publish(grpc::ServerContext* context, const rpc::PubProcArg* req, - rpc::ErrReply* resp); + grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* request, + rpc::ErrReply* response); - grpc::Status Kill(grpc::ServerContext* context, const rpc::KillArg* request, - rpc::ErrReply* response); + grpc::Status GetConfigPolicy(grpc::ServerContext* context, + const rpc::Empty* request, + rpc::GetConfigPolicyReply* resp); - grpc::Status GetConfigPolicy(grpc::ServerContext* context, - const rpc::Empty* request, - rpc::GetConfigPolicyReply* resp); + grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* request, + rpc::ErrReply* resp); - grpc::Status Ping(grpc::ServerContext* context, const rpc::Empty* request, - rpc::ErrReply* resp); - - private: - Plugin::PublisherInterface* publisher; - PluginImpl* plugin_impl_ptr; -}; - -} // namespace Proxy + private: + Plugin::PublisherInterface* publisher; + PluginImpl* plugin_impl_ptr; + }; + } // namespace Proxy } // namespace Plugin diff --git a/include/snap/rpc/plugin.pb.h b/include/snap/rpc/plugin.pb.h index 8d29fc7..1d0e135 100644 --- a/include/snap/rpc/plugin.pb.h +++ b/include/snap/rpc/plugin.pb.h @@ -40,6 +40,8 @@ void protobuf_ShutdownFile_plugin_2eproto(); class BoolPolicy; class BoolRule; +class CollectArg; +class CollectReply; class ConfigMap; class Empty; class ErrReply; @@ -61,6 +63,212 @@ class Time; // =================================================================== +class CollectArg : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:rpc.CollectArg) */ { + public: + CollectArg(); + virtual ~CollectArg(); + + CollectArg(const CollectArg& from); + + inline CollectArg& operator=(const CollectArg& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CollectArg& default_instance(); + + void Swap(CollectArg* other); + + // implements Message ---------------------------------------------- + + inline CollectArg* New() const { return New(NULL); } + + CollectArg* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CollectArg& from); + void MergeFrom(const CollectArg& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { + return InternalSerializeWithCachedSizesToArray(false, output); + } + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(CollectArg* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .rpc.MetricsArg Metrics_Arg = 1; + bool has_metrics_arg() const; + void clear_metrics_arg(); + static const int kMetricsArgFieldNumber = 1; + const ::rpc::MetricsArg& metrics_arg() const; + ::rpc::MetricsArg* mutable_metrics_arg(); + ::rpc::MetricsArg* release_metrics_arg(); + void set_allocated_metrics_arg(::rpc::MetricsArg* metrics_arg); + + // optional int64 MaxCollectDuration = 2; + void clear_maxcollectduration(); + static const int kMaxCollectDurationFieldNumber = 2; + ::google::protobuf::int64 maxcollectduration() const; + void set_maxcollectduration(::google::protobuf::int64 value); + + // optional int64 MaxMetricsBuffer = 3; + void clear_maxmetricsbuffer(); + static const int kMaxMetricsBufferFieldNumber = 3; + ::google::protobuf::int64 maxmetricsbuffer() const; + void set_maxmetricsbuffer(::google::protobuf::int64 value); + + // optional bytes Other = 4; + void clear_other(); + static const int kOtherFieldNumber = 4; + const ::std::string& other() const; + void set_other(const ::std::string& value); + void set_other(const char* value); + void set_other(const void* value, size_t size); + ::std::string* mutable_other(); + ::std::string* release_other(); + void set_allocated_other(::std::string* other); + + // @@protoc_insertion_point(class_scope:rpc.CollectArg) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::rpc::MetricsArg* metrics_arg_; + ::google::protobuf::int64 maxcollectduration_; + ::google::protobuf::int64 maxmetricsbuffer_; + ::google::protobuf::internal::ArenaStringPtr other_; + mutable int _cached_size_; + friend void protobuf_AddDesc_plugin_2eproto(); + friend void protobuf_AssignDesc_plugin_2eproto(); + friend void protobuf_ShutdownFile_plugin_2eproto(); + + void InitAsDefaultInstance(); + static CollectArg* default_instance_; +}; +// ------------------------------------------------------------------- + +class CollectReply : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:rpc.CollectReply) */ { + public: + CollectReply(); + virtual ~CollectReply(); + + CollectReply(const CollectReply& from); + + inline CollectReply& operator=(const CollectReply& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const CollectReply& default_instance(); + + void Swap(CollectReply* other); + + // implements Message ---------------------------------------------- + + inline CollectReply* New() const { return New(NULL); } + + CollectReply* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const CollectReply& from); + void MergeFrom(const CollectReply& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { + return InternalSerializeWithCachedSizesToArray(false, output); + } + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(CollectReply* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .rpc.MetricsReply Metrics_Reply = 1; + bool has_metrics_reply() const; + void clear_metrics_reply(); + static const int kMetricsReplyFieldNumber = 1; + const ::rpc::MetricsReply& metrics_reply() const; + ::rpc::MetricsReply* mutable_metrics_reply(); + ::rpc::MetricsReply* release_metrics_reply(); + void set_allocated_metrics_reply(::rpc::MetricsReply* metrics_reply); + + // optional .rpc.ErrReply Error = 2; + bool has_error() const; + void clear_error(); + static const int kErrorFieldNumber = 2; + const ::rpc::ErrReply& error() const; + ::rpc::ErrReply* mutable_error(); + ::rpc::ErrReply* release_error(); + void set_allocated_error(::rpc::ErrReply* error); + + // @@protoc_insertion_point(class_scope:rpc.CollectReply) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::rpc::MetricsReply* metrics_reply_; + ::rpc::ErrReply* error_; + mutable int _cached_size_; + friend void protobuf_AddDesc_plugin_2eproto(); + friend void protobuf_AssignDesc_plugin_2eproto(); + friend void protobuf_ShutdownFile_plugin_2eproto(); + + void InitAsDefaultInstance(); + static CollectReply* default_instance_; +}; +// ------------------------------------------------------------------- + class Empty : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:rpc.Empty) */ { public: Empty(); @@ -543,6 +751,9 @@ class Metric : public ::google::protobuf::Message /* @@protoc_insertion_point(cl kInt32Data = 12, kInt64Data = 13, kBytesData = 14, + kBoolData = 15, + kUint32Data = 16, + kUint64Data = 17, DATA_NOT_SET = 0, }; @@ -732,6 +943,33 @@ class Metric : public ::google::protobuf::Message /* @@protoc_insertion_point(cl ::std::string* release_bytes_data(); void set_allocated_bytes_data(::std::string* bytes_data); + // optional bool bool_data = 15; + private: + bool has_bool_data() const; + public: + void clear_bool_data(); + static const int kBoolDataFieldNumber = 15; + bool bool_data() const; + void set_bool_data(bool value); + + // optional uint32 uint32_data = 16; + private: + bool has_uint32_data() const; + public: + void clear_uint32_data(); + static const int kUint32DataFieldNumber = 16; + ::google::protobuf::uint32 uint32_data() const; + void set_uint32_data(::google::protobuf::uint32 value); + + // optional uint64 uint64_data = 17; + private: + bool has_uint64_data() const; + public: + void clear_uint64_data(); + static const int kUint64DataFieldNumber = 17; + ::google::protobuf::uint64 uint64_data() const; + void set_uint64_data(::google::protobuf::uint64 value); + DataCase data_case() const; // @@protoc_insertion_point(class_scope:rpc.Metric) private: @@ -741,6 +979,9 @@ class Metric : public ::google::protobuf::Message /* @@protoc_insertion_point(cl inline void set_has_int32_data(); inline void set_has_int64_data(); inline void set_has_bytes_data(); + inline void set_has_bool_data(); + inline void set_has_uint32_data(); + inline void set_has_uint64_data(); inline bool has_data() const; void clear_data(); @@ -774,6 +1015,9 @@ class Metric : public ::google::protobuf::Message /* @@protoc_insertion_point(cl ::google::protobuf::int32 int32_data_; ::google::protobuf::int64 int64_data_; ::google::protobuf::internal::ArenaStringPtr bytes_data_; + bool bool_data_; + ::google::protobuf::uint32 uint32_data_; + ::google::protobuf::uint64 uint64_data_; } data_; mutable int _cached_size_; ::google::protobuf::uint32 _oneof_case_[1]; @@ -1364,6 +1608,22 @@ class BoolPolicy : public ::google::protobuf::Message /* @@protoc_insertion_poin ::google::protobuf::Map< ::std::string, ::rpc::BoolRule >* mutable_rules(); + // repeated string key = 2; + int key_size() const; + void clear_key(); + static const int kKeyFieldNumber = 2; + const ::std::string& key(int index) const; + ::std::string* mutable_key(int index); + void set_key(int index, const ::std::string& value); + void set_key(int index, const char* value); + void set_key(int index, const char* value, size_t size); + ::std::string* add_key(); + void add_key(const ::std::string& value); + void add_key(const char* value); + void add_key(const char* value, size_t size); + const ::google::protobuf::RepeatedPtrField< ::std::string>& key() const; + ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_key(); + // @@protoc_insertion_point(class_scope:rpc.BoolPolicy) private: @@ -1380,6 +1640,7 @@ class BoolPolicy : public ::google::protobuf::Message /* @@protoc_insertion_poin ::google::protobuf::internal::WireFormatLite::TYPE_STRING, ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, 0 > rules_; + ::google::protobuf::RepeatedPtrField< ::std::string> key_; mutable int _cached_size_; friend void protobuf_AddDesc_plugin_2eproto(); friend void protobuf_AssignDesc_plugin_2eproto(); @@ -1584,6 +1845,22 @@ class FloatPolicy : public ::google::protobuf::Message /* @@protoc_insertion_poi ::google::protobuf::Map< ::std::string, ::rpc::FloatRule >* mutable_rules(); + // repeated string key = 2; + int key_size() const; + void clear_key(); + static const int kKeyFieldNumber = 2; + const ::std::string& key(int index) const; + ::std::string* mutable_key(int index); + void set_key(int index, const ::std::string& value); + void set_key(int index, const char* value); + void set_key(int index, const char* value, size_t size); + ::std::string* add_key(); + void add_key(const ::std::string& value); + void add_key(const char* value); + void add_key(const char* value, size_t size); + const ::google::protobuf::RepeatedPtrField< ::std::string>& key() const; + ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_key(); + // @@protoc_insertion_point(class_scope:rpc.FloatPolicy) private: @@ -1600,6 +1877,7 @@ class FloatPolicy : public ::google::protobuf::Message /* @@protoc_insertion_poi ::google::protobuf::internal::WireFormatLite::TYPE_STRING, ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, 0 > rules_; + ::google::protobuf::RepeatedPtrField< ::std::string> key_; mutable int _cached_size_; friend void protobuf_AddDesc_plugin_2eproto(); friend void protobuf_AssignDesc_plugin_2eproto(); @@ -1804,6 +2082,22 @@ class IntegerPolicy : public ::google::protobuf::Message /* @@protoc_insertion_p ::google::protobuf::Map< ::std::string, ::rpc::IntegerRule >* mutable_rules(); + // repeated string key = 2; + int key_size() const; + void clear_key(); + static const int kKeyFieldNumber = 2; + const ::std::string& key(int index) const; + ::std::string* mutable_key(int index); + void set_key(int index, const ::std::string& value); + void set_key(int index, const char* value); + void set_key(int index, const char* value, size_t size); + ::std::string* add_key(); + void add_key(const ::std::string& value); + void add_key(const char* value); + void add_key(const char* value, size_t size); + const ::google::protobuf::RepeatedPtrField< ::std::string>& key() const; + ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_key(); + // @@protoc_insertion_point(class_scope:rpc.IntegerPolicy) private: @@ -1820,6 +2114,7 @@ class IntegerPolicy : public ::google::protobuf::Message /* @@protoc_insertion_p ::google::protobuf::internal::WireFormatLite::TYPE_STRING, ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, 0 > rules_; + ::google::protobuf::RepeatedPtrField< ::std::string> key_; mutable int _cached_size_; friend void protobuf_AddDesc_plugin_2eproto(); friend void protobuf_AssignDesc_plugin_2eproto(); @@ -2001,6 +2296,22 @@ class StringPolicy : public ::google::protobuf::Message /* @@protoc_insertion_po ::google::protobuf::Map< ::std::string, ::rpc::StringRule >* mutable_rules(); + // repeated string key = 2; + int key_size() const; + void clear_key(); + static const int kKeyFieldNumber = 2; + const ::std::string& key(int index) const; + ::std::string* mutable_key(int index); + void set_key(int index, const ::std::string& value); + void set_key(int index, const char* value); + void set_key(int index, const char* value, size_t size); + ::std::string* add_key(); + void add_key(const ::std::string& value); + void add_key(const char* value); + void add_key(const char* value, size_t size); + const ::google::protobuf::RepeatedPtrField< ::std::string>& key() const; + ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_key(); + // @@protoc_insertion_point(class_scope:rpc.StringPolicy) private: @@ -2017,6 +2328,7 @@ class StringPolicy : public ::google::protobuf::Message /* @@protoc_insertion_po ::google::protobuf::internal::WireFormatLite::TYPE_STRING, ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, 0 > rules_; + ::google::protobuf::RepeatedPtrField< ::std::string> key_; mutable int _cached_size_; friend void protobuf_AddDesc_plugin_2eproto(); friend void protobuf_AssignDesc_plugin_2eproto(); @@ -2304,6 +2616,200 @@ class GetMetricTypesArg : public ::google::protobuf::Message /* @@protoc_inserti // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +// CollectArg + +// optional .rpc.MetricsArg Metrics_Arg = 1; +inline bool CollectArg::has_metrics_arg() const { + return !_is_default_instance_ && metrics_arg_ != NULL; +} +inline void CollectArg::clear_metrics_arg() { + if (GetArenaNoVirtual() == NULL && metrics_arg_ != NULL) delete metrics_arg_; + metrics_arg_ = NULL; +} +inline const ::rpc::MetricsArg& CollectArg::metrics_arg() const { + // @@protoc_insertion_point(field_get:rpc.CollectArg.Metrics_Arg) + return metrics_arg_ != NULL ? *metrics_arg_ : *default_instance_->metrics_arg_; +} +inline ::rpc::MetricsArg* CollectArg::mutable_metrics_arg() { + + if (metrics_arg_ == NULL) { + metrics_arg_ = new ::rpc::MetricsArg; + } + // @@protoc_insertion_point(field_mutable:rpc.CollectArg.Metrics_Arg) + return metrics_arg_; +} +inline ::rpc::MetricsArg* CollectArg::release_metrics_arg() { + // @@protoc_insertion_point(field_release:rpc.CollectArg.Metrics_Arg) + + ::rpc::MetricsArg* temp = metrics_arg_; + metrics_arg_ = NULL; + return temp; +} +inline void CollectArg::set_allocated_metrics_arg(::rpc::MetricsArg* metrics_arg) { + delete metrics_arg_; + metrics_arg_ = metrics_arg; + if (metrics_arg) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:rpc.CollectArg.Metrics_Arg) +} + +// optional int64 MaxCollectDuration = 2; +inline void CollectArg::clear_maxcollectduration() { + maxcollectduration_ = GOOGLE_LONGLONG(0); +} +inline ::google::protobuf::int64 CollectArg::maxcollectduration() const { + // @@protoc_insertion_point(field_get:rpc.CollectArg.MaxCollectDuration) + return maxcollectduration_; +} +inline void CollectArg::set_maxcollectduration(::google::protobuf::int64 value) { + + maxcollectduration_ = value; + // @@protoc_insertion_point(field_set:rpc.CollectArg.MaxCollectDuration) +} + +// optional int64 MaxMetricsBuffer = 3; +inline void CollectArg::clear_maxmetricsbuffer() { + maxmetricsbuffer_ = GOOGLE_LONGLONG(0); +} +inline ::google::protobuf::int64 CollectArg::maxmetricsbuffer() const { + // @@protoc_insertion_point(field_get:rpc.CollectArg.MaxMetricsBuffer) + return maxmetricsbuffer_; +} +inline void CollectArg::set_maxmetricsbuffer(::google::protobuf::int64 value) { + + maxmetricsbuffer_ = value; + // @@protoc_insertion_point(field_set:rpc.CollectArg.MaxMetricsBuffer) +} + +// optional bytes Other = 4; +inline void CollectArg::clear_other() { + other_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& CollectArg::other() const { + // @@protoc_insertion_point(field_get:rpc.CollectArg.Other) + return other_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void CollectArg::set_other(const ::std::string& value) { + + other_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:rpc.CollectArg.Other) +} +inline void CollectArg::set_other(const char* value) { + + other_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:rpc.CollectArg.Other) +} +inline void CollectArg::set_other(const void* value, size_t size) { + + other_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:rpc.CollectArg.Other) +} +inline ::std::string* CollectArg::mutable_other() { + + // @@protoc_insertion_point(field_mutable:rpc.CollectArg.Other) + return other_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* CollectArg::release_other() { + // @@protoc_insertion_point(field_release:rpc.CollectArg.Other) + + return other_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void CollectArg::set_allocated_other(::std::string* other) { + if (other != NULL) { + + } else { + + } + other_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), other); + // @@protoc_insertion_point(field_set_allocated:rpc.CollectArg.Other) +} + +// ------------------------------------------------------------------- + +// CollectReply + +// optional .rpc.MetricsReply Metrics_Reply = 1; +inline bool CollectReply::has_metrics_reply() const { + return !_is_default_instance_ && metrics_reply_ != NULL; +} +inline void CollectReply::clear_metrics_reply() { + if (GetArenaNoVirtual() == NULL && metrics_reply_ != NULL) delete metrics_reply_; + metrics_reply_ = NULL; +} +inline const ::rpc::MetricsReply& CollectReply::metrics_reply() const { + // @@protoc_insertion_point(field_get:rpc.CollectReply.Metrics_Reply) + return metrics_reply_ != NULL ? *metrics_reply_ : *default_instance_->metrics_reply_; +} +inline ::rpc::MetricsReply* CollectReply::mutable_metrics_reply() { + + if (metrics_reply_ == NULL) { + metrics_reply_ = new ::rpc::MetricsReply; + } + // @@protoc_insertion_point(field_mutable:rpc.CollectReply.Metrics_Reply) + return metrics_reply_; +} +inline ::rpc::MetricsReply* CollectReply::release_metrics_reply() { + // @@protoc_insertion_point(field_release:rpc.CollectReply.Metrics_Reply) + + ::rpc::MetricsReply* temp = metrics_reply_; + metrics_reply_ = NULL; + return temp; +} +inline void CollectReply::set_allocated_metrics_reply(::rpc::MetricsReply* metrics_reply) { + delete metrics_reply_; + metrics_reply_ = metrics_reply; + if (metrics_reply) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:rpc.CollectReply.Metrics_Reply) +} + +// optional .rpc.ErrReply Error = 2; +inline bool CollectReply::has_error() const { + return !_is_default_instance_ && error_ != NULL; +} +inline void CollectReply::clear_error() { + if (GetArenaNoVirtual() == NULL && error_ != NULL) delete error_; + error_ = NULL; +} +inline const ::rpc::ErrReply& CollectReply::error() const { + // @@protoc_insertion_point(field_get:rpc.CollectReply.Error) + return error_ != NULL ? *error_ : *default_instance_->error_; +} +inline ::rpc::ErrReply* CollectReply::mutable_error() { + + if (error_ == NULL) { + error_ = new ::rpc::ErrReply; + } + // @@protoc_insertion_point(field_mutable:rpc.CollectReply.Error) + return error_; +} +inline ::rpc::ErrReply* CollectReply::release_error() { + // @@protoc_insertion_point(field_release:rpc.CollectReply.Error) + + ::rpc::ErrReply* temp = error_; + error_ = NULL; + return temp; +} +inline void CollectReply::set_allocated_error(::rpc::ErrReply* error) { + delete error_; + error_ = error; + if (error) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:rpc.CollectReply.Error) +} + +// ------------------------------------------------------------------- + // Empty // ------------------------------------------------------------------- @@ -3140,6 +3646,93 @@ inline void Metric::set_allocated_bytes_data(::std::string* bytes_data) { // @@protoc_insertion_point(field_set_allocated:rpc.Metric.bytes_data) } +// optional bool bool_data = 15; +inline bool Metric::has_bool_data() const { + return data_case() == kBoolData; +} +inline void Metric::set_has_bool_data() { + _oneof_case_[0] = kBoolData; +} +inline void Metric::clear_bool_data() { + if (has_bool_data()) { + data_.bool_data_ = false; + clear_has_data(); + } +} +inline bool Metric::bool_data() const { + // @@protoc_insertion_point(field_get:rpc.Metric.bool_data) + if (has_bool_data()) { + return data_.bool_data_; + } + return false; +} +inline void Metric::set_bool_data(bool value) { + if (!has_bool_data()) { + clear_data(); + set_has_bool_data(); + } + data_.bool_data_ = value; + // @@protoc_insertion_point(field_set:rpc.Metric.bool_data) +} + +// optional uint32 uint32_data = 16; +inline bool Metric::has_uint32_data() const { + return data_case() == kUint32Data; +} +inline void Metric::set_has_uint32_data() { + _oneof_case_[0] = kUint32Data; +} +inline void Metric::clear_uint32_data() { + if (has_uint32_data()) { + data_.uint32_data_ = 0u; + clear_has_data(); + } +} +inline ::google::protobuf::uint32 Metric::uint32_data() const { + // @@protoc_insertion_point(field_get:rpc.Metric.uint32_data) + if (has_uint32_data()) { + return data_.uint32_data_; + } + return 0u; +} +inline void Metric::set_uint32_data(::google::protobuf::uint32 value) { + if (!has_uint32_data()) { + clear_data(); + set_has_uint32_data(); + } + data_.uint32_data_ = value; + // @@protoc_insertion_point(field_set:rpc.Metric.uint32_data) +} + +// optional uint64 uint64_data = 17; +inline bool Metric::has_uint64_data() const { + return data_case() == kUint64Data; +} +inline void Metric::set_has_uint64_data() { + _oneof_case_[0] = kUint64Data; +} +inline void Metric::clear_uint64_data() { + if (has_uint64_data()) { + data_.uint64_data_ = GOOGLE_ULONGLONG(0); + clear_has_data(); + } +} +inline ::google::protobuf::uint64 Metric::uint64_data() const { + // @@protoc_insertion_point(field_get:rpc.Metric.uint64_data) + if (has_uint64_data()) { + return data_.uint64_data_; + } + return GOOGLE_ULONGLONG(0); +} +inline void Metric::set_uint64_data(::google::protobuf::uint64 value) { + if (!has_uint64_data()) { + clear_data(); + set_has_uint64_data(); + } + data_.uint64_data_ = value; + // @@protoc_insertion_point(field_set:rpc.Metric.uint64_data) +} + inline bool Metric::has_data() const { return data_case() != DATA_NOT_SET; } @@ -3461,6 +4054,61 @@ BoolPolicy::mutable_rules() { return rules_.MutableMap(); } +// repeated string key = 2; +inline int BoolPolicy::key_size() const { + return key_.size(); +} +inline void BoolPolicy::clear_key() { + key_.Clear(); +} +inline const ::std::string& BoolPolicy::key(int index) const { + // @@protoc_insertion_point(field_get:rpc.BoolPolicy.key) + return key_.Get(index); +} +inline ::std::string* BoolPolicy::mutable_key(int index) { + // @@protoc_insertion_point(field_mutable:rpc.BoolPolicy.key) + return key_.Mutable(index); +} +inline void BoolPolicy::set_key(int index, const ::std::string& value) { + // @@protoc_insertion_point(field_set:rpc.BoolPolicy.key) + key_.Mutable(index)->assign(value); +} +inline void BoolPolicy::set_key(int index, const char* value) { + key_.Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:rpc.BoolPolicy.key) +} +inline void BoolPolicy::set_key(int index, const char* value, size_t size) { + key_.Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:rpc.BoolPolicy.key) +} +inline ::std::string* BoolPolicy::add_key() { + // @@protoc_insertion_point(field_add_mutable:rpc.BoolPolicy.key) + return key_.Add(); +} +inline void BoolPolicy::add_key(const ::std::string& value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add:rpc.BoolPolicy.key) +} +inline void BoolPolicy::add_key(const char* value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add_char:rpc.BoolPolicy.key) +} +inline void BoolPolicy::add_key(const char* value, size_t size) { + key_.Add()->assign(reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:rpc.BoolPolicy.key) +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +BoolPolicy::key() const { + // @@protoc_insertion_point(field_list:rpc.BoolPolicy.key) + return key_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +BoolPolicy::mutable_key() { + // @@protoc_insertion_point(field_mutable_list:rpc.BoolPolicy.key) + return &key_; +} + // ------------------------------------------------------------------- // FloatRule @@ -3585,6 +4233,61 @@ FloatPolicy::mutable_rules() { return rules_.MutableMap(); } +// repeated string key = 2; +inline int FloatPolicy::key_size() const { + return key_.size(); +} +inline void FloatPolicy::clear_key() { + key_.Clear(); +} +inline const ::std::string& FloatPolicy::key(int index) const { + // @@protoc_insertion_point(field_get:rpc.FloatPolicy.key) + return key_.Get(index); +} +inline ::std::string* FloatPolicy::mutable_key(int index) { + // @@protoc_insertion_point(field_mutable:rpc.FloatPolicy.key) + return key_.Mutable(index); +} +inline void FloatPolicy::set_key(int index, const ::std::string& value) { + // @@protoc_insertion_point(field_set:rpc.FloatPolicy.key) + key_.Mutable(index)->assign(value); +} +inline void FloatPolicy::set_key(int index, const char* value) { + key_.Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:rpc.FloatPolicy.key) +} +inline void FloatPolicy::set_key(int index, const char* value, size_t size) { + key_.Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:rpc.FloatPolicy.key) +} +inline ::std::string* FloatPolicy::add_key() { + // @@protoc_insertion_point(field_add_mutable:rpc.FloatPolicy.key) + return key_.Add(); +} +inline void FloatPolicy::add_key(const ::std::string& value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add:rpc.FloatPolicy.key) +} +inline void FloatPolicy::add_key(const char* value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add_char:rpc.FloatPolicy.key) +} +inline void FloatPolicy::add_key(const char* value, size_t size) { + key_.Add()->assign(reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:rpc.FloatPolicy.key) +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +FloatPolicy::key() const { + // @@protoc_insertion_point(field_list:rpc.FloatPolicy.key) + return key_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +FloatPolicy::mutable_key() { + // @@protoc_insertion_point(field_mutable_list:rpc.FloatPolicy.key) + return &key_; +} + // ------------------------------------------------------------------- // IntegerRule @@ -3709,6 +4412,61 @@ IntegerPolicy::mutable_rules() { return rules_.MutableMap(); } +// repeated string key = 2; +inline int IntegerPolicy::key_size() const { + return key_.size(); +} +inline void IntegerPolicy::clear_key() { + key_.Clear(); +} +inline const ::std::string& IntegerPolicy::key(int index) const { + // @@protoc_insertion_point(field_get:rpc.IntegerPolicy.key) + return key_.Get(index); +} +inline ::std::string* IntegerPolicy::mutable_key(int index) { + // @@protoc_insertion_point(field_mutable:rpc.IntegerPolicy.key) + return key_.Mutable(index); +} +inline void IntegerPolicy::set_key(int index, const ::std::string& value) { + // @@protoc_insertion_point(field_set:rpc.IntegerPolicy.key) + key_.Mutable(index)->assign(value); +} +inline void IntegerPolicy::set_key(int index, const char* value) { + key_.Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:rpc.IntegerPolicy.key) +} +inline void IntegerPolicy::set_key(int index, const char* value, size_t size) { + key_.Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:rpc.IntegerPolicy.key) +} +inline ::std::string* IntegerPolicy::add_key() { + // @@protoc_insertion_point(field_add_mutable:rpc.IntegerPolicy.key) + return key_.Add(); +} +inline void IntegerPolicy::add_key(const ::std::string& value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add:rpc.IntegerPolicy.key) +} +inline void IntegerPolicy::add_key(const char* value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add_char:rpc.IntegerPolicy.key) +} +inline void IntegerPolicy::add_key(const char* value, size_t size) { + key_.Add()->assign(reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:rpc.IntegerPolicy.key) +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +IntegerPolicy::key() const { + // @@protoc_insertion_point(field_list:rpc.IntegerPolicy.key) + return key_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +IntegerPolicy::mutable_key() { + // @@protoc_insertion_point(field_mutable_list:rpc.IntegerPolicy.key) + return &key_; +} + // ------------------------------------------------------------------- // StringRule @@ -3807,6 +4565,61 @@ StringPolicy::mutable_rules() { return rules_.MutableMap(); } +// repeated string key = 2; +inline int StringPolicy::key_size() const { + return key_.size(); +} +inline void StringPolicy::clear_key() { + key_.Clear(); +} +inline const ::std::string& StringPolicy::key(int index) const { + // @@protoc_insertion_point(field_get:rpc.StringPolicy.key) + return key_.Get(index); +} +inline ::std::string* StringPolicy::mutable_key(int index) { + // @@protoc_insertion_point(field_mutable:rpc.StringPolicy.key) + return key_.Mutable(index); +} +inline void StringPolicy::set_key(int index, const ::std::string& value) { + // @@protoc_insertion_point(field_set:rpc.StringPolicy.key) + key_.Mutable(index)->assign(value); +} +inline void StringPolicy::set_key(int index, const char* value) { + key_.Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:rpc.StringPolicy.key) +} +inline void StringPolicy::set_key(int index, const char* value, size_t size) { + key_.Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:rpc.StringPolicy.key) +} +inline ::std::string* StringPolicy::add_key() { + // @@protoc_insertion_point(field_add_mutable:rpc.StringPolicy.key) + return key_.Add(); +} +inline void StringPolicy::add_key(const ::std::string& value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add:rpc.StringPolicy.key) +} +inline void StringPolicy::add_key(const char* value) { + key_.Add()->assign(value); + // @@protoc_insertion_point(field_add_char:rpc.StringPolicy.key) +} +inline void StringPolicy::add_key(const char* value, size_t size) { + key_.Add()->assign(reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:rpc.StringPolicy.key) +} +inline const ::google::protobuf::RepeatedPtrField< ::std::string>& +StringPolicy::key() const { + // @@protoc_insertion_point(field_list:rpc.StringPolicy.key) + return key_; +} +inline ::google::protobuf::RepeatedPtrField< ::std::string>* +StringPolicy::mutable_key() { + // @@protoc_insertion_point(field_mutable_list:rpc.StringPolicy.key) + return &key_; +} + // ------------------------------------------------------------------- // MetricsArg @@ -4000,6 +4813,10 @@ inline void GetMetricTypesArg::set_allocated_config(::rpc::ConfigMap* config) { // ------------------------------------------------------------------- +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) diff --git a/src/main.cpp b/src/main.cpp index 0218007..d9eeae5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,14 +18,15 @@ #include "rdt/rdt.hpp" #include "rdt/pqos.hpp" -int main() { +int main(int argc, char **argv) { int exit_code = -1; auto pqos = new rdt::PQOS(); rdt::Collector *rdt; try { rdt = new rdt::Collector(pqos); - start_collector(rdt, rdt->get_plugin_meta()); + Plugin::Meta meta = rdt->get_plugin_meta(); + start_collector(argc, argv, rdt, meta); exit_code = 0; } catch (Plugin::PluginException &e) { fprintf(stderr, "Plugin exception: %s\n", e.what()); diff --git a/src/medium_test.cpp b/src/medium_test.cpp index d1ee4fe..7c052a3 100644 --- a/src/medium_test.cpp +++ b/src/medium_test.cpp @@ -391,12 +391,13 @@ bool is_prefix(std::string const &prefix, std::string const &str) // Extract ns entries and return as single string value std::string extract_ns(const Plugin::Metric &metric) { - std::string ns_str; - for (auto const &elem : metric.ns()) - { - ns_str += "/" + elem.value; - } - return ns_str; + return metric.ns().get_string(); + // std::string ns_str; + // for (auto const &elem : metric.ns()) + // { + // ns_str += "/" + elem.value; + // } + // return ns_str; } // Mock capabilities object @@ -458,38 +459,18 @@ std::vector fixture_metrics(unsigned cpu_cores) for (unsigned i = 0; i < cpu_cores; i++) { - Plugin::Metric::NamespaceElement dynamicCoreIdElement; - dynamicCoreIdElement.value = "*"; - dynamicCoreIdElement.name = "core_id"; - dynamicCoreIdElement.description = "Cache occupancy for core_id"; - std::string core_id = std::to_string(i); - Plugin::Metric llc_occupancy_bytes( - {{"intel"}, {"rdt"}, {"llc_occupancy"}, dynamicCoreIdElement, {"bytes"}}, - "bytes", - "Total LLC Occupancy of CPU " + core_id + " in bytes."); - Plugin::Metric llc_occupancy_percentage( - {{"intel"}, {"rdt"}, {"llc_occupancy"}, dynamicCoreIdElement, {"percentage"}}, - "percentage", - "Total LLC Occupancy of CPU " + core_id + " in bytes."); - Plugin::Metric local_membw_usage_bytes( - {{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"local"}, dynamicCoreIdElement, {"bytes"}}, - "bytes", - "Local memory bandwidth usage for CPU " + core_id + " in bytes."); - Plugin::Metric remote_membw_usage_bytes( - {{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"remote"}, dynamicCoreIdElement, {"bytes"}}, - "bytes", - "Remote memory bandwidth usage for CPU " + core_id + " in bytes."); - Plugin::Metric total_membw_usage_bytes( - {{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"total"}, dynamicCoreIdElement, {"bytes"}}, - "bytes", - "Total memory bandwidth usage for CPU " + core_id + " in bytes."); - - metrics.push_back(llc_occupancy_bytes); - metrics.push_back(llc_occupancy_percentage); - metrics.push_back(local_membw_usage_bytes); - metrics.push_back(remote_membw_usage_bytes); - metrics.push_back(total_membw_usage_bytes); + + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("bytes"), + "bytes","Total LLC Occupancy of CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("percentage"), + "percentage","Total LLC Occupancy of CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("bytes"), + "bytes","Local memory bandwidth usage for CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("bytes"), + "bytes","Remote memory bandwidth usage for CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","total"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("bytes"), + "bytes","Total memory bandwidth usage for CPU " + core_id + " in bytes.")); } return metrics; diff --git a/src/rdt/rdt.cpp b/src/rdt/rdt.cpp index 2b29433..24ea939 100644 --- a/src/rdt/rdt.cpp +++ b/src/rdt/rdt.cpp @@ -22,6 +22,14 @@ namespace rdt { + Plugin::Namespace cmt_capability_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cmt_capability"}); + Plugin::Namespace mbm_local_monitoring_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_local_monitoring"}); + Plugin::Namespace mbm_remote_monitoring_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_remote_monitoring"}); + Plugin::Namespace l3ca_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_allocation"}); + Plugin::Namespace llc_size_ns =Plugin::Namespace({"intel", "rdt", "capabilities", "llc_size"}); + Plugin::Namespace cache_ways_count_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_ways_count"}); + Plugin::Namespace cache_way_size_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_way_size"}); + Collector::Collector(PQOSInterface *pqos) { struct pqos_config config = {0}; @@ -95,23 +103,11 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) { for (int cpu_index = 0; cpu_index < this->core_count; cpu_index++) { - Plugin::Metric::NamespaceElement dynamicCoreIdElement; - dynamicCoreIdElement.value = "*"; - dynamicCoreIdElement.name = "core_id"; - dynamicCoreIdElement.description = "Cache occupancy for core_id"; - std::string core_id = std::to_string(cpu_index); - Plugin::Metric llc_occupancy_bytes( - {{"intel"}, {"rdt"}, {"llc_occupancy"}, dynamicCoreIdElement, {"bytes"}}, - "bytes", - "Total LLC Occupancy of CPU " + core_id + " in bytes."); - Plugin::Metric llc_occupancy_percentage( - {{"intel"}, {"rdt"}, {"llc_occupancy"}, dynamicCoreIdElement, {"percentage"}}, - "percentage", - "Total LLC Occupancy of CPU " + core_id + " in bytes."); - - metrics.push_back(llc_occupancy_bytes); - metrics.push_back(llc_occupancy_percentage); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("bytes"), + "bytes","Total LLC Occupancy of CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("percentage"), + "percentage","Total LLC Occupancy of CPU " + core_id + " in bytes.")); } } @@ -119,68 +115,42 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) if (this->mbm_local_capability || this->mbm_remote_capability) { for (int cpu_index = 0; cpu_index < this->core_count; cpu_index++) { std::string core_id = std::to_string(cpu_index); - Plugin::Metric::NamespaceElement coreId; - coreId.value = "*"; - coreId.name = "core_id"; if (this->mbm_local_capability) { - coreId.description = "core_id to gather local memory bandwidth usage for"; - Plugin::Metric local_membw_usage_bytes( - {{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"local"}, coreId, {"bytes"}}, - "bytes", - "Local memory bandwidth usage for CPU " + core_id + " in bytes." - ); - metrics.push_back(local_membw_usage_bytes); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}).add_dynamic_element("core_id","core_id to gather local memory bandwidth usage for").add_static_element("bytes"), + "bytes","Local memory bandwidth usage for CPU " + core_id + " in bytes.")); } - if (this->mbm_remote_capability) { - Plugin::Metric::NamespaceElement remoteCoreId; - coreId.value = "*"; - coreId.name = "core_id"; - coreId.description = "core_id to gather remote memory bandwidth usage for"; - Plugin::Metric remote_membw_usage_bytes( - {{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"remote"}, remoteCoreId, {"bytes"}}, - "bytes", - "Remote memory bandwidth usage for CPU " + core_id + " in bytes." - ); - metrics.push_back(remote_membw_usage_bytes); - - Plugin::Metric::NamespaceElement totalCoreId; - coreId.value = "*"; - coreId.name = "core_id"; - coreId.description = "core_id to gather total memory bandwidth usage for"; - Plugin::Metric total_membw_usage_bytes( - {{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"total"}, totalCoreId, {"bytes"}}, - "bytes", - "Total memory bandwidth usage for CPU " + core_id + " in bytes." - ); - metrics.push_back(total_membw_usage_bytes); + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_dynamic_element("core_id","core_id to gather remote memory bandwidth usage for").add_static_element("bytes"), + "bytes","Remote memory bandwidth usage for CPU " + core_id + " in bytes.")); + + metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_dynamic_element("core_id","core_id to gather total memory bandwidth usage for").add_static_element("bytes"), + "bytes","Total memory bandwidth usage for CPU " + core_id + " in bytes.")); } - } } // Monitoring capabilities. metrics.push_back(Plugin::Metric( - cmt_capability_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "cmt_capability"}), "bool", "This CPU supports LLC Cache Monitoring." )); metrics.push_back(Plugin::Metric( - mbm_local_monitoring_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_local_monitoring"}), "bool", "This CPU supports Local Memory Bandwidth Monitoring." )); metrics.push_back(Plugin::Metric( - mbm_remote_monitoring_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_remote_monitoring"}), "bool", "This CPU supports Remote Memory Bandwidth Monitoring." )); metrics.push_back(Plugin::Metric( - rdt::l3ca_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "cache_allocation"}), "bool", "This CPU supports L3CA capabilities." )); @@ -188,24 +158,24 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) // CAT Capabilities. metrics.push_back(Plugin::Metric( - rdt::llc_size_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "llc_size"}), "bytes", "LLC Size.")); metrics.push_back(Plugin::Metric( - rdt::cache_ways_count_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "cache_ways_count"}), "bytes", "Number of cache ways in Last Level Cache.")); metrics.push_back(Plugin::Metric( - rdt::cache_way_size_ns, + Plugin::Namespace({"intel", "rdt", "capabilities", "cache_way_size"}), "bytes", "Size of cache way in Last Level Cache.")); return metrics; } -void Collector::collect_metrics(std::vector &metrics) +std::vector Collector::collect_metrics(std::vector &metrics) { metrics.clear(); @@ -244,12 +214,12 @@ std::vector Collector::get_capabilities_metrics() std::vector capabilities; Plugin::Metric cmt_capa_metric; - cmt_capa_metric.set_ns(rdt::cmt_capability_ns); + cmt_capa_metric.set_ns(cmt_capability_ns); cmt_capa_metric.set_data(this->cmt_capability); capabilities.push_back(cmt_capa_metric); Plugin::Metric mbm_local_capa_metric; - mbm_local_capa_metric.set_ns(rdt::mbm_local_monitoring_ns); + mbm_local_capa_metric.set_ns(mbm_local_monitoring_ns); mbm_local_capa_metric.set_data(this->mbm_local_capability); capabilities.push_back(mbm_local_capa_metric); @@ -259,22 +229,22 @@ std::vector Collector::get_capabilities_metrics() capabilities.push_back(mbm_remote_capa_metric); Plugin::Metric l3ca_capa_metric; - l3ca_capa_metric.set_ns(rdt::l3ca_ns); + l3ca_capa_metric.set_ns(l3ca_ns); l3ca_capa_metric.set_data(this->l3ca_capability); capabilities.push_back(l3ca_capa_metric); Plugin::Metric llc_size_metric; - llc_size_metric.set_ns(rdt::llc_size_ns); + llc_size_metric.set_ns(llc_size_ns); llc_size_metric.set_data(this->llc_size); capabilities.push_back(llc_size_metric); Plugin::Metric cache_ways_count_metric; - cache_ways_count_metric.set_ns(rdt::cache_ways_count_ns); + cache_ways_count_metric.set_ns(cache_ways_count_ns); cache_ways_count_metric.set_data(this->cache_ways_count); capabilities.push_back(cache_ways_count_metric); Plugin::Metric cache_way_size_metric; - cache_way_size_metric.set_ns(rdt::cache_way_size_ns); + cache_way_size_metric.set_ns(cache_way_size_ns); cache_way_size_metric.set_data(this->cache_way_size); capabilities.push_back(cache_way_size_metric); @@ -359,23 +329,18 @@ std::vector Collector::get_cmt_metrics() { for (auto &group : this->groups) { - Plugin::Metric cmt_bytes; - - Plugin::Metric::NamespaceElement dynamicCoreIdElement; - dynamicCoreIdElement.value = std::to_string(group->cores[0]); - dynamicCoreIdElement.name = "core_id"; - dynamicCoreIdElement.description = "Cache occupancy for core_id"; + Plugin::Metric cmt_bytes(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), + "",""); double cmt_data = static_cast(group->values.llc); cmt_bytes.set_data(cmt_data); - cmt_bytes.set_ns({{"intel"}, {"rdt"}, {"llc_occupancy"}, dynamicCoreIdElement, {"bytes"}}); - Plugin::Metric cmt_percentage; + Plugin::Metric cmt_percentage(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_static_element(std::to_string(group->cores[0])).add_static_element("percentage"), + "",""); cmt_percentage.set_data((static_cast(cmt_data) / static_cast(this->llc_size)) * 100); - cmt_percentage.set_ns({{"intel"}, {"rdt"}, {"llc_occupancy"}, dynamicCoreIdElement, {"percentage"}}); - metrics.push_back(cmt_bytes); - metrics.push_back(cmt_percentage); + metrics.push_back(cmt_bytes); + metrics.push_back(cmt_percentage); } return metrics; } @@ -386,31 +351,27 @@ std::vector Collector::get_cmt_metrics() { for(auto& group : this->groups) { Plugin::Metric mbw; - Plugin::Metric::NamespaceElement coreId; - coreId.value = std::to_string(group->cores[0]); - coreId.name = "core_id"; - coreId.description = "Memory bandwidth usage per core_id"; - if (this->mbm_local_capability) { + Plugin::Metric mbw(Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), + "",""); double local_mbw = static_cast(group->values.mbm_local_delta); - coreId.description = "core_id to gather local memory bandwidth for"; mbw.set_data(local_mbw); - mbw.set_ns({{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"local"}, coreId, {"bytes"}}); metrics.push_back(mbw); } if (this->mbm_remote_capability) { + Plugin::Metric mbw(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), + "",""); double remote_mbw = static_cast(group->values.mbm_remote_delta); - coreId.description = "core_id to gather remote memory bandwidth for"; mbw.set_data(remote_mbw); - mbw.set_ns({{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"remote"}, coreId, {"bytes"}}); metrics.push_back(mbw); - double total_mbw = static_cast(group->values.mbm_total_delta); - coreId.description = "core_id to gather total memory bandwidth for"; - mbw.set_data(total_mbw); - mbw.set_ns({{"intel"}, {"rdt"}, {"memory_bandwidth"}, {"total"}, coreId, {"bytes"}});\ - metrics.push_back(mbw); + + Plugin::Metric mbw2(Plugin::Namespace({"intel","rdt","memory_bandwidth","total"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), + "",""); + double remote_mbw2 = static_cast(group->values.mbm_total_delta); + mbw2.set_data(remote_mbw2); + metrics.push_back(mbw2); } } return metrics; diff --git a/src/rdt/rdt.hpp b/src/rdt/rdt.hpp index 4efd231..96e5b43 100644 --- a/src/rdt/rdt.hpp +++ b/src/rdt/rdt.hpp @@ -26,13 +26,13 @@ namespace rdt { - const std::vector cmt_capability_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"cmt_capability"}}; - const std::vector mbm_local_monitoring_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"mbm_local_monitoring"}}; - const std::vector mbm_remote_monitoring_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"mbm_remote_monitoring"}}; - const std::vector l3ca_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"cache_allocation"}}; - const std::vector llc_size_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"llc_size"}}; - const std::vector cache_ways_count_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"cache_ways_count"}}; - const std::vector cache_way_size_ns = {{"intel"}, {"rdt"}, {"capabilities"}, {"cache_way_size"}}; + extern Plugin::Namespace cmt_capability_ns ; + extern Plugin::Namespace mbm_local_monitoring_ns ; + extern Plugin::Namespace mbm_remote_monitoring_ns ; + extern Plugin::Namespace l3ca_ns ; + extern Plugin::Namespace llc_size_ns ; + extern Plugin::Namespace cache_ways_count_ns ; + extern Plugin::Namespace cache_way_size_ns; class Collector : public Plugin::CollectorInterface { @@ -42,7 +42,7 @@ namespace rdt const Plugin::ConfigPolicy get_config_policy(); std::vector get_metric_types(Plugin::Config cfg); - void collect_metrics(std::vector &metrics); + std::vector collect_metrics(std::vector &metrics); Plugin::Meta get_plugin_meta(); std::string name = "rdt"; diff --git a/third_party/snap-plugin-lib-cpp b/third_party/snap-plugin-lib-cpp index aa62c24..fe1f73d 160000 --- a/third_party/snap-plugin-lib-cpp +++ b/third_party/snap-plugin-lib-cpp @@ -1 +1 @@ -Subproject commit aa62c247654e4eec9d9a87ee6a7bed812b16bf9c +Subproject commit fe1f73da743cb2d59b00dbb7ed19dfb7bc50a89d From 628c521468091a8bdb00c9f8bb0f045bc737e2b0 Mon Sep 17 00:00:00 2001 From: Rafal Borysionek Date: Fri, 8 Sep 2017 14:33:31 +0200 Subject: [PATCH 2/8] Updated tests and refractored code little bit --- src/medium_test.cpp | 44 ++++++++---------- src/medium_test.hpp | 1 + src/rdt/rdt.cpp | 106 +++++++++++++++++++++++++++----------------- src/rdt/rdt.hpp | 12 ++--- 4 files changed, 90 insertions(+), 73 deletions(-) diff --git a/src/medium_test.cpp b/src/medium_test.cpp index 7c052a3..20113ab 100644 --- a/src/medium_test.cpp +++ b/src/medium_test.cpp @@ -38,7 +38,6 @@ using ::testing::Invoke; #define CAP_METRICS 7 bool is_prefix(std::string const &prefix, std::string const &str); -std::string extract_ns(const Plugin::Metric &metric); pqos_cap *mock_caps(std::vector events); pqos_cpuinfo *mock_cpu(unsigned num_cores); void mock_mon_poll(struct pqos_mon_data **groups, const unsigned num_groups); @@ -215,9 +214,10 @@ void test_collect_no_cmt_cap(PQOSMock *p_mock, pqos_cap *p_cap, unsigned num_cor rdt::Collector *rdt = new rdt::Collector(p_mock); auto metrics = fixture_metrics(num_cores); + auto mts = rdt->collect_metrics(metrics); EXPECT_NO_THROW(rdt->collect_metrics(metrics)); - EXPECT_EQ(metrics.size(), CAP_METRICS); + EXPECT_EQ(mts.size(), CAP_METRICS); EXPECT_CALL(*p_mock, pqos_fini()).Times(1); delete (rdt); delete (p_cpu); @@ -320,13 +320,13 @@ void test_collected_metrics_content(PQOSMock *p_mock, pqos_cap *p_cap, unsigned const double llc_size = 202 * num_cores; // Global metrics independent from CPU core number - expected_values.emplace("/intel/rdt/capabilities/cmt_capability", rdt_metric_data{expected_value : 1, is_float: false}); - expected_values.emplace("/intel/rdt/capabilities/mbm_local_monitoring", rdt_metric_data{expected_value : 1, is_float: false}); - expected_values.emplace("/intel/rdt/capabilities/mbm_remote_monitoring", rdt_metric_data{expected_value : 1, is_float: false}); - expected_values.emplace("/intel/rdt/capabilities/cache_allocation", rdt_metric_data{expected_value : 0, is_float: false}); - expected_values.emplace("/intel/rdt/capabilities/llc_size", rdt_metric_data{expected_value : llc_size, is_float: false}); - expected_values.emplace("/intel/rdt/capabilities/cache_ways_count", rdt_metric_data{expected_value : cache_ways_count, is_float: false}); - expected_values.emplace("/intel/rdt/capabilities/cache_way_size", rdt_metric_data{expected_value : cache_way_size, is_float: false}); + expected_values.emplace("/intel/rdt/capabilities/cmt_capability", rdt_metric_data{expected_value : true, is_float: false, is_bool: true}); + expected_values.emplace("/intel/rdt/capabilities/mbm_local_monitoring", rdt_metric_data{expected_value : true, is_float: false, is_bool: true}); + expected_values.emplace("/intel/rdt/capabilities/mbm_remote_monitoring", rdt_metric_data{expected_value : true, is_float: false, is_bool: true}); + expected_values.emplace("/intel/rdt/capabilities/cache_allocation", rdt_metric_data{expected_value : 0, is_float: false, is_bool: false}); + expected_values.emplace("/intel/rdt/capabilities/llc_size", rdt_metric_data{expected_value : llc_size, is_float: false, is_bool: false}); + expected_values.emplace("/intel/rdt/capabilities/cache_ways_count", rdt_metric_data{expected_value : cache_ways_count, is_float: false, is_bool: false}); + expected_values.emplace("/intel/rdt/capabilities/cache_way_size", rdt_metric_data{expected_value : cache_way_size, is_float: false, is_bool: false}); // Mocks auto p_cpu = mock_cpu(num_cores); @@ -336,7 +336,8 @@ void test_collected_metrics_content(PQOSMock *p_mock, pqos_cap *p_cap, unsigned // Start collecting all metrics rdt::Collector *rdt = new rdt::Collector(p_mock); auto metrics = fixture_metrics(num_cores); - EXPECT_NO_THROW(rdt->collect_metrics(metrics)); + auto mts = rdt->collect_metrics(metrics); + // /EXPECT_NO_THROW(rdt->collect_metrics(metrics)); // Fill expected values map with per-core metric values for (int cpu_id = 0; cpu_id < num_cores; cpu_id++) { @@ -344,17 +345,20 @@ void test_collected_metrics_content(PQOSMock *p_mock, pqos_cap *p_cap, unsigned } // Checking if collected metrics values equal expected ones - for (int i = 0; i < metrics.size(); i++) + for (int i = 0; i < mts.size(); i++) { - auto metric_ns = extract_ns(metrics[i]); + std::string metric_ns = "/"; + metric_ns += mts[i].ns().get_string(); auto tested_ns = expected_values.find(metric_ns) != expected_values.end(); EXPECT_TRUE(tested_ns); if (tested_ns) { if (expected_values[metric_ns].is_float) - EXPECT_EQ(expected_values[metric_ns].expected_value, metrics[i].get_float64_data()); + EXPECT_EQ(expected_values[metric_ns].expected_value, mts[i].get_float64_data()); + else if (expected_values[metric_ns].is_bool) + EXPECT_EQ(expected_values[metric_ns].expected_value, mts[i].get_bool_data()); else - EXPECT_EQ(expected_values[metric_ns].expected_value, metrics[i].get_int_data()); + EXPECT_EQ(expected_values[metric_ns].expected_value, mts[i].get_int_data()); } } @@ -388,18 +392,6 @@ bool is_prefix(std::string const &prefix, std::string const &str) return res.first == prefix.end(); } -// Extract ns entries and return as single string value -std::string extract_ns(const Plugin::Metric &metric) -{ - return metric.ns().get_string(); - // std::string ns_str; - // for (auto const &elem : metric.ns()) - // { - // ns_str += "/" + elem.value; - // } - // return ns_str; -} - // Mock capabilities object pqos_cap *mock_caps(std::vector events) { diff --git a/src/medium_test.hpp b/src/medium_test.hpp index ebd9482..08e904d 100644 --- a/src/medium_test.hpp +++ b/src/medium_test.hpp @@ -26,6 +26,7 @@ namespace rdt typedef struct { double expected_value; bool is_float; + bool is_bool; } rdt_metric_data; typedef std::unordered_map rdt_metric_map; diff --git a/src/rdt/rdt.cpp b/src/rdt/rdt.cpp index 24ea939..ff21d9b 100644 --- a/src/rdt/rdt.cpp +++ b/src/rdt/rdt.cpp @@ -21,12 +21,11 @@ namespace rdt { - - Plugin::Namespace cmt_capability_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cmt_capability"}); - Plugin::Namespace mbm_local_monitoring_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_local_monitoring"}); - Plugin::Namespace mbm_remote_monitoring_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_remote_monitoring"}); - Plugin::Namespace l3ca_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_allocation"}); - Plugin::Namespace llc_size_ns =Plugin::Namespace({"intel", "rdt", "capabilities", "llc_size"}); + Plugin::Namespace cmt_capability_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cmt_capability"}); + Plugin::Namespace mbm_local_monitoring_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_local_monitoring"}); + Plugin::Namespace mbm_remote_monitoring_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_remote_monitoring"}); + Plugin::Namespace l3ca_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_allocation"}); + Plugin::Namespace llc_size_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "llc_size"}); Plugin::Namespace cache_ways_count_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_ways_count"}); Plugin::Namespace cache_way_size_ns = Plugin::Namespace({"intel", "rdt", "capabilities", "cache_way_size"}); @@ -104,10 +103,18 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) for (int cpu_index = 0; cpu_index < this->core_count; cpu_index++) { std::string core_id = std::to_string(cpu_index); - metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("bytes"), - "bytes","Total LLC Occupancy of CPU " + core_id + " in bytes.")); - metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_dynamic_element("core_id","Cache occupancy for core_id").add_static_element("percentage"), - "percentage","Total LLC Occupancy of CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric( + Plugin::Namespace({"intel","rdt","llc_occupancy"}). + add_dynamic_element("core_id","Cache occupancy for core_id"). + add_static_element("bytes"), + "bytes", + "Total LLC Occupancy of CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric( + Plugin::Namespace({"intel","rdt","llc_occupancy"}). + add_dynamic_element("core_id","Cache occupancy for core_id"). + add_static_element("percentage"), + "percentage", + "Total LLC Occupancy of CPU " + core_id + " in bytes.")); } } @@ -117,40 +124,52 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) std::string core_id = std::to_string(cpu_index); if (this->mbm_local_capability) { - metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}).add_dynamic_element("core_id","core_id to gather local memory bandwidth usage for").add_static_element("bytes"), - "bytes","Local memory bandwidth usage for CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric( + Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}). + add_dynamic_element("core_id","core_id to gather local memory bandwidth usage for"). + add_static_element("bytes"), + "bytes", + "Local memory bandwidth usage for CPU " + core_id + " in bytes.")); } if (this->mbm_remote_capability) { - metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_dynamic_element("core_id","core_id to gather remote memory bandwidth usage for").add_static_element("bytes"), - "bytes","Remote memory bandwidth usage for CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric( + Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}). + add_dynamic_element("core_id","core_id to gather remote memory bandwidth usage for"). + add_static_element("bytes"), + "bytes", + "Remote memory bandwidth usage for CPU " + core_id + " in bytes.")); - metrics.push_back(Plugin::Metric(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_dynamic_element("core_id","core_id to gather total memory bandwidth usage for").add_static_element("bytes"), - "bytes","Total memory bandwidth usage for CPU " + core_id + " in bytes.")); + metrics.push_back(Plugin::Metric( + Plugin::Namespace({"intel","rdt","memory_bandwidth","total"}). + add_dynamic_element("core_id","core_id to gather total memory bandwidth usage for"). + add_static_element("bytes"), + "bytes", + "Total memory bandwidth usage for CPU " + core_id + " in bytes.")); } } } // Monitoring capabilities. metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "cmt_capability"}), + cmt_capability_ns, "bool", "This CPU supports LLC Cache Monitoring." )); metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_local_monitoring"}), + mbm_local_monitoring_ns, "bool", "This CPU supports Local Memory Bandwidth Monitoring." )); metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "mbm_remote_monitoring"}), + mbm_remote_monitoring_ns, "bool", "This CPU supports Remote Memory Bandwidth Monitoring." )); metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "cache_allocation"}), + rdt::l3ca_ns, "bool", "This CPU supports L3CA capabilities." )); @@ -158,27 +177,26 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) // CAT Capabilities. metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "llc_size"}), + l3ca_ns, "bytes", "LLC Size.")); metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "cache_ways_count"}), + cache_ways_count_ns, "bytes", "Number of cache ways in Last Level Cache.")); metrics.push_back(Plugin::Metric( - Plugin::Namespace({"intel", "rdt", "capabilities", "cache_way_size"}), + cache_way_size_ns, "bytes", "Size of cache way in Last Level Cache.")); return metrics; } -std::vector Collector::collect_metrics(std::vector &metrics) +std::vector Collector::collect_metrics(std::vector &mts) { - metrics.clear(); - + std::vector metrics; // Load metrics. if (!this->is_monitoring_active) { this->setup_monitoring(); @@ -206,7 +224,7 @@ std::vector Collector::collect_metrics(std::vector Collector::get_capabilities_metrics() @@ -329,14 +347,20 @@ std::vector Collector::get_cmt_metrics() { for (auto &group : this->groups) { - Plugin::Metric cmt_bytes(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), - "",""); + Plugin::Metric cmt_bytes( + Plugin::Namespace({"intel","rdt","llc_occupancy"}). + add_static_element(std::to_string(group->cores[0])). + add_static_element("bytes"), + "",""); double cmt_data = static_cast(group->values.llc); cmt_bytes.set_data(cmt_data); - Plugin::Metric cmt_percentage(Plugin::Namespace({"intel","rdt","llc_occupancy"}).add_static_element(std::to_string(group->cores[0])).add_static_element("percentage"), - "",""); + Plugin::Metric cmt_percentage( + Plugin::Namespace({"intel","rdt","llc_occupancy"}). + add_static_element(std::to_string(group->cores[0])). + add_static_element("percentage"), + "",""); cmt_percentage.set_data((static_cast(cmt_data) / static_cast(this->llc_size)) * 100); metrics.push_back(cmt_bytes); @@ -350,28 +374,28 @@ std::vector Collector::get_cmt_metrics() { for(auto& group : this->groups) { Plugin::Metric mbw; + std::string coreId = std::to_string(group->cores[0]); if (this->mbm_local_capability) { - Plugin::Metric mbw(Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), - "",""); + Plugin::Namespace local_ns({"intel","rdt","memory_bandwidth","local",coreId,"bytes"}); + mbw.set_ns(local_ns); double local_mbw = static_cast(group->values.mbm_local_delta); mbw.set_data(local_mbw); metrics.push_back(mbw); } if (this->mbm_remote_capability) { - Plugin::Metric mbw(Plugin::Namespace({"intel","rdt","memory_bandwidth","remote"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), - "",""); + Plugin::Namespace remote_ns({"intel","rdt","memory_bandwidth","remote",coreId,"bytes"}); + mbw.set_ns(remote_ns); double remote_mbw = static_cast(group->values.mbm_remote_delta); mbw.set_data(remote_mbw); metrics.push_back(mbw); - - Plugin::Metric mbw2(Plugin::Namespace({"intel","rdt","memory_bandwidth","total"}).add_static_element(std::to_string(group->cores[0])).add_static_element("bytes"), - "",""); - double remote_mbw2 = static_cast(group->values.mbm_total_delta); - mbw2.set_data(remote_mbw2); - metrics.push_back(mbw2); + Plugin::Namespace total_ns({"intel","rdt","memory_bandwidth","total",coreId,"bytes"}); + mbw.set_ns(total_ns); + double total_mbw = static_cast(group->values.mbm_total_delta); + mbw.set_data(total_mbw); + metrics.push_back(mbw); } } return metrics; diff --git a/src/rdt/rdt.hpp b/src/rdt/rdt.hpp index 96e5b43..5061b1d 100644 --- a/src/rdt/rdt.hpp +++ b/src/rdt/rdt.hpp @@ -26,12 +26,12 @@ namespace rdt { - extern Plugin::Namespace cmt_capability_ns ; - extern Plugin::Namespace mbm_local_monitoring_ns ; - extern Plugin::Namespace mbm_remote_monitoring_ns ; - extern Plugin::Namespace l3ca_ns ; - extern Plugin::Namespace llc_size_ns ; - extern Plugin::Namespace cache_ways_count_ns ; + extern Plugin::Namespace cmt_capability_ns; + extern Plugin::Namespace mbm_local_monitoring_ns; + extern Plugin::Namespace mbm_remote_monitoring_ns; + extern Plugin::Namespace l3ca_ns; + extern Plugin::Namespace llc_size_ns; + extern Plugin::Namespace cache_ways_count_ns; extern Plugin::Namespace cache_way_size_ns; class Collector : public Plugin::CollectorInterface From cab8bc61242a2ffaf833b43a047883dd0d007fd2 Mon Sep 17 00:00:00 2001 From: Rafal Borysionek Date: Fri, 8 Sep 2017 14:56:12 +0200 Subject: [PATCH 3/8] Fixed get_metric_types issue. Added example task --- src/medium_test.cpp | 17 ++++++++--------- src/rdt/rdt.cpp | 18 +++++------------- task.json | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 task.json diff --git a/src/medium_test.cpp b/src/medium_test.cpp index 20113ab..4c314e5 100644 --- a/src/medium_test.cpp +++ b/src/medium_test.cpp @@ -113,10 +113,10 @@ TEST(GetMetricTypesTest, TestMetricCountMultiCpu) EXPECT_CALL(p_mock, pqos_init(_)).WillRepeatedly(Return(PQOS_RETVAL_OK)); int mts_per_core = CMT_METRICS_PER_CORE + MBM_LOCAL_METRICS_PER_CORE + MBM_REMOTE_METRICS_PER_CORE; - test_get_metric_types(&p_mock, p_cap, 1, CAP_METRICS + 1 * mts_per_core); - test_get_metric_types(&p_mock, p_cap, 2, CAP_METRICS + 2 * mts_per_core); - test_get_metric_types(&p_mock, p_cap, 3, CAP_METRICS + 3 * mts_per_core); - test_get_metric_types(&p_mock, p_cap, 4, CAP_METRICS + 4 * mts_per_core); + test_get_metric_types(&p_mock, p_cap, 1, CAP_METRICS + mts_per_core); + test_get_metric_types(&p_mock, p_cap, 2, CAP_METRICS + mts_per_core); + test_get_metric_types(&p_mock, p_cap, 3, CAP_METRICS + mts_per_core); + test_get_metric_types(&p_mock, p_cap, 4, CAP_METRICS + mts_per_core); delete (p_cap); } @@ -151,10 +151,10 @@ TEST(GetMetricTypesTest, TestMetricCountMultiCpuNoCmtCap) EXPECT_CALL(p_mock, pqos_init(_)).WillRepeatedly(Return(PQOS_RETVAL_OK)); int mts_per_core = MBM_LOCAL_METRICS_PER_CORE + MBM_REMOTE_METRICS_PER_CORE; - test_get_metric_types(&p_mock, p_cap, 1, CAP_METRICS + 1 * mts_per_core); - test_get_metric_types(&p_mock, p_cap, 2, CAP_METRICS + 2 * mts_per_core); - test_get_metric_types(&p_mock, p_cap, 3, CAP_METRICS + 3 * mts_per_core); - test_get_metric_types(&p_mock, p_cap, 4, CAP_METRICS + 4 * mts_per_core); + test_get_metric_types(&p_mock, p_cap, 1, CAP_METRICS + mts_per_core); + test_get_metric_types(&p_mock, p_cap, 2, CAP_METRICS + mts_per_core); + test_get_metric_types(&p_mock, p_cap, 3, CAP_METRICS + mts_per_core); + test_get_metric_types(&p_mock, p_cap, 4, CAP_METRICS + mts_per_core); delete (p_cap); } @@ -337,7 +337,6 @@ void test_collected_metrics_content(PQOSMock *p_mock, pqos_cap *p_cap, unsigned rdt::Collector *rdt = new rdt::Collector(p_mock); auto metrics = fixture_metrics(num_cores); auto mts = rdt->collect_metrics(metrics); - // /EXPECT_NO_THROW(rdt->collect_metrics(metrics)); // Fill expected values map with per-core metric values for (int cpu_id = 0; cpu_id < num_cores; cpu_id++) { diff --git a/src/rdt/rdt.cpp b/src/rdt/rdt.cpp index ff21d9b..04837c1 100644 --- a/src/rdt/rdt.cpp +++ b/src/rdt/rdt.cpp @@ -100,36 +100,29 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) // CMT Count. if (this->cmt_capability) { - for (int cpu_index = 0; cpu_index < this->core_count; cpu_index++) - { - std::string core_id = std::to_string(cpu_index); metrics.push_back(Plugin::Metric( Plugin::Namespace({"intel","rdt","llc_occupancy"}). add_dynamic_element("core_id","Cache occupancy for core_id"). add_static_element("bytes"), "bytes", - "Total LLC Occupancy of CPU " + core_id + " in bytes.")); + "Total LLC Occupancy for each CPU in bytes.")); metrics.push_back(Plugin::Metric( Plugin::Namespace({"intel","rdt","llc_occupancy"}). add_dynamic_element("core_id","Cache occupancy for core_id"). add_static_element("percentage"), "percentage", - "Total LLC Occupancy of CPU " + core_id + " in bytes.")); - } + "Total LLC Occupancy for each CPU in bytes.")); } // MBM metrics if (this->mbm_local_capability || this->mbm_remote_capability) { - for (int cpu_index = 0; cpu_index < this->core_count; cpu_index++) { - std::string core_id = std::to_string(cpu_index); - if (this->mbm_local_capability) { metrics.push_back(Plugin::Metric( Plugin::Namespace({"intel","rdt","memory_bandwidth","local"}). add_dynamic_element("core_id","core_id to gather local memory bandwidth usage for"). add_static_element("bytes"), "bytes", - "Local memory bandwidth usage for CPU " + core_id + " in bytes.")); + "Local memory bandwidth usage for each CPU in bytes.")); } if (this->mbm_remote_capability) { metrics.push_back(Plugin::Metric( @@ -137,15 +130,14 @@ std::vector Collector::get_metric_types(Plugin::Config cfg) add_dynamic_element("core_id","core_id to gather remote memory bandwidth usage for"). add_static_element("bytes"), "bytes", - "Remote memory bandwidth usage for CPU " + core_id + " in bytes.")); + "Remote memory bandwidth usage for each CPU in bytes.")); metrics.push_back(Plugin::Metric( Plugin::Namespace({"intel","rdt","memory_bandwidth","total"}). add_dynamic_element("core_id","core_id to gather total memory bandwidth usage for"). add_static_element("bytes"), "bytes", - "Total memory bandwidth usage for CPU " + core_id + " in bytes.")); - } + "Total memory bandwidth usage for each CPU in bytes.")); } } diff --git a/task.json b/task.json new file mode 100644 index 0000000..bd07948 --- /dev/null +++ b/task.json @@ -0,0 +1,18 @@ +{ + "version":1, + "schedule":{ + "type":"simple", + "interval":"1s" + }, + "max-failures":10, + "workflow":{ + "collect":{ + "metrics":{ + "/intel/rdt/llc_occupancy/*/bytes":{}, + "/intel/rdt/capabilities/cmt_capability":{}, + "/intel/rdt/capabilities/cache_allocation":{}, + "/intel/rdt/llc_occupancy/*/percentage":{} + } + } + } +} From 44f9d1a37aa6927f2ce85c2e66f7acb2f3c798fc Mon Sep 17 00:00:00 2001 From: Rafal Borysionek Date: Thu, 14 Sep 2017 12:41:47 +0200 Subject: [PATCH 4/8] Testing build on vagrant --- Vagrant/Vagrantfile | 8 +++++-- build.sh | 3 +++ install_deps_centos.sh | 53 +++++++++++++++++++++--------------------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Vagrant/Vagrantfile b/Vagrant/Vagrantfile index 8e01e9c..41984f8 100644 --- a/Vagrant/Vagrantfile +++ b/Vagrant/Vagrantfile @@ -80,10 +80,14 @@ Vagrant.configure("2") do |config| # documentation for more information about their specific syntax and use. config.vm.provision "shell", inline: <<-SHELL sudo yum update -y - sudo yum install -y git cmake mc tmux autoconf automake libtool curl make unzip wget clang gcc-c++ + sudo yum install -y git cmake mc tmux autoconf automake libtool curl make unzip wget golang clang gcc-c++ protobuf-compiler libprotobuf-dev libprotoc-dev centos-release-scl-rh + sudo yum install -y devtoolset-3-gcc devtoolset-3-gcc-c++ + sudo scl enable devtoolset-3 bash + export PATH=/opt/rh/devtoolset-3/root/usr/bin/:$PATH + gcc --version cd snap-plugin-collector-rdt git submodule update --init ./install_deps_centos.sh ./build.sh SHELL -end +end \ No newline at end of file diff --git a/build.sh b/build.sh index 76f99b2..8c00b81 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash + +export PATH=/opt/rh/devtoolset-3/root/usr/bin/:$PATH +gcc --version mkdir -p build cd build cmake .. diff --git a/install_deps_centos.sh b/install_deps_centos.sh index e57d652..8979166 100755 --- a/install_deps_centos.sh +++ b/install_deps_centos.sh @@ -18,8 +18,13 @@ set -e mkdir -p lib -export CC=/usr/bin/gcc -export CXX=/usr/bin/g++ +# export CC=/usr/bin/gcc +# export CXX=/usr/bin/g++ + +export CC=/opt/rh/devtoolset-3/root/usr/bin/gcc +export CXX=/opt/rh/devtoolset-3/root/usr/bin/g++ + +gcc --version pushd `pwd` cd third_party/intel-cmt-cat/lib/ @@ -27,35 +32,31 @@ make SHARED=n cp libpqos.a ../../../lib/ popd -if [ ! -d "./third_party/protobuf/gmock" ] -then pushd `pwd` -cd ./third_party/protobuf -wget http://pkgs.fedoraproject.org/repo/pkgs/gmock/gmock-1.7.0.zip/073b984d8798ea1594f5e44d85b20d66/gmock-1.7.0.zip -unzip -q gmock-1.7.0.zip -rm gmock-1.7.0.zip -mv gmock-1.7.0 gmock -popd -fi - +cd ./third_party/grpc +git checkout tags/v1.0.1 +git submodule update --init +make -j2 +make install pushd `pwd` cd ./third_party/protobuf +make clean ./autogen.sh ./configure make -j2 -make install +make install +popd popd pushd `pwd` -cd ./third_party/grpc -git checkout tags/v1.0.1 -git submodule update --init +cd ./third_party/googletest +cmake CMakeLists.txt make -j2 make install +cp googlemock/libgmock.a ../../lib +cp googlemock/gtest/libgtest.a ../../lib popd - -export CC=/usr/bin/clang -export CXX=/usr/bin/clang++ +echo PO GOOGLETEST pushd `pwd` cd ./third_party/snap-plugin-lib-cpp @@ -68,14 +69,14 @@ cp build/lib/libsnap.a ../../lib popd pushd `pwd` -cd ./third_party/googletest -cmake CMakeLists.txt -make -j2 -make install -cp googlemock/libgmock.a ../../lib -cp googlemock/gtest/libgtest.a ../../lib +cd ./third_party +git clone https://github.com/square/certstrap +cd certstrap +./build +export PATH=$PATH:/opt/certstrap/bin +popd popd # /usr/local/lib is usually not in LD_LIBRARY_PATH #sudo cp /usr/local/lib/* /usr/lib -ldconfig -v +ldconfig -v \ No newline at end of file From 81717345e5afaf6f6f1d42c6f8c963bb82e3c88c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 14 Sep 2017 13:06:19 +0000 Subject: [PATCH 5/8] Bumping release number to 44f9d1a37aa6927f2ce85c2e66f7acb2f3c798fc --- .../boost/network/version.hpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 third_party/netlib/cpp-netlib-0.11.2-final/boost/network/version.hpp diff --git a/third_party/netlib/cpp-netlib-0.11.2-final/boost/network/version.hpp b/third_party/netlib/cpp-netlib-0.11.2-final/boost/network/version.hpp new file mode 100644 index 0000000..14d6770 --- /dev/null +++ b/third_party/netlib/cpp-netlib-0.11.2-final/boost/network/version.hpp @@ -0,0 +1,22 @@ +#ifndef BOOST_NETWORK_VERSION_HPP_20091214 +#define BOOST_NETWORK_VERSION_HPP_20091214 + +// Copyright 2009, 2013 Dean Michael Berris +// Copyright Glyn Matthews 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +#define BOOST_NETLIB_VERSION_MAJOR 0 +#define BOOST_NETLIB_VERSION_MINOR 11 +#define BOOST_NETLIB_VERSION_INCREMENT 2 + +#ifndef BOOST_NETLIB_VERSION +#define BOOST_NETLIB_VERSION \ + BOOST_STRINGIZE(BOOST_NETLIB_VERSION_MAJOR) "." BOOST_STRINGIZE( \ + BOOST_NETLIB_VERSION_MINOR) "." BOOST_STRINGIZE(BOOST_NETLIB_VERSION_INCREMENT) +#endif // BOOST_NETLIB_VERSION + +#endif // BOOST_NETWORK_VERSION_HPP_20091214 From d5da87b63be69302f1d6812b73b44ef42a832385 Mon Sep 17 00:00:00 2001 From: Rafal Borysionek Date: Thu, 14 Sep 2017 15:46:51 +0200 Subject: [PATCH 6/8] Again testing vagrant work in progress- testing --- Docker/Dockerfile.travis | 5 +- Vagrant/Vagrantfile | 9 +- build.sh | 4 +- include/snap/plugin.h | 100 +++++++++-- include/snap/rpc/plugin.grpc.pb.h | 275 ++++++++++++++++++++++++++++++ install_deps_centos.sh | 61 ++++--- 6 files changed, 408 insertions(+), 46 deletions(-) diff --git a/Docker/Dockerfile.travis b/Docker/Dockerfile.travis index a7aaeee..fe00ac2 100644 --- a/Docker/Dockerfile.travis +++ b/Docker/Dockerfile.travis @@ -18,4 +18,7 @@ FROM centos:7 RUN yum update -y RUN yum groupinstall -y base -RUN yum install -y git cmake mc tmux autoconf automake libtool curl make unzip wget clang gcc-c++ +RUN yum install -y git cmake mc tmux autoconf automake python-devel libtool zlib-devel openssl-devel curl make unzip wget golang clang bzip2-devel gcc-c++ protobuf-compiler libprotobuf-dev libprotoc-dev centos-release-scl-rh +RUN yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++ +RUN scl enable devtoolset-4 bash +RUN export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH \ No newline at end of file diff --git a/Vagrant/Vagrantfile b/Vagrant/Vagrantfile index 41984f8..17a1d64 100644 --- a/Vagrant/Vagrantfile +++ b/Vagrant/Vagrantfile @@ -80,11 +80,10 @@ Vagrant.configure("2") do |config| # documentation for more information about their specific syntax and use. config.vm.provision "shell", inline: <<-SHELL sudo yum update -y - sudo yum install -y git cmake mc tmux autoconf automake libtool curl make unzip wget golang clang gcc-c++ protobuf-compiler libprotobuf-dev libprotoc-dev centos-release-scl-rh - sudo yum install -y devtoolset-3-gcc devtoolset-3-gcc-c++ - sudo scl enable devtoolset-3 bash - export PATH=/opt/rh/devtoolset-3/root/usr/bin/:$PATH - gcc --version + sudo yum install -y git cmake mc tmux autoconf automake libtool zlib-devel openssl-devel curl make unzip wget golang clang gcc-c++ protobuf-compiler libprotobuf-dev libprotoc-dev centos-release-scl-rh + sudo yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++ + sudo scl enable devtoolset-4 bash + export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH cd snap-plugin-collector-rdt git submodule update --init ./install_deps_centos.sh diff --git a/build.sh b/build.sh index 8c00b81..fdfdd51 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -export PATH=/opt/rh/devtoolset-3/root/usr/bin/:$PATH +export CC=/opt/rh/devtoolset-4/root/usr/bin/gcc +export CXX=/opt/rh/devtoolset-4/root/usr/bin/g++ +export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH gcc --version mkdir -p build cd build diff --git a/include/snap/plugin.h b/include/snap/plugin.h index 57ff90d..e9715c8 100644 --- a/include/snap/plugin.h +++ b/include/snap/plugin.h @@ -19,6 +19,8 @@ limitations under the License. #include #include +#include + #include "snap/config.h" #include "snap/metric.h" #include "snap/flags.h" @@ -29,14 +31,15 @@ namespace Plugin { class CollectorInterface; class ProcessorInterface; class PublisherInterface; - + class StreamCollectorInterface; /** * Type is the plugin type */ enum Type { Collector, Processor, - Publisher + Publisher, + StreamCollector }; /** @@ -78,8 +81,7 @@ namespace Plugin { */ class Meta final { public: - Meta(Type type, std::string name, int version); - Meta(Type type, std::string name, int version, Flags *flags); + Meta(Type type, std::string name, int version, RpcType rpc_type = GRPC); Type type; std::string name; @@ -176,20 +178,6 @@ namespace Plugin { */ int stand_alone_port; - /** - * sets the maximum duration (always greater than 0s) between collections - * before metrics are sent. Defaults to 10s what means that after 10 seconds - * no new metrics are received, the plugin should send whatever data it has - * in the buffer instead of waiting longer. (e.g. 5s) - */ - std::chrono::seconds max_collect_duration; - - /** - * maximum number of metrics the plugin is buffering before sending metrics. - * Defaults to zero what means send metrics immediately - */ - int64_t max_metrics_buffer; - /** * use_cli_args updates plugin meta using arguments from cli */ @@ -218,6 +206,7 @@ namespace Plugin { virtual CollectorInterface* IsCollector(); virtual ProcessorInterface* IsProcessor(); virtual PublisherInterface* IsPublisher(); + virtual StreamCollectorInterface* IsStreamCollector(); virtual const ConfigPolicy get_config_policy() = 0; protected: @@ -366,6 +355,80 @@ namespace Plugin { + /** + * The interface for a stream collector plugin. + * A Stream Collector is the source. + * It is responsible for streaming metrics in the Snap pipeline. + */ + class StreamCollectorInterface : public PluginInterface { + public: + Type GetType() const final; + StreamCollectorInterface* IsStreamCollector() final; + + void SetMaxCollectDuration(std::chrono::seconds maxCollectDuration) { + _max_collect_duration = maxCollectDuration; + } + void SetMaxCollectDuration(int64_t maxCollectDuration) { + _max_collect_duration = std::chrono::seconds(maxCollectDuration); + } + std::chrono::seconds GetMaxCollectDuration() { + return _max_collect_duration; + } + + void SetMaxMetricsBuffer(int64_t maxMetricsBuffer) { + _max_metrics_buffer = maxMetricsBuffer; + } + int64_t GetMaxMetricsBuffer() { + return _max_metrics_buffer; + } + + /* + * (inherited from PluginInterface) + */ + virtual const ConfigPolicy get_config_policy() = 0; + + virtual std::vector get_metric_types(Config cfg) = 0; + + /* StreamMetrics allows the plugin to send/receive metrics on a channel + * Arguments are (in order): + * + * A channel for metrics into the plugin from Snap -- which + * are the metric types snap is requesting the plugin to collect. + * + * A channel for metrics from the plugin to Snap -- the actual + * collected metrics from the plugin. + * + * A channel for error strings that the library will report to snap + * as task errors. + */ + virtual void stream_metrics() = 0; + + virtual std::vector put_metrics_out() = 0; + virtual std::string put_err_msg() = 0; + virtual void get_metrics_in(std::vector &metsIn) = 0; + virtual bool put_mets() = 0; + virtual bool put_err() = 0; + virtual void set_put_mets(const bool &putMets) = 0; + virtual void set_put_err(const bool &putErr) = 0; + virtual void set_context_cancelled(const bool &contextCancelled) = 0; + virtual bool context_cancelled() = 0; + + private: + /** + * sets the maximum duration (always greater than 0s) between collections + * before metrics are sent. Defaults to 10s what means that after 10 seconds + * no new metrics are received, the plugin should send whatever data it has + * in the buffer instead of waiting longer. (e.g. 5s) + */ + std::chrono::seconds _max_collect_duration; + + /** + * maximum number of metrics the plugin is buffering before sending metrics. + * Defaults to zero what means send metrics immediately + */ + int64_t _max_metrics_buffer; + }; + /** * These functions are called to start a plugin. * They export plugin using default PluginExporter based on GRPC: @@ -378,4 +441,5 @@ namespace Plugin { void start_collector(int argc, char **argv, CollectorInterface* plg, Meta& meta); void start_processor(int argc, char **argv, ProcessorInterface* plg, Meta& meta); void start_publisher(int argc, char **argv, PublisherInterface* plg, Meta& meta); + void start_stream_collector(int argc, char **argv, StreamCollectorInterface* plg, Meta& meta); }; // namespace Plugin diff --git a/include/snap/rpc/plugin.grpc.pb.h b/include/snap/rpc/plugin.grpc.pb.h index ca1b7ff..7acd1e7 100644 --- a/include/snap/rpc/plugin.grpc.pb.h +++ b/include/snap/rpc/plugin.grpc.pb.h @@ -752,6 +752,281 @@ class Publisher GRPC_FINAL { }; }; +class StreamCollector GRPC_FINAL { + public: + class StubInterface { + public: + virtual ~StubInterface() {} + std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::rpc::CollectArg, ::rpc::CollectReply>> StreamMetrics(::grpc::ClientContext* context) { + return std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::rpc::CollectArg, ::rpc::CollectReply>>(StreamMetricsRaw(context)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::rpc::CollectArg, ::rpc::CollectReply>> AsyncStreamMetrics(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::rpc::CollectArg, ::rpc::CollectReply>>(AsyncStreamMetricsRaw(context, cq, tag)); + } + virtual ::grpc::Status GetMetricTypes(::grpc::ClientContext* context, const ::rpc::GetMetricTypesArg& request, ::rpc::MetricsReply* response) = 0; + std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::MetricsReply>> AsyncGetMetricTypes(::grpc::ClientContext* context, const ::rpc::GetMetricTypesArg& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::MetricsReply>>(AsyncGetMetricTypesRaw(context, request, cq)); + } + virtual ::grpc::Status Ping(::grpc::ClientContext* context, const ::rpc::Empty& request, ::rpc::ErrReply* response) = 0; + std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::ErrReply>> AsyncPing(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::ErrReply>>(AsyncPingRaw(context, request, cq)); + } + virtual ::grpc::Status Kill(::grpc::ClientContext* context, const ::rpc::KillArg& request, ::rpc::ErrReply* response) = 0; + std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::ErrReply>> AsyncKill(::grpc::ClientContext* context, const ::rpc::KillArg& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::ErrReply>>(AsyncKillRaw(context, request, cq)); + } + virtual ::grpc::Status GetConfigPolicy(::grpc::ClientContext* context, const ::rpc::Empty& request, ::rpc::GetConfigPolicyReply* response) = 0; + std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::GetConfigPolicyReply>> AsyncGetConfigPolicy(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::rpc::GetConfigPolicyReply>>(AsyncGetConfigPolicyRaw(context, request, cq)); + } + private: + virtual ::grpc::ClientReaderWriterInterface< ::rpc::CollectArg, ::rpc::CollectReply>* StreamMetricsRaw(::grpc::ClientContext* context) = 0; + virtual ::grpc::ClientAsyncReaderWriterInterface< ::rpc::CollectArg, ::rpc::CollectReply>* AsyncStreamMetricsRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface< ::rpc::MetricsReply>* AsyncGetMetricTypesRaw(::grpc::ClientContext* context, const ::rpc::GetMetricTypesArg& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface< ::rpc::ErrReply>* AsyncPingRaw(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface< ::rpc::ErrReply>* AsyncKillRaw(::grpc::ClientContext* context, const ::rpc::KillArg& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface< ::rpc::GetConfigPolicyReply>* AsyncGetConfigPolicyRaw(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) = 0; + }; + class Stub GRPC_FINAL : public StubInterface { + public: + Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); + std::unique_ptr< ::grpc::ClientReaderWriter< ::rpc::CollectArg, ::rpc::CollectReply>> StreamMetrics(::grpc::ClientContext* context) { + return std::unique_ptr< ::grpc::ClientReaderWriter< ::rpc::CollectArg, ::rpc::CollectReply>>(StreamMetricsRaw(context)); + } + std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::rpc::CollectArg, ::rpc::CollectReply>> AsyncStreamMetrics(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::rpc::CollectArg, ::rpc::CollectReply>>(AsyncStreamMetricsRaw(context, cq, tag)); + } + ::grpc::Status GetMetricTypes(::grpc::ClientContext* context, const ::rpc::GetMetricTypesArg& request, ::rpc::MetricsReply* response) GRPC_OVERRIDE; + std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::MetricsReply>> AsyncGetMetricTypes(::grpc::ClientContext* context, const ::rpc::GetMetricTypesArg& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::MetricsReply>>(AsyncGetMetricTypesRaw(context, request, cq)); + } + ::grpc::Status Ping(::grpc::ClientContext* context, const ::rpc::Empty& request, ::rpc::ErrReply* response) GRPC_OVERRIDE; + std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::ErrReply>> AsyncPing(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::ErrReply>>(AsyncPingRaw(context, request, cq)); + } + ::grpc::Status Kill(::grpc::ClientContext* context, const ::rpc::KillArg& request, ::rpc::ErrReply* response) GRPC_OVERRIDE; + std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::ErrReply>> AsyncKill(::grpc::ClientContext* context, const ::rpc::KillArg& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::ErrReply>>(AsyncKillRaw(context, request, cq)); + } + ::grpc::Status GetConfigPolicy(::grpc::ClientContext* context, const ::rpc::Empty& request, ::rpc::GetConfigPolicyReply* response) GRPC_OVERRIDE; + std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::GetConfigPolicyReply>> AsyncGetConfigPolicy(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) { + return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::rpc::GetConfigPolicyReply>>(AsyncGetConfigPolicyRaw(context, request, cq)); + } + + private: + std::shared_ptr< ::grpc::ChannelInterface> channel_; + ::grpc::ClientReaderWriter< ::rpc::CollectArg, ::rpc::CollectReply>* StreamMetricsRaw(::grpc::ClientContext* context) GRPC_OVERRIDE; + ::grpc::ClientAsyncReaderWriter< ::rpc::CollectArg, ::rpc::CollectReply>* AsyncStreamMetricsRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE; + ::grpc::ClientAsyncResponseReader< ::rpc::MetricsReply>* AsyncGetMetricTypesRaw(::grpc::ClientContext* context, const ::rpc::GetMetricTypesArg& request, ::grpc::CompletionQueue* cq) GRPC_OVERRIDE; + ::grpc::ClientAsyncResponseReader< ::rpc::ErrReply>* AsyncPingRaw(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) GRPC_OVERRIDE; + ::grpc::ClientAsyncResponseReader< ::rpc::ErrReply>* AsyncKillRaw(::grpc::ClientContext* context, const ::rpc::KillArg& request, ::grpc::CompletionQueue* cq) GRPC_OVERRIDE; + ::grpc::ClientAsyncResponseReader< ::rpc::GetConfigPolicyReply>* AsyncGetConfigPolicyRaw(::grpc::ClientContext* context, const ::rpc::Empty& request, ::grpc::CompletionQueue* cq) GRPC_OVERRIDE; + const ::grpc::RpcMethod rpcmethod_StreamMetrics_; + const ::grpc::RpcMethod rpcmethod_GetMetricTypes_; + const ::grpc::RpcMethod rpcmethod_Ping_; + const ::grpc::RpcMethod rpcmethod_Kill_; + const ::grpc::RpcMethod rpcmethod_GetConfigPolicy_; + }; + static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); + + class Service : public ::grpc::Service { + public: + Service(); + virtual ~Service(); + virtual ::grpc::Status StreamMetrics(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::rpc::CollectReply, ::rpc::CollectArg>* stream); + virtual ::grpc::Status GetMetricTypes(::grpc::ServerContext* context, const ::rpc::GetMetricTypesArg* request, ::rpc::MetricsReply* response); + virtual ::grpc::Status Ping(::grpc::ServerContext* context, const ::rpc::Empty* request, ::rpc::ErrReply* response); + virtual ::grpc::Status Kill(::grpc::ServerContext* context, const ::rpc::KillArg* request, ::rpc::ErrReply* response); + virtual ::grpc::Status GetConfigPolicy(::grpc::ServerContext* context, const ::rpc::Empty* request, ::rpc::GetConfigPolicyReply* response); + }; + template + class WithAsyncMethod_StreamMetrics : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_StreamMetrics() { + ::grpc::Service::MarkMethodAsync(0); + } + ~WithAsyncMethod_StreamMetrics() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status StreamMetrics(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::rpc::CollectReply, ::rpc::CollectArg>* stream) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestStreamMetrics(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::rpc::CollectReply, ::rpc::CollectArg>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncBidiStreaming(0, context, stream, new_call_cq, notification_cq, tag); + } + }; + template + class WithAsyncMethod_GetMetricTypes : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_GetMetricTypes() { + ::grpc::Service::MarkMethodAsync(1); + } + ~WithAsyncMethod_GetMetricTypes() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status GetMetricTypes(::grpc::ServerContext* context, const ::rpc::GetMetricTypesArg* request, ::rpc::MetricsReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestGetMetricTypes(::grpc::ServerContext* context, ::rpc::GetMetricTypesArg* request, ::grpc::ServerAsyncResponseWriter< ::rpc::MetricsReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(1, context, request, response, new_call_cq, notification_cq, tag); + } + }; + template + class WithAsyncMethod_Ping : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_Ping() { + ::grpc::Service::MarkMethodAsync(2); + } + ~WithAsyncMethod_Ping() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status Ping(::grpc::ServerContext* context, const ::rpc::Empty* request, ::rpc::ErrReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestPing(::grpc::ServerContext* context, ::rpc::Empty* request, ::grpc::ServerAsyncResponseWriter< ::rpc::ErrReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(2, context, request, response, new_call_cq, notification_cq, tag); + } + }; + template + class WithAsyncMethod_Kill : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_Kill() { + ::grpc::Service::MarkMethodAsync(3); + } + ~WithAsyncMethod_Kill() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status Kill(::grpc::ServerContext* context, const ::rpc::KillArg* request, ::rpc::ErrReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestKill(::grpc::ServerContext* context, ::rpc::KillArg* request, ::grpc::ServerAsyncResponseWriter< ::rpc::ErrReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(3, context, request, response, new_call_cq, notification_cq, tag); + } + }; + template + class WithAsyncMethod_GetConfigPolicy : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithAsyncMethod_GetConfigPolicy() { + ::grpc::Service::MarkMethodAsync(4); + } + ~WithAsyncMethod_GetConfigPolicy() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status GetConfigPolicy(::grpc::ServerContext* context, const ::rpc::Empty* request, ::rpc::GetConfigPolicyReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestGetConfigPolicy(::grpc::ServerContext* context, ::rpc::Empty* request, ::grpc::ServerAsyncResponseWriter< ::rpc::GetConfigPolicyReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(4, context, request, response, new_call_cq, notification_cq, tag); + } + }; + typedef WithAsyncMethod_StreamMetrics > > > > AsyncService; + template + class WithGenericMethod_StreamMetrics : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_StreamMetrics() { + ::grpc::Service::MarkMethodGeneric(0); + } + ~WithGenericMethod_StreamMetrics() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status StreamMetrics(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::rpc::CollectReply, ::rpc::CollectArg>* stream) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template + class WithGenericMethod_GetMetricTypes : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_GetMetricTypes() { + ::grpc::Service::MarkMethodGeneric(1); + } + ~WithGenericMethod_GetMetricTypes() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status GetMetricTypes(::grpc::ServerContext* context, const ::rpc::GetMetricTypesArg* request, ::rpc::MetricsReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template + class WithGenericMethod_Ping : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_Ping() { + ::grpc::Service::MarkMethodGeneric(2); + } + ~WithGenericMethod_Ping() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status Ping(::grpc::ServerContext* context, const ::rpc::Empty* request, ::rpc::ErrReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template + class WithGenericMethod_Kill : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_Kill() { + ::grpc::Service::MarkMethodGeneric(3); + } + ~WithGenericMethod_Kill() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status Kill(::grpc::ServerContext* context, const ::rpc::KillArg* request, ::rpc::ErrReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; + template + class WithGenericMethod_GetConfigPolicy : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithGenericMethod_GetConfigPolicy() { + ::grpc::Service::MarkMethodGeneric(4); + } + ~WithGenericMethod_GetConfigPolicy() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status GetConfigPolicy(::grpc::ServerContext* context, const ::rpc::Empty* request, ::rpc::GetConfigPolicyReply* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + }; +}; + } // namespace rpc diff --git a/install_deps_centos.sh b/install_deps_centos.sh index 8979166..b81efc9 100755 --- a/install_deps_centos.sh +++ b/install_deps_centos.sh @@ -18,11 +18,9 @@ set -e mkdir -p lib -# export CC=/usr/bin/gcc -# export CXX=/usr/bin/g++ - -export CC=/opt/rh/devtoolset-3/root/usr/bin/gcc -export CXX=/opt/rh/devtoolset-3/root/usr/bin/g++ +export CC=/opt/rh/devtoolset-4/root/usr/bin/gcc +export CXX=/opt/rh/devtoolset-4/root/usr/bin/g++ +export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH gcc --version @@ -32,12 +30,22 @@ make SHARED=n cp libpqos.a ../../../lib/ popd +pushd `pwd` +cd ./third_party/googletest +cmake CMakeLists.txt +make -j2 +make install +cp googlemock/libgmock.a ../../lib +cp googlemock/gtest/libgtest.a ../../lib +popd + pushd `pwd` cd ./third_party/grpc git checkout tags/v1.0.1 git submodule update --init make -j2 make install + pushd `pwd` cd ./third_party/protobuf make clean @@ -49,14 +57,33 @@ popd popd pushd `pwd` -cd ./third_party/googletest -cmake CMakeLists.txt +cd ./third_party +wget -c 'http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2/download' +tar xf download +rm download +cd ./boost_1_58_0 +./bootstrap.sh --show-libraries +./bootstrap.sh +./b2 install --prefix=/usr -j2 +popd + +pushd `pwd` +cd ./third_party +git clone https://github.com/gabime/spdlog.git +cd ./spdlog +cp -r include/spdlog /usr/include/ +popd + +pushd `pwd` +cd ./third_party +wget http://downloads.cpp-netlib.org/0.11.2/cpp-netlib-0.11.2-final.tar.gz +tar xf cpp-netlib-0.11.2-final.tar.gz +rm cpp-netlib-0.11.2-final.tar.gz +cd cpp-netlib-0.11.2-final/ +cmake . make -j2 -make install -cp googlemock/libgmock.a ../../lib -cp googlemock/gtest/libgtest.a ../../lib +make install popd -echo PO GOOGLETEST pushd `pwd` cd ./third_party/snap-plugin-lib-cpp @@ -68,15 +95,7 @@ make install cp build/lib/libsnap.a ../../lib popd -pushd `pwd` -cd ./third_party -git clone https://github.com/square/certstrap -cd certstrap -./build -export PATH=$PATH:/opt/certstrap/bin -popd -popd - # /usr/local/lib is usually not in LD_LIBRARY_PATH #sudo cp /usr/local/lib/* /usr/lib -ldconfig -v \ No newline at end of file +export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib +ldconfig -v From 3ff254f5bf881fa240d7104d00934d60eb9df113 Mon Sep 17 00:00:00 2001 From: Rafal Borysionek Date: Tue, 19 Sep 2017 15:18:53 +0200 Subject: [PATCH 7/8] Added install script on Ubuntu --- .travis.yml | 2 +- Docker/Dockerfile.travis | 11 +-- Vagrant/Vagrantfile | 13 ++-- build.sh | 4 - include/snap/flags.h | 160 +++++++++++++++++++++++++++++++++++++++ install_deps_ubuntu.sh | 58 ++++++++++++++ 6 files changed, 228 insertions(+), 20 deletions(-) create mode 100644 include/snap/flags.h create mode 100755 install_deps_ubuntu.sh diff --git a/.travis.yml b/.travis.yml index 5e94418..434b4b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ install: - docker run -dt --name "worker-box" -e TEST_TYPE -e GTEST_ROOT -v ${TRAVIS_BUILD_DIR}/:/${TRAVIS_REPO_SLUG} for-worker-box bash script: - docker exec -ti worker-box bash -c "cd /${TRAVIS_REPO_SLUG} && git submodule update --init" - - docker exec -ti worker-box bash -c "cd /${TRAVIS_REPO_SLUG} && ./install_deps_centos.sh" + - docker exec -ti worker-box bash -c "cd /${TRAVIS_REPO_SLUG} && ./install_deps_ubuntu.sh" - docker exec -ti worker-box bash -c "cd /${TRAVIS_REPO_SLUG} && ./test.sh" after_script: - docker rm -fv worker-box diff --git a/Docker/Dockerfile.travis b/Docker/Dockerfile.travis index fe00ac2..cdd2bc3 100644 --- a/Docker/Dockerfile.travis +++ b/Docker/Dockerfile.travis @@ -15,10 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM centos:7 -RUN yum update -y -RUN yum groupinstall -y base -RUN yum install -y git cmake mc tmux autoconf automake python-devel libtool zlib-devel openssl-devel curl make unzip wget golang clang bzip2-devel gcc-c++ protobuf-compiler libprotobuf-dev libprotoc-dev centos-release-scl-rh -RUN yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++ -RUN scl enable devtoolset-4 bash -RUN export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH \ No newline at end of file +FROM ubuntu:xenial + +RUN apt-get update && apt-get upgrade -yq +RUN apt-get install g++-4.9 gcc-4.9 protobuf-compiler libprotobuf-dev libprotoc-dev libboost-dev libcppnetlib-dev libspdlog-dev git curl cmake golang-go autoconf libtool ca-certificates unzip software-properties-common golang-go -yq \ No newline at end of file diff --git a/Vagrant/Vagrantfile b/Vagrant/Vagrantfile index 17a1d64..45c4e7f 100644 --- a/Vagrant/Vagrantfile +++ b/Vagrant/Vagrantfile @@ -13,7 +13,7 @@ Vagrant.configure("2") do |config| # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. - config.vm.box = "centos/7" + config.vm.box = "ubuntu/xenial64" config.vm.synced_folder "..", "/home/vagrant/snap-plugin-collector-rdt", :mount_options => ["umask=0022,dmask=0022,fmask=0022"] @@ -79,14 +79,11 @@ Vagrant.configure("2") do |config| # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. config.vm.provision "shell", inline: <<-SHELL - sudo yum update -y - sudo yum install -y git cmake mc tmux autoconf automake libtool zlib-devel openssl-devel curl make unzip wget golang clang gcc-c++ protobuf-compiler libprotobuf-dev libprotoc-dev centos-release-scl-rh - sudo yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++ - sudo scl enable devtoolset-4 bash - export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH - cd snap-plugin-collector-rdt + sudo apt-get update && sudo apt-get upgrade -yq + sudo apt-get install g++-4.9 gcc-4.9 protobuf-compiler libprotobuf-dev libprotoc-dev libboost-dev libcppnetlib-dev libspdlog-dev git curl cmake golang-go autoconf libtool ca-certificates unzip software-properties-common golang-go -yq + cd /home/vagrant/snap-plugin-collector-rdt git submodule update --init - ./install_deps_centos.sh + ./install_deps_ubuntu.sh ./build.sh SHELL end \ No newline at end of file diff --git a/build.sh b/build.sh index fdfdd51..424e065 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,5 @@ #!/usr/bin/env bash -export CC=/opt/rh/devtoolset-4/root/usr/bin/gcc -export CXX=/opt/rh/devtoolset-4/root/usr/bin/g++ -export PATH=/opt/rh/devtoolset-4/root/usr/bin/:$PATH -gcc --version mkdir -p build cd build cmake .. diff --git a/include/snap/flags.h b/include/snap/flags.h new file mode 100644 index 0000000..46780d9 --- /dev/null +++ b/include/snap/flags.h @@ -0,0 +1,160 @@ +/* +http://www.apache.org/licenses/LICENSE-2.0.txt +Copyright 2017 Intel Corporation +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + + +#define COMMAND_DESC "COMMANDS" +#define GLOBAL_DESC "GLOBAL OPTIONS" +#define ADDITIONAL_DESC "" + +namespace po = boost::program_options; +namespace spd = spdlog; + +using namespace std; + + +namespace Plugin { + //helper function to simplify main part + template + ostream& operator<<(ostream& os, const vector& v) { + copy(v.begin(), v.end(), ostream_iterator(os, " ")); + return os; + }; + + class Flags { + private: + std::shared_ptr _logger; + + po::variables_map _flags; + + // Initial option descriptions + po::options_description _command{COMMAND_DESC}, _global{GLOBAL_DESC}; + po::options_description _hidden, _additional{ADDITIONAL_DESC}; + + // Combined option descriptions + po::options_description _visible, _command_line, _config_file; + + // Default variables + int _log_level, _stand_alone_port, _max_collect_duration; + std::string _options_file, _listen_port, _listen_addr, _cert_path, _key_path, _root_cert_paths; + int64_t _max_metrics_buffer; + + bool _framework_json_parsed; + + public: + enum FlagType { + Bool, + Int, + String + }; + + enum FlagLevel { + Command, + Global, + Hidden, + Custom + }; + + Flags() { + _logger = spdlog::stderr_logger_mt("flags"); + } + + Flags(const int &argc, char **argv) : + _framework_json_parsed(false) { + std::string logger_name = argc > 0 ? "flags_" + std::string(argv[0]) : "flags"; + _logger = spdlog::stderr_logger_mt(logger_name); + this->SetFlags(); + this->ParseFlags(argc, argv); + } + + int addDefaultCommandFlags(); + int addDefaultGlobalFlags(); + int addDefaultHiddenFlags(); + int SetDefaultFlags(); + + int addBoolFlag(const char *optionName, const char *description, + FlagLevel flagLevel); + int addIntFlag(const char *optionName, const char *description, + FlagLevel flagLevel); + int addStringFlag(const char *optionName, const char *description, + FlagLevel flagLevel); + int AddFlag(const char *optionName, const char *description, + FlagType flagType, FlagLevel flagLevel); + + int setVisibleFlags(); + int setCommandLineFlags(); + int setConfigFileFlags(); + int SetCombinedFlags(); + + int SetFlags() { + if (SetDefaultFlags() != 0) return 1; + if (SetCombinedFlags() != 0) return 1; + return 0; + } + + int parseCommandLineFlags(const int &argc, char **argv); + int parsejsonFlags(const int &argc, char **argv); + int parseConfigFileFlags(std::string filePathAndName = ""); + int ParseFlags(const int &argc, char **argv, std::string filePathAndName = ""); + + + void ShowVariablesMap(); + bool IsParsedFlag(const char *flagKey) { return _flags.count(flagKey); } + po::variables_map GetFlagsVM() { return _flags; } + const bool IsConfigFromFramework() const {return _framework_json_parsed; } + + bool GetFlagBoolValue(const char *flagKey); + int GetFlagIntValue(const char *flagKey); + int64_t GetFlagInt64Value(const char *flagKey); + std::string GetFlagStrValue(const char *flagKey); + + void SetFlagsLogLevel(const int &logLevel = 2); + + int helpFlagCalled() { + std::cout << _visible << std::endl; + return 0; + } + + po::options_description GetCommandOptions() { return _command; } + void PrintCommandOptions() { std::cout << _command << std::endl; } + + po::options_description GetGlobalOptions() { return _global; } + void PrintGlobalOptions() { std::cout << _global << std::endl; } + + po::options_description GetHiddenOptions() { return _hidden; } + void PrintHiddenOptions() { std::cout << _hidden << std::endl; } + + po::options_description GetAdditionalOptions() { return _additional; } + void PrintAdditionalOptions() { std::cout << _additional << std::endl; } + + po::options_description GetVisibleOptions() { return _visible; } + void PrintVisibleOptions() { std::cout << _visible << std::endl; } + + po::options_description GetCommandLineOptions() { return _command_line; } + void PrintCommandLineOptions() { std::cout << _command_line << std::endl; } + + po::options_description GetConfigFileOptions() { return _config_file; } + void PrintConfigFileOptions() { std::cout << _config_file << std::endl; } + + const rpc::ConfigMap GenerateConfigMapFromCommandJson(); + }; +} // namespace Plugin diff --git a/install_deps_ubuntu.sh b/install_deps_ubuntu.sh new file mode 100755 index 0000000..9517a28 --- /dev/null +++ b/install_deps_ubuntu.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# Copyright (c) 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +pushd `pwd` +cd third_party/intel-cmt-cat/lib/ +make SHARED=n +cp libpqos.a ../../../lib/ +popd + +pushd `pwd` +cd ./third_party/googletest +cmake CMakeLists.txt +make -j2 +make install +cp googlemock/libgmock.a ../../lib +cp googlemock/gtest/libgtest.a ../../lib +popd + +pushd `pwd` +cd ./third_party/grpc +git checkout tags/v1.0.1 +git submodule update --init +make -j2 +make install + +pushd `pwd` +cd ./third_party/protobuf +make clean +./autogen.sh +./configure +make -j2 +make install +popd +popd + +pushd `pwd` +cd ./third_party/snap-plugin-lib-cpp +mkdir -p build +./autogen.sh +./configure -prefix=`pwd`/build +make -j2 +make install +cp build/lib/libsnap.a ../../lib +popd + +ldconfig -v \ No newline at end of file From 1dcd5147f9121603c22fa23de15e77405692d7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borysionek?= Date: Wed, 27 Sep 2017 12:32:17 +0200 Subject: [PATCH 8/8] Update install_deps_ubuntu.sh --- install_deps_ubuntu.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install_deps_ubuntu.sh b/install_deps_ubuntu.sh index 9517a28..37732f5 100755 --- a/install_deps_ubuntu.sh +++ b/install_deps_ubuntu.sh @@ -26,6 +26,7 @@ make -j2 make install cp googlemock/libgmock.a ../../lib cp googlemock/gtest/libgtest.a ../../lib +cp googlemock/gtest/libgtest.a /usr/lib popd pushd `pwd` @@ -55,4 +56,4 @@ make install cp build/lib/libsnap.a ../../lib popd -ldconfig -v \ No newline at end of file +ldconfig -v