summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-05-27 13:34:53 +0000
committerArne Juul <arnej@verizonmedia.com>2021-05-27 13:51:13 +0000
commite6832404fb93af477d8f3829d7258827d6280a8a (patch)
treefe9e020cbc61f65c840cf4b703a4d37941b27821 /configd
parent855c5b2ab689fa15ab6f8e9512d36d691ff3bfed (diff)
add environment class that can live outside manager
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/CMakeLists.txt13
-rw-r--r--configd/src/apps/sentinel/config-owner.cpp2
-rw-r--r--configd/src/apps/sentinel/env.cpp84
-rw-r--r--configd/src/apps/sentinel/env.h44
4 files changed, 136 insertions, 7 deletions
diff --git a/configd/src/apps/sentinel/CMakeLists.txt b/configd/src/apps/sentinel/CMakeLists.txt
index b20aa4e190a..f6b4c3a2184 100644
--- a/configd/src/apps/sentinel/CMakeLists.txt
+++ b/configd/src/apps/sentinel/CMakeLists.txt
@@ -1,17 +1,18 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_executable(configd_config-sentinel_app
SOURCES
+ cmdq.cpp
config-owner.cpp
- sentinel.cpp
- service.cpp
- manager.cpp
+ env.cpp
line-splitter.cpp
- output-connection.cpp
+ manager.cpp
metrics.cpp
- state-api.cpp
- cmdq.cpp
+ output-connection.cpp
rpchooks.cpp
rpcserver.cpp
+ sentinel.cpp
+ service.cpp
+ state-api.cpp
OUTPUT_NAME vespa-config-sentinel
INSTALL sbin
DEPENDS
diff --git a/configd/src/apps/sentinel/config-owner.cpp b/configd/src/apps/sentinel/config-owner.cpp
index f4ea76855f6..3feec70d2e5 100644
--- a/configd/src/apps/sentinel/config-owner.cpp
+++ b/configd/src/apps/sentinel/config-owner.cpp
@@ -26,7 +26,7 @@ ConfigOwner::doConfigure()
_currGeneration = _subscriber.getGeneration();
const SentinelConfig& config(*_currConfig);
const auto & app = config.application;
- LOG(info, "ConfigOwner got %zd service elements [tenant(%s), application(%s), instance(%s)] for config generation %zd",
+ LOG(config, "Sentinel got %zd service elements [tenant(%s), application(%s), instance(%s)] for config generation %zd",
config.service.size(), app.tenant.c_str(), app.name.c_str(), app.instance.c_str(), _currGeneration);
}
diff --git a/configd/src/apps/sentinel/env.cpp b/configd/src/apps/sentinel/env.cpp
new file mode 100644
index 00000000000..02df292a423
--- /dev/null
+++ b/configd/src/apps/sentinel/env.cpp
@@ -0,0 +1,84 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "env.h"
+#include <vespa/log/log.h>
+#include <vespa/config/common/exceptions.h>
+#include <vespa/vespalib/util/exceptions.h>
+#include <thread>
+#include <chrono>
+
+LOG_SETUP(".env");
+
+namespace config::sentinel {
+
+constexpr std::chrono::milliseconds CONFIG_TIMEOUT_MS(3 * 60 * 1000);
+
+Env::Env()
+ : _cfgOwner(),
+ _rpcCommandQueue(),
+ _rpcServer(),
+ _stateApi(),
+ _startMetrics(),
+ _stateServer(),
+ _statePort(0)
+{
+ _startMetrics.startedTime = vespalib::steady_clock::now();
+}
+
+Env::~Env() = default;
+
+void Env::boot(const std::string &configId) {
+ LOG(debug, "Reading configuration for ID: %s", configId.c_str());
+ _cfgOwner.subscribe(configId, CONFIG_TIMEOUT_MS);
+ if (_cfgOwner.checkForConfigUpdate()) {
+ LOG_ASSERT(_cfgOwner.hasConfig());
+ } else {
+ throw InvalidConfigException("checkForConfigUpdate() failed");
+ }
+ const auto & cfg = _cfgOwner.getConfig();
+ LOG(config, "Booting sentinel '%s' with [stateserver port %d] and [rpc port %d]",
+ configId.c_str(), cfg.port.telnet, cfg.port.rpc);
+ rpcPort(cfg.port.rpc);
+ statePort(cfg.port.telnet);
+}
+
+void Env::rpcPort(int port) {
+ if (port < 0 || port > 65535) {
+ throw vespalib::FatalException("Bad port " + std::to_string(port) + ", expected range [1, 65535]", VESPA_STRLOC);
+ }
+ if (port == 0) {
+ port = 19097; // default in config
+ }
+ if (_rpcServer && port == _rpcServer->getPort()) {
+ return; // ok already
+ }
+ _rpcServer = std::make_unique<RpcServer>(port, _rpcCommandQueue);
+}
+
+void Env::statePort(int port) {
+ if (port < 0 || port > 65535) {
+ throw vespalib::FatalException("Bad port " + std::to_string(port) + ", expected range [1, 65535]", VESPA_STRLOC);
+ }
+ if (port == 0) {
+ port = 19098;
+ const char *portString = getenv("VESPA_SENTINEL_PORT");
+ if (portString) {
+ port = strtoul(portString, nullptr, 10);
+ }
+ }
+ if (_stateServer && port == _statePort) {
+ return; // ok already
+ }
+ LOG(debug, "Config-sentinel accepts connections on port %d", port);
+ _stateServer = std::make_unique<vespalib::StateServer>(
+ port, _stateApi.myHealth, _startMetrics.producer, _stateApi.myComponents);
+ _statePort = port;
+}
+
+void Env::notifyConfigUpdated() {
+ vespalib::ComponentConfigProducer::Config current("sentinel", _cfgOwner.getGeneration(), "ok");
+ _stateApi.myComponents.addConfig(current);
+
+}
+
+}
diff --git a/configd/src/apps/sentinel/env.h b/configd/src/apps/sentinel/env.h
new file mode 100644
index 00000000000..da04a328c41
--- /dev/null
+++ b/configd/src/apps/sentinel/env.h
@@ -0,0 +1,44 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "cmdq.h"
+#include "config-owner.h"
+#include "metrics.h"
+#include "rpcserver.h"
+#include "state-api.h"
+#include <vespa/vespalib/net/state_server.h>
+
+namespace config::sentinel {
+
+/**
+ * Environment for config sentinel, with config
+ * subscription, rpc server, state server, and
+ * metrics.
+ **/
+class Env {
+public:
+ Env();
+ ~Env();
+
+ ConfigOwner &configOwner() { return _cfgOwner; }
+ CommandQueue &commandQueue() { return _rpcCommandQueue; }
+ StartMetrics &metrics() { return _startMetrics; }
+
+ void boot(const std::string &configId);
+ void rpcPort(int portnum);
+ void statePort(int portnum);
+
+ void notifyConfigUpdated();
+
+private:
+ ConfigOwner _cfgOwner;
+ CommandQueue _rpcCommandQueue;
+ std::unique_ptr<RpcServer> _rpcServer;
+ StateApi _stateApi;
+ StartMetrics _startMetrics;
+ std::unique_ptr<vespalib::StateServer> _stateServer;
+ int _statePort;
+};
+
+}