]> granicus.if.org Git - icinga2/commitdiff
Fix that MaxConcurrentChecks constant is overridden from 'checker' feature 7121/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Mon, 15 Apr 2019 14:56:30 +0000 (16:56 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 16 Apr 2019 13:04:57 +0000 (15:04 +0200)
Note: This drops the deprecated concurrent_checks setting from the checker feature
entirely and refactors the underlaying code handling.

Also affects ReloadTimeout which is new for 2.11.

fixes #7111

15 files changed:
doc/09-object-types.md
doc/12-icinga2-api.md
doc/16-upgrading-icinga-2.md
icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.hpp
lib/base/configuration.cpp
lib/base/configuration.hpp
lib/base/configuration.ti
lib/checker/checkercomponent.cpp
lib/checker/checkercomponent.ti
lib/icinga/clusterevents-check.cpp
lib/icinga/icingaapplication.cpp
lib/icinga/icingaapplication.hpp
lib/remote/configpackageutility.cpp

index 2e3ceaf7e6903e8bc06e47a45c477f3b5478a2bb..dbca5fefe7eb34a2c739fe9ea6a8f6f8c599c45e 100644 (file)
@@ -1156,7 +1156,7 @@ requires to use `cipher_list` compatible with the endpoint using the oldest vers
 other tools to connect to the API ensure also compatibility with them as this setting affects not only inter-cluster
 communcation but also the REST API.
 
-### CheckerComponent <a id="objecttype-checkcomponent"></a>
+### CheckerComponent <a id="objecttype-checkercomponent"></a>
 
 The checker component is responsible for scheduling active checks.
 This configuration object is available as [checker feature](11-cli-commands.md#cli-command-feature).
@@ -1167,11 +1167,10 @@ Example:
 object CheckerComponent "checker" { }
 ```
 
-Configuration Attributes:
-
-  Name                      | Type                  | Description
-  --------------------------|-----------------------|----------------------------------
-  concurrent\_checks        | Number                | **Optional and deprecated.** The maximum number of concurrent checks. Was replaced by global constant `MaxConcurrentChecks` which will be set if you still use `concurrent_checks`.
+In order to limit the concurrent checks on a master/satellite endpoint,
+use [MaxConcurrentChecks](17-language-reference.md#icinga-constants-global-config) constant.
+This also applies to an agent as command endpoint where the checker
+feature is disabled.
 
 ### CheckResultReader <a id="objecttype-checkresultreader"></a>
 
index 0984fb6beef6b3e4fc3abb155393932f0c9d34e8..9fbc7965bca4a050c7783111e674cd77d476e387 100644 (file)
@@ -2215,11 +2215,11 @@ and developers have been working hard to add more REST API
 clients and integrations into DevOps tools.
 
 * [Libraries](12-icinga2-api.md#icinga2-api-clients-libraries)
-* [Status](#icinga2-api-clients-status)
-* [Management](#icinga2-api-clients-management)
-* [Event Streams](#icinga2-api-clients-event-streams)
-* [Actions](#icinga2-api-clients-actions)
-* [REST API Apps](#icinga2-api-clients-apps)
+* [Status](12-icinga2-api.md#icinga2-api-clients-status)
+* [Management](12-icinga2-api.md#icinga2-api-clients-management)
+* [Event Streams](12-icinga2-api.md#icinga2-api-clients-event-streams)
+* [Actions](12-icinga2-api.md#icinga2-api-clients-actions)
+* [REST API Apps](12-icinga2-api.md#icinga2-api-clients-apps)
 
 Additional [programmatic examples](12-icinga2-api.md#icinga2-api-clients-programmatic-examples)
 will help you getting started using the Icinga 2 API in your environment.
index 8f7d6895ab62acfce64477a4321038e5cd7ecf99..665f41b232757057fb0bddb997a158a4d56851b6 100644 (file)
@@ -96,6 +96,12 @@ user has the capabilities to change to a different user.
 If you still encounter problems, run the aforementioned CLI commands as root,
 or with sudo.
 
+### Configuration <a id="upgrading-to-2-11-configuration"></a>
+
+The deprecated `concurrent_checks` attribute in the [checker feature](09-object-types.md#objecttype-checkercomponent)
+has no effect anymore if set. Please use the [MaxConcurrentChecks](17-language-reference.md#icinga-constants-global-config)
+constant in [constants.conf](04-configuring-icinga-2.md#constants-conf) instead.
+
 ## Upgrading to v2.10 <a id="upgrading-to-2-10"></a>
 
 ### Path Constant Changes <a id="upgrading-to-2-10-path-constant-changes"></a>
index e6a361dc5ac540c0c3875493e56a511add582d76..5d3e3165e4091b46d84317143b7cb3b65d03e59b 100644 (file)
@@ -282,8 +282,7 @@ static int Main()
 #endif /* RLIMIT_STACK */
        }
 
-       ScriptGlobal::Set("MaxConcurrentChecks", Application::GetDefaultMaxConcurrentChecks());
-
+       /* Calculate additional global constants. */
        ScriptGlobal::Set("System.PlatformKernel", Utility::GetPlatformKernel(), true);
        ScriptGlobal::Set("System.PlatformKernelVersion", Utility::GetPlatformKernelVersion(), true);
        ScriptGlobal::Set("System.PlatformName", Utility::GetPlatformName(), true);
index 1e7cd5d42a74c54c8ca4db45f8dfa2755e96aef1..57ca8688fb332cae2f96abb7dc890ae088af1be7 100644 (file)
@@ -60,14 +60,6 @@ void Application::OnConfigLoaded()
 
        ASSERT(m_Instance == nullptr);
        m_Instance = this;
-
-       String reloadTimeout;
-
-       if (ScriptGlobal::Exists("ReloadTimeout"))
-               reloadTimeout = ScriptGlobal::Get("ReloadTimeout");
-
-       if (!reloadTimeout.IsEmpty())
-               Configuration::ReloadTimeout = Convert::ToDouble(reloadTimeout);
 }
 
 /**
@@ -406,14 +398,16 @@ pid_t Application::StartReloadProcess()
        args.push_back("--validate");
 #endif /* _WIN32 */
 
+       double reloadTimeout = Application::GetReloadTimeout();
+
        Process::Ptr process = new Process(Process::PrepareCommand(new Array(std::move(args))));
-       process->SetTimeout(Configuration::ReloadTimeout);
+       process->SetTimeout(reloadTimeout);
        process->Run(&ReloadProcessCallback);
 
        Log(LogInformation, "Application")
                << "Got reload command: Started new instance with PID '"
                << (unsigned long)(process->GetPID()) << "' (timeout is "
-               << Configuration::ReloadTimeout << "s).";
+               << reloadTimeout << "s).";
 
        return process->GetPID();
 }
@@ -1179,35 +1173,9 @@ int Application::GetDefaultRLimitStack()
        return 256 * 1024;
 }
 
-/**
- * Sets the max concurrent checks.
- *
- * @param maxChecks The new limit.
- */
-void Application::SetMaxConcurrentChecks(int maxChecks)
-{
-       ScriptGlobal::Set("MaxConcurrentChecks", maxChecks, true);
-}
-
-/**
- * Retrieves the max concurrent checks.
- *
- * @returns The max number of concurrent checks.
- */
-int Application::GetMaxConcurrentChecks()
-{
-       Value defaultMaxConcurrentChecks = GetDefaultMaxConcurrentChecks();
-       return ScriptGlobal::Get("MaxConcurrentChecks", &defaultMaxConcurrentChecks);
-}
-
-/**
- * Retrieves the default value for max concurrent checks.
- *
- * @returns The default max number of concurrent checks.
- */
-int Application::GetDefaultMaxConcurrentChecks()
+double Application::GetReloadTimeout()
 {
-       return 512;
+       return ScriptGlobal::Get("ReloadTimeout");
 }
 
 /**
index e612502eddedba104a2f5688d0d3d0217a76bf18..ceab4441ef3d272e3a994bc91d95748c4817426f 100644 (file)
@@ -77,9 +77,7 @@ public:
        static int GetDefaultRLimitProcesses();
        static int GetDefaultRLimitStack();
 
-       static int GetMaxConcurrentChecks();
-       static int GetDefaultMaxConcurrentChecks();
-       static void SetMaxConcurrentChecks(int maxChecks);
+       static double GetReloadTimeout();
 
        static ThreadPool& GetTP();
 
index 4ef31fb1e5fd76d939bc49c2246603958d148343..d163937e2a7b953a6ee520cc60d06f078a5c57ed 100644 (file)
@@ -25,7 +25,6 @@ String Configuration::PidPath;
 String Configuration::PkgDataDir;
 String Configuration::PrefixDir;
 String Configuration::ProgramData;
-double Configuration::ReloadTimeout{300};
 int Configuration::RLimitFiles;
 int Configuration::RLimitProcesses;
 int Configuration::RLimitStack;
@@ -224,16 +223,6 @@ void Configuration::SetProgramData(const String& val, bool suppress_events, cons
        HandleUserWrite("ProgramData", &Configuration::ProgramData, val, m_ReadOnly);
 }
 
-double Configuration::GetReloadTimeout() const
-{
-       return Configuration::ReloadTimeout;
-}
-
-void Configuration::SetReloadTimeout(double val, bool suppress_events, const Value& cookie)
-{
-       HandleUserWrite("ReloadTimeout", &Configuration::ReloadTimeout, val, m_ReadOnly);
-}
-
 int Configuration::GetRLimitFiles() const
 {
        return Configuration::RLimitFiles;
index 69781454d52792e25f2c1f20a3e56e8a6cbbb837..560906596ccdcc0d8ec2500a19aeb20ca7686bc7 100644 (file)
@@ -70,9 +70,6 @@ public:
        String GetProgramData() const override;
        void SetProgramData(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
 
-       double GetReloadTimeout() const override;
-       void SetReloadTimeout(double value, bool suppress_events = false, const Value& cookie = Empty) override;
-
        int GetRLimitFiles() const override;
        void SetRLimitFiles(int value, bool suppress_events = false, const Value& cookie = Empty) override;
 
@@ -133,7 +130,6 @@ public:
        static String PkgDataDir;
        static String PrefixDir;
        static String ProgramData;
-       static double ReloadTimeout;
        static int RLimitFiles;
        static int RLimitProcesses;
        static int RLimitStack;
index 8d4c9b3e0908a0b4f54190cb4504bbd53fb883d5..72fa92dcf27fce00e6ba66a76a915a27d4ac2e95 100644 (file)
@@ -94,11 +94,6 @@ abstract class Configuration
                set;
        };
 
-       [config, no_storage, virtual] double ReloadTimeout {
-               get;
-               set;
-       };
-
        [config, no_storage, virtual] int RLimitFiles {
                get;
                set;
index 0ff4f0e0240a106405cf85f722d085a97f209e07..8f6ba524914db4510f70586ee61f8edb20fea44f 100644 (file)
@@ -5,6 +5,7 @@
 #include "icinga/icingaapplication.hpp"
 #include "icinga/cib.hpp"
 #include "remote/apilistener.hpp"
+#include "base/configuration.hpp"
 #include "base/configtype.hpp"
 #include "base/objectlock.hpp"
 #include "base/utility.hpp"
@@ -84,14 +85,15 @@ void CheckerComponent::Stop(bool runtimeRemoved)
                wait += 0.1;
 
                /* Pick a timeout slightly shorther than the process reload timeout. */
-               double waitMax = Configuration::ReloadTimeout - 30;
+               double reloadTimeout = Application::GetReloadTimeout();
+               double waitMax = reloadTimeout - 30;
                if (waitMax <= 0)
                        waitMax = 1;
 
                if (wait > waitMax) {
                        Log(LogWarning, "CheckerComponent")
                                << "Checks running too long for " << wait
-                               << " seconds, hard shutdown before reload timeout: " << Configuration::ReloadTimeout << ".";
+                               << " seconds, hard shutdown before reload timeout: " << reloadTimeout << ".";
                        break;
                }
        }
@@ -108,6 +110,7 @@ void CheckerComponent::Stop(bool runtimeRemoved)
 void CheckerComponent::CheckThreadProc()
 {
        Utility::SetThreadName("Check Scheduler");
+       IcingaApplication::Ptr icingaApp = IcingaApplication::GetInstance();
 
        boost::mutex::scoped_lock lock(m_Mutex);
 
@@ -126,7 +129,13 @@ void CheckerComponent::CheckThreadProc()
 
                double wait = csi.NextCheck - Utility::GetTime();
 
-               if (Checkable::GetPendingChecks() >= GetConcurrentChecks())
+//#ifdef I2_DEBUG
+//             Log(LogDebug, "CheckerComponent")
+//                     << "Pending checks " << Checkable::GetPendingChecks()
+//                     << " vs. max concurrent checks " << icingaApp->GetMaxConcurrentChecks() << ".";
+//#endif /* I2_DEBUG */
+
+               if (Checkable::GetPendingChecks() >= icingaApp->GetMaxConcurrentChecks())
                        wait = 0.5;
 
                if (wait > 0) {
@@ -154,12 +163,12 @@ void CheckerComponent::CheckThreadProc()
                        Service::Ptr service;
                        tie(host, service) = GetHostService(checkable);
 
-                       if (host && !service && (!checkable->GetEnableActiveChecks() || !IcingaApplication::GetInstance()->GetEnableHostChecks())) {
+                       if (host && !service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableHostChecks())) {
                                Log(LogNotice, "CheckerComponent")
                                        << "Skipping check for host '" << host->GetName() << "': active host checks are disabled";
                                check = false;
                        }
-                       if (host && service && (!checkable->GetEnableActiveChecks() || !IcingaApplication::GetInstance()->GetEnableServiceChecks())) {
+                       if (host && service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableServiceChecks())) {
                                Log(LogNotice, "CheckerComponent")
                                        << "Skipping check for service '" << service->GetName() << "': active service checks are disabled";
                                check = false;
index 433940313d7567b731105204c884b13ffac624ad..3959aeb489291edb6684b60cc0cdfe1d5faa925f 100644 (file)
@@ -11,17 +11,8 @@ class CheckerComponent : ConfigObject
 {
        activation_priority 300;
 
-       [config, no_storage] int concurrent_checks {
-               get {{{
-                       return Application::GetMaxConcurrentChecks();
-               }}}
-               set {{{
-                       Application::SetMaxConcurrentChecks(value);
-               }}}
-               default {{{
-                       return Application::GetDefaultMaxConcurrentChecks();
-               }}}
-       };
+       /* Has no effect. Keep this here to avoid breaking config changes. */
+       [deprecated, config] int concurrent_checks;
 };
 
 }
index 28fa3fa19eee6630753921db1a18ab12bf2926ec..dec1b7c128567b6d0ef1f3edcb694f9121838318 100644 (file)
@@ -1,7 +1,9 @@
 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
 
 #include "icinga/clusterevents.hpp"
+#include "icinga/icingaapplication.hpp"
 #include "remote/apilistener.hpp"
+#include "base/configuration.hpp"
 #include "base/serializer.hpp"
 #include "base/exception.hpp"
 #include <boost/thread/once.hpp>
@@ -20,6 +22,8 @@ void ClusterEvents::RemoteCheckThreadProc()
 {
        Utility::SetThreadName("Remote Check Scheduler");
 
+       int maxConcurrentChecks = IcingaApplication::GetInstance()->GetMaxConcurrentChecks();
+
        boost::mutex::scoped_lock lock(m_Mutex);
 
        for(;;) {
@@ -27,7 +31,7 @@ void ClusterEvents::RemoteCheckThreadProc()
                        break;
 
                lock.unlock();
-               Checkable::AquirePendingCheckSlot(Application::GetMaxConcurrentChecks());
+               Checkable::AquirePendingCheckSlot(maxConcurrentChecks);
                lock.lock();
 
                auto callback = m_CheckRequestQueue.front();
@@ -205,4 +209,4 @@ void ClusterEvents::LogRemoteCheckQueueInformation() {
                << m_ChecksExecutedDuringInterval * 6 * 15 << "/15min" << ");";
 
        m_ChecksExecutedDuringInterval = 0;
-}
\ No newline at end of file
+}
index b0f62b208792db497582a9f2a1bd08d04d504884..d9518abc887247eb83e654bdba5e180aa2869517 100644 (file)
@@ -29,6 +29,7 @@ INITIALIZE_ONCE_WITH_PRIORITY(&IcingaApplication::StaticInitialize, 50);
 
 void IcingaApplication::StaticInitialize()
 {
+       /* Pre-fill global constants, can be overridden with user input later in icinga-app/icinga.cpp. */
        String node_name = Utility::GetFQDN();
 
        if (node_name.IsEmpty()) {
@@ -43,6 +44,9 @@ void IcingaApplication::StaticInitialize()
 
        ScriptGlobal::Set("NodeName", node_name);
 
+       ScriptGlobal::Set("ReloadTimeout", 300);
+       ScriptGlobal::Set("MaxConcurrentChecks", 512);
+
        Namespace::Ptr systemNS = ScriptGlobal::Get("System");
        /* Ensure that the System namespace is already initialized. Otherwise this is a programming error. */
        VERIFY(systemNS);
@@ -289,6 +293,12 @@ String IcingaApplication::GetNodeName() const
        return ScriptGlobal::Get("NodeName");
 }
 
+/* Intentionally kept here, since an agent may not have the CheckerComponent loaded. */
+int IcingaApplication::GetMaxConcurrentChecks() const
+{
+       return ScriptGlobal::Get("MaxConcurrentChecks");
+}
+
 String IcingaApplication::GetEnvironment() const
 {
        return Application::GetAppEnvironment();
index c878f91ce32dc4daa88c0fd41a41160f8f2ff627..7888fa6adc7884311dd082b4e82dd7db10afe26e 100644 (file)
@@ -33,6 +33,8 @@ public:
 
        String GetNodeName() const;
 
+       int GetMaxConcurrentChecks() const;
+
        String GetEnvironment() const override;
        void SetEnvironment(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
 
index c35dd1163c17e76532e8752e237c095549e0ef67..fad266b530f45714b69246d0be5383514d0b9a8b 100644 (file)
@@ -218,7 +218,7 @@ void ConfigPackageUtility::AsyncTryActivateStage(const String& packageName, cons
        args->Add("ActiveStageOverride=" + packageName + ":" + stageName);
 
        Process::Ptr process = new Process(Process::PrepareCommand(args));
-       process->SetTimeout(Configuration::ReloadTimeout);
+       process->SetTimeout(Application::GetReloadTimeout());
        process->Run(std::bind(&TryActivateStageCallback, _1, packageName, stageName, reload));
 }