Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Docker/Dockerfile.travis
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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 libtool curl make unzip wget clang gcc-c++
FROM ubuntu:xenial

RUN apt-get update && apt-get upgrade -yq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove double spaces

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang-go two times

12 changes: 6 additions & 6 deletions Vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -79,11 +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 curl make unzip wget clang gcc-c++
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang-go two times

cd /home/vagrant/snap-plugin-collector-rdt
git submodule update --init
./install_deps_centos.sh
./install_deps_ubuntu.sh
./build.sh
SHELL
end
end
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

mkdir -p build
cd build
cmake ..
Expand Down
296 changes: 155 additions & 141 deletions include/snap/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,145 +19,159 @@ limitations under the License.
#include <snap/rpc/plugin.pb.h>

namespace Plugin {

template<class P, class R, typename T> class Rule;

/**
* A Rule of type std::string
*/
typedef Rule<rpc::StringPolicy, rpc::StringRule, std::string> StringRule;

/**
* A Rule of type int
*/
typedef Rule<rpc::IntegerPolicy, rpc::IntegerRule, int> IntRule;

/**
* A Rule of type bool
*/
typedef Rule<rpc::BoolPolicy, rpc::BoolRule, bool> 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 P, class R, typename T>
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<std::string>& ns, const StringRule& rule);
void add_rule(const std::vector<std::string>& ns, const IntRule& rule);
void add_rule(const std::vector<std::string>& 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 P, class R, typename T> class Rule;

/**
* A Rule of type std::string
*/
typedef Rule<rpc::StringPolicy, rpc::StringRule, std::string> StringRule;

/**
* A Rule of type int
*/
typedef Rule<rpc::IntegerPolicy, rpc::IntegerRule, int> IntRule;

/**
* A Rule of type bool
*/
typedef Rule<rpc::BoolPolicy, rpc::BoolRule, bool> 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 P, class R, typename T>
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<std::string>& ns, const StringRule& rule);
void add_rule(const std::vector<std::string>& ns, const IntRule& rule);
void add_rule(const std::vector<std::string>& 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
Loading