diff options
author | Arne Juul <arnej@yahoo-inc.com> | 2017-11-07 15:09:37 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahoo-inc.com> | 2017-11-21 12:59:23 +0000 |
commit | 2ccc391e1aa9bd190d1d40dcd1c01cf85fe5a5c6 (patch) | |
tree | f596b2e946fec6f7fe30f3acf60c6fecda86e97a /logd | |
parent | 1b245f10e77b4aac6ac0197b1654815ccdc961c7 (diff) |
skeleton for state reporting in logd
* allocate port in config model for logd state reporting
* add state port to logd configuration
* add a state server with no metrics production
Diffstat (limited to 'logd')
-rw-r--r-- | logd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | logd/src/apps/logd/main.cpp | 8 | ||||
-rw-r--r-- | logd/src/logd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | logd/src/logd/conf.cpp | 3 | ||||
-rw-r--r-- | logd/src/logd/conf.h | 3 | ||||
-rw-r--r-- | logd/src/logd/state.cpp | 31 | ||||
-rw-r--r-- | logd/src/logd/state.h | 24 | ||||
-rw-r--r-- | logd/src/main/resources/configdefinitions/logd.def | 3 |
8 files changed, 71 insertions, 3 deletions
diff --git a/logd/CMakeLists.txt b/logd/CMakeLists.txt index 53309ef3dd8..3eeeb7adb66 100644 --- a/logd/CMakeLists.txt +++ b/logd/CMakeLists.txt @@ -4,6 +4,7 @@ vespa_define_module( fastos vespalog vespalib + staging_vespalib config_cloudconfig APPS diff --git a/logd/src/apps/logd/main.cpp b/logd/src/apps/logd/main.cpp index 00654060107..70df928dfd2 100644 --- a/logd/src/apps/logd/main.cpp +++ b/logd/src/apps/logd/main.cpp @@ -5,6 +5,7 @@ #include <logd/forward.h> #include <logd/conf.h> #include <logd/watch.h> +#include <logd/state.h> #include <vespa/config/common/exceptions.h> #include <csignal> #include <unistd.h> @@ -29,9 +30,8 @@ int main(int, char**) const char *cfid = getenv("VESPA_CONFIG_ID"); try { - std::unique_ptr<ConfSub> subscriberP; - subscriberP.reset(new ConfSub(fwd, config::ConfigUri(cfid))); - ConfSub & subscriber(*subscriberP); + ConfSub subscriber(fwd, config::ConfigUri(cfid)); + StateReporter stateReporter; int sleepcount = 0; while (true) { @@ -39,6 +39,8 @@ int main(int, char**) try { subscriber.latch(); + stateReporter.setStatePort(subscriber.getStatePort()); + stateReporter.gotConf(subscriber.generation()); int fd = subscriber.getservfd(); if (fd >= 0) { sleepcount = 0 ; // connection OK, reset sleep time diff --git a/logd/src/logd/CMakeLists.txt b/logd/src/logd/CMakeLists.txt index b436ef52876..3ef48f9255a 100644 --- a/logd/src/logd/CMakeLists.txt +++ b/logd/src/logd/CMakeLists.txt @@ -8,6 +8,7 @@ vespa_add_library(logd STATIC service.cpp cmdbuf.cpp perform.cpp + state.cpp DEPENDS ) vespa_generate_config(logd ../main/resources/configdefinitions/logd.def) diff --git a/logd/src/logd/conf.cpp b/logd/src/logd/conf.cpp index 8a53317c286..716ba97effd 100644 --- a/logd/src/logd/conf.cpp +++ b/logd/src/logd/conf.cpp @@ -42,6 +42,8 @@ ConfSub::configure(std::unique_ptr<LogdConfig> cfg) _use_logserver = newconf.logserver.use; _newConf = true; } + _statePort = newconf.stateport; + ForwardMap forwardMap; forwardMap[Logger::fatal] = newconf.loglevel.fatal.forward; forwardMap[Logger::error] = newconf.loglevel.error.forward; @@ -145,6 +147,7 @@ ConfSub::closeConn() ConfSub::ConfSub(Forwarder &fw, const config::ConfigUri & configUri) : _logPort(0), _logserverfd(-1), + _statePort(0), _rotate_size(INT_MAX), _rotate_age(INT_MAX), _remove_meg(INT_MAX), diff --git a/logd/src/logd/conf.h b/logd/src/logd/conf.h index ce135d153cd..7a91630ff93 100644 --- a/logd/src/logd/conf.h +++ b/logd/src/logd/conf.h @@ -10,6 +10,7 @@ private: char _logServer[256]; int _logPort; int _logserverfd; + int _statePort; int _rotate_size; int _rotate_age; int _remove_meg; @@ -31,6 +32,7 @@ public: ConfSub(Forwarder &fw, const config::ConfigUri & configUri); ~ConfSub(); + int getStatePort() const { return _statePort; } int getservfd() const { return _logserverfd; } int getRotateSize() const { return _rotate_size; } int getRotateAge() const { return _rotate_age; } @@ -39,6 +41,7 @@ public: bool useLogserver() const { return _use_logserver; } void configure(std::unique_ptr<cloud::config::log::LogdConfig> cfg); + size_t generation() const { return _subscriber.getGeneration(); } }; } // namespace diff --git a/logd/src/logd/state.cpp b/logd/src/logd/state.cpp new file mode 100644 index 00000000000..b73183d5987 --- /dev/null +++ b/logd/src/logd/state.cpp @@ -0,0 +1,31 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/log/log.h> +LOG_SETUP(""); + +#include "state.h" + +namespace logdemon { + +StateReporter::StateReporter() +{ +} + +void +StateReporter::setStatePort(int statePort) +{ + if (statePort != _port) { + _port = statePort; + _server.reset(new vespalib::StateServer(_port, _health, _metrics, _components)); + LOG(info, "state server listening on port %d", _server->getListenPort()); + } +} + +void +StateReporter::gotConf(size_t generation) +{ + vespalib::ComponentConfigProducer::Config conf("logd", generation); + _components.addConfig(conf); +} + +} // namespace diff --git a/logd/src/logd/state.h b/logd/src/logd/state.h new file mode 100644 index 00000000000..7abcc7eb93c --- /dev/null +++ b/logd/src/logd/state.h @@ -0,0 +1,24 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/vespalib/net/state_server.h> +#include <vespa/vespalib/net/simple_health_producer.h> +#include <vespa/vespalib/net/simple_metrics_producer.h> +#include <vespa/vespalib/net/simple_component_config_producer.h> +#include <vespa/vespalib/net/generic_state_handler.h> + +namespace logdemon { + +class StateReporter { + int _port; + std::unique_ptr<vespalib::StateServer> _server; + vespalib::SimpleHealthProducer _health; + vespalib::SimpleMetricsProducer _metrics; + vespalib::SimpleComponentConfigProducer _components; +public: + StateReporter(); + void setStatePort(int statePort); + void gotConf(size_t generation); +}; + +} // namespace diff --git a/logd/src/main/resources/configdefinitions/logd.def b/logd/src/main/resources/configdefinitions/logd.def index 96c6bf5a616..7f7e69d3260 100644 --- a/logd/src/main/resources/configdefinitions/logd.def +++ b/logd/src/main/resources/configdefinitions/logd.def @@ -1,6 +1,9 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. namespace=cloud.config.log +## Port to serve status and metrics on +stateport int default=0 + ## Host to contact the logserver on. logserver.host string default="localhost" |