Commit Graph

6283 Commits

Author SHA1 Message Date
Alexander A. Klimov b2b49caf61 Macros: support $env.ENV_VAR_NAME$
refs #6259
2023-02-10 17:21:29 +01:00
Alexander A. Klimov f3f2c943c7 ScriptGlobal::Set(): don't explicitly give Namespace#Set() its default values 2023-02-10 15:55:10 +01:00
Alexander A. Klimov e61b380808 Call Namespace#Set(), not #SetFieldByName()
Namespace#SetFieldByName() calls #Set() anyway.
2023-02-10 15:53:30 +01:00
Alexander A. Klimov 683095a165 Make globals.Internal values non-const by default
That namespace is internal anyway.

Previous commit, icinga2 console:
Error: Constants must not be removed.

This commit fixes it.
2023-02-10 15:47:25 +01:00
Alexander A. Klimov 02df94a46a Repair DSL Namespace values being constant broken in #9627
master before #9627 (a0286e9c6):

<1> => namespace n { x = 42; x = 42 }
                             ^^^^^^
Constant must not be modified.
<2> =>

HEAD of #9627 (24b57f0d3):

<1> => namespace n { x = 42; x = 42 }
null
<2> =>
2023-02-10 15:43:01 +01:00
Julian Brost 0dd35bb960
Merge pull request #9657 from Icinga/shared_mutex-Dictionary
Use a shared_mutex for read `Dictionary` operations
2023-02-10 15:15:52 +01:00
Alexander A. Klimov e9846f1827 ScriptGlobal::Set(): remove unused bool overrideFrozen 2023-02-10 11:33:46 +01:00
Alexander A. Klimov cd78da13d3 Dictionary#Clear(): remove unused bool overrideFrozen 2023-02-10 11:33:46 +01:00
Alexander A. Klimov 270c6392d4 Dictionary#Remove(): remove unused bool overrideFrozen 2023-02-10 11:33:46 +01:00
Alexander A. Klimov ca547d0292 Use a shared_mutex for read `Dictionary` operations
This allows multiple parallel read operations resulting
in a overall speedup on systems with many cores.
2023-02-10 11:31:51 +01:00
Alexander A. Klimov a309b4a415 ResolverSpec: add option not to resolve "$name$"
but only "$host.name$".
2023-02-06 16:39:17 +01:00
Alexander A. Klimov 5b63407d15 Forbid dependency cycles 2023-02-06 12:33:48 +01:00
Alexander A. Klimov 91901eafd8 Introduce EnvResolver
refs #6259
2023-02-06 11:25:25 +01:00
Alexander A. Klimov a9341eb4a0 Setup all signal handlers with SA_RESTART flag
so interrupted syscalls get auto-restarted and callers
don't get or have to handle the EINTR error.
2023-02-03 14:46:45 +01:00
Julian Brost c51037725a
Merge pull request #9466 from Icinga/flush-temp-files
Deduplicate and stabilize fragile filesystem transactions
2023-02-02 16:29:11 +01:00
Julian Brost 3eb85797ce
Merge pull request #9622 from Icinga/9563
Main process: ignore SIGHUP
2023-02-02 11:36:13 +01:00
Julian Brost a0239e44f7
Merge pull request #9598 from Icinga/9596
CheckerComponent#CheckThreadProc(): also propagate next check update …
2023-02-01 20:09:06 +01:00
Alexander Aleksandrovič Klimov 4e021e0105
Merge pull request #9648 from Icinga/frozen-namespace-config-validation
Fix config sync after freezing namespaces
2023-02-01 17:07:57 +01:00
Alexander A. Klimov e9b8c67975 CheckerComponent#CheckThreadProc(): also propagate next check update to Icinga DB
if caused by dependency or check period.

Now as long as any of the above causes check skips
next check and next update will be up-to-date in Icinga DB,
so the checkable won't slide into false positive overdue.
2023-02-01 16:25:56 +01:00
Julian Brost 2b43354080
Merge pull request #8744 from Icinga/bugfix/unnecessary-chown-8743
NodeUtility::WriteNodeConfigObjects(): avoid unneccessary Utility::SetFileOwnership()
2023-02-01 14:27:46 +01:00
Julian Brost fd1aa73d25 Fix config sync after freezing namespaces
This was accidentally broken by #9627 because during config sync, a config
validation happens that uses `--define System.ZonesStageVarDir=...` which fails
on the now frozen namespace.

This commit changes this to use `Internal.ZonesStageVarDir` instead. After all,
this is used for internal functionality, users should not directly interact
with this flag.

Additionally, it no longer freezes the `Internal` namespace which actually
allows using `Internal.ZonesStageVarDir` in the first place. This also fixes
`--define Internal.Debug*` which was also broken by said PR. Freezing of the
`Internal` namespace is not necessary for performance reasons as it's not
searched implicitly (for example when accessing `globals.x`) and should users
actually interact with it, they should know by that name that they are on their
own.
2023-02-01 12:29:47 +01:00
Alexander A. Klimov c953ba1206 Remove redundant ThreadPool#m_Threads 2023-01-27 16:34:11 +01:00
Alexander A. Klimov 288ad68649 ThreadPool#ThreadPool(): remove unused parameter 2023-01-27 16:32:29 +01:00
Alexander A. Klimov fd93feaec7 Include Utility::SetFileOwnership() inside FS transactions
to make them even more atomic.
2023-01-27 12:03:59 +01:00
Alexander A. Klimov d22fdf2a7a Introduce AtomicFile#GetTempFilename() 2023-01-27 12:03:59 +01:00
Alexander A. Klimov 0367c9e099 Remove unused Utility::CreateTempFile() 2023-01-27 12:03:59 +01:00
Alexander A. Klimov b92fe23469 Deduplicate and stabilize fragile filesystem transactions
by using AtomicFile so they ensure all or nothing of a file gets replaced.
2023-01-27 12:03:56 +01:00
Alexander A. Klimov a3e205b990 Introduce AtomicFile::Write() 2023-01-27 11:36:09 +01:00
Julian Brost 2d860a0f5e
Merge pull request #8118 from Icinga/feature/speed-object-registry-8112
Speed up config object lookup
2023-01-26 19:03:40 +01:00
Alexander Aleksandrovič Klimov 421ac1735c
Merge pull request #9608 from Icinga/move-types-namespace
Move Types namespace into type.cpp and simplify Type::GetByName()
2023-01-26 18:32:41 +01:00
Julian Brost ad8868cab7
Merge pull request #9599 from Icinga/influx-ns
Influx DB: don't unneccessarily truncate timestamps to whole seconds
2023-01-26 17:44:50 +01:00
Alexander A. Klimov b2fc49569c Make ConfigType#m_Mutex a std::shared_timed_mutex
refs #8112
2023-01-26 15:04:02 +01:00
Alexander A. Klimov 21759f015d ConfigType: store config objects in a hash map
refs #8112
2023-01-26 15:03:54 +01:00
Julian Brost 3dab46623b Move Types namespace into type.cpp and simplify Type::GetByName()
This commit moves the initialization of the globals.Types namespace to type.cpp
in order to keep a pointer to the Namespace object in Type::m_Namespace and
simplify Type::GetByName() using it.

The dynamic type check is moved into an assertion after freezing the namespace.
2023-01-26 14:26:41 +01:00
Yonas Habteab 5a67ddea76 Don't post-increment stl iterators 2023-01-26 09:10:49 +01:00
Yonas Habteab 8bb0b857d8 ApiListener: Fix memory leak & group `a || b && c` correctly 2023-01-26 09:10:49 +01:00
Yonas Habteab 95cec9cba2 Don't mark a method as `virtual` in a `final` class 2023-01-26 09:10:38 +01:00
Yonas Habteab 7b91b200f5 Use simplified if conditions where applicable 2023-01-26 09:06:20 +01:00
Yonas Habteab 38313434d2 Avoid calling `GetDeferredInitializers()` repeatedly 2023-01-26 09:05:19 +01:00
Alexander Aleksandrovič Klimov bb99106926
Merge pull request #7863 from Icinga/bugfix/disallow-receiving-ticket-salt-via-api
Disallow fetching the ticket salt via REST API
2023-01-25 16:39:30 +01:00
Julian Brost 5fea15e090
Merge pull request #7958 from Icinga/bugfix/api-500-404-7956
/v1/actions/*: return 404 if no objects found
2023-01-24 15:08:17 +01:00
Michael Friedrich 4d57de2a1a Hide TicketSalt in /v1/variables 2023-01-20 12:38:18 +01:00
Julian Brost 24b57f0d3a Namespace: don't acquire shared locks on frozen namespaces
This makes freezing a namespace an irrevocable operation but in return allows
omitting further lock operations. This results in a performance improvement as
reading an atomic bool is faster than acquiring and releasing a shared lock.

ObjectLocks on namespaces remain untouched as these mostly affect write
operations which there should be none of after freezing (if there are some,
they will throw exceptions anyways).
2023-01-19 17:56:44 +01:00
Julian Brost cc0e2ec181 Use a shared_mutex for read `Namespace` operations
This allows multiple parallel read operations resulting in a overall speedup on
systems with many cores.
2023-01-19 17:55:29 +01:00
Julian Brost 1c066fc02e Simplify NamespaceValue class hierarchy to one struct without member functions
This commit removes EmbeddedNamespaceValue and ConstEmbeddedNamespaceValue and
reduces NamespaceValue down to a simple struct without inheritance or member
functions. The code from these clases is inlined into the Namespace class. The
class hierarchy determining whether a value is const is moved to an attribute
of NamespaceValue.

This is done in preparation for changes to the locking in the Namespace class.
Currently, it relies on a recursive mutex. In the future, a shared mutex
(read/write lock) should be used instead, which cannot allow recursive locking
(without failing or risk deadlocking on lock upgrades). With this change, all
operations requiring a lock for one operation are within one function, no
recursive locking is not needed any more.
2023-01-19 17:55:11 +01:00
Julian Brost 0503ca1379 Initialize namespaces without using `overrideFrozen`
This commit adds a new initialization priority `FreezeNamespaces` that is run
last and moves all calls to `Namespace::Freeze()` there. This allows all other
initialization functions to still update namespaces without the use of the
`overrideFrozen` flag.

It also moves the initialization of `System.Platform*` and `System.Build*` to
an initialize function so that these can also be set without setting
`overrideFrozen`.

This is preparation for a following commit that will make the frozen flag in
namespaces finial, no longer allowing it to be overriden (freezing the
namespace will disable locking, so performing further updates would be unsafe).
2023-01-19 09:53:36 +01:00
Julian Brost 6229f4d9bf InitializePriority: don't explicitly specify values
Now that all values are in one place, there is no reason for this numbering
with gaps anymore. If you need to insert a new value in between, you can just
do so in the enum.

This reverses the sort order of the enum, thereby requiring a change to the
sort order of the std::priority_queue containing the elements.
2023-01-18 15:57:32 +01:00
Julian Brost 99bb687350 INITIALIZE_ONCE_WITH_PRIORITY: use enum for priority values
Change the type of the priority values from int to a new enum. By replacing the
magic int values throughout the code base with named values, there is now a
single place where all priority values are defined and you get an overview over
the initialization order.
2023-01-18 15:57:27 +01:00
Julian Brost 61285adcae InitializeOnceHelper: use std::function instead of C function pointer
InitializeOnceHelper calls Loader::AddDeferredInitializer which takes a
std::function, so it's eventually converted to that anyways. This commit just
does this a bit earlier, and by saving the step of the intermediate C function
pointer, this would now also work for capturing lambdas (which there are none
of at the moment).
2023-01-18 15:52:42 +01:00
Julian Brost c019f8c04a
Merge pull request #9603 from Icinga/remove-namespace-behavior
Namespace: replace behavior classes with a bool
2023-01-18 15:48:34 +01:00
Julian Brost a259650bea
Merge pull request #8595 from Icinga/bugfix/cluster-zone-own-zone-8570
cluster-zone: consider own zone connected if there's only one endpoint
2023-01-17 17:26:14 +01:00
Alexander A. Klimov 21f548d3c0 Remove no-op InfluxDB URL param
precision=ns is the default.
2023-01-16 12:03:08 +01:00
Julian Brost 9590c176e3
Merge pull request #9491 from Icinga/9488
Fix compile error on Solaris 11.4
2023-01-12 14:22:52 +01:00
Julian Brost 0294c174a4
Merge pull request #9594 from Icinga/8834
ConfigObjectUtility::GetObjectConfigPath(): just return paths of existing objects
2023-01-09 13:49:58 +01:00
Alexander A. Klimov e1bb085b0f ConfigObjectUtility::DeleteObjectHelper(): only delete _api files
to restore the behavior before the previous commit. Otherwise we'd delete all
API object's child objects' files including applied child object rules in /etc.
2023-01-05 18:05:31 +01:00
Julian Brost dd51997c73
Merge pull request #9624 from Icinga/9618
Make compilable on Boost v1.81
2023-01-05 15:32:22 +01:00
Alexander A. Klimov 99c2d69dc8 Handle boost::beast::http::basic_fields#operator[]() signature change (v1.81)
Use always working std::string(x), not broken x.to_string().
(x is a return value.)
2023-01-05 11:18:20 +01:00
Alexander A. Klimov 5bcbc96e22 Handle boost::beast::http::basic_fields#set() signature change (v1.81)
Make String convertible to boost::beast::string_view (always working),
not boost::string_view (broken).
2023-01-05 11:18:20 +01:00
Alexander A. Klimov d059885d9b Main process: ignore SIGHUP
On OpenBSD rcctl reload icinga2 SIGHUPs all "icinga2" processes,
not just our umbrella. We must handle this.
2023-01-03 18:29:31 +01:00
Julian Brost fbb68dbcd0 Namespace: replace behavior classes with a bool
In essence, namespace behaviors acted as hooks for update operations on
namespaces. Two behaviors were implemented:

- `NamespaceBehavior`: allows the update operation unless it acts on a value
  that itself was explicitly marked as constant.
- `ConstNamespaceBehavior`: initially allows insert operations but marks the
  individual values as const. Additionally provides a `Freeze()` member
  function. After this was called, updates are rejected unless a special
  `overrideFrozen` flag is set explicitly.

This marvel of object-oriented programming can be replaced with a simple bool.
This commit basically replaces `Namespace::m_Behavior` with
`Namespace::m_ConstValues` and inlines the behavior functions where they were
called. While doing so, the code was slightly simplified by assuming that
`m_ConstValues` is true if `m_Frozen` is true. This is similar to what the API
allowed in the old code as you could only freeze a `ConstNamespaceBehavior`.
However, this PR moves the `Freeze()` member function and the related
`m_Freeze` member variable to the `Namespace` class. So now the API allows any
namespace to be frozen. The new code also makes sense with the previously
mentioned simplification: a `Namespace` with `m_ConstValues = false` can be
modified without restrictions until `Freeze()` is called. When this is done, it
becomes read-only.

The changes outside of `namespace.*` just adapt the code to the slightly
changed API.
2022-12-09 09:25:46 +01:00
Julian Brost a8cc5dff89 Prevent ObjectLock from being copied
Copying an ObjectLock results in the underlying mutex being unlocked too often.
There's also no good reason for copying a scoped locking class (if at all, it
should be moved).
2022-12-08 15:48:01 +01:00
Alexander Aleksandrovič Klimov ca328627cd
Merge pull request #9537 from Icinga/replace-some-raw-pointer-with-intrusive-ptr
FilterUtility: Replace some nested raw pointers by `unique_ptr<>*`
2022-12-06 13:07:24 +01:00
Alexander Aleksandrovič Klimov b585e20a4c
Merge pull request #9591 from Icinga/circular-refs
icinga2 daemon: w/o --dump-objects just check for circular refs
2022-11-30 21:41:21 +01:00
Alexander A. Klimov 83021f8231 CONTEXT: use << everywhere to unify usages 2022-11-30 11:06:51 +01:00
Alexander A. Klimov b82814fb29 CONTEXT: lazily evaluate frames to only actually assemble when needed 2022-11-30 11:06:45 +01:00
Alexander A. Klimov 0b46e0aeab CONTEXT: use l_Frames as stack to reduce modification complexity 2022-11-30 10:56:24 +01:00
Alexander A. Klimov 70df0e298e CONTEXT: reduce malloc()s by replacing linked list with vector 2022-11-30 10:56:24 +01:00
Alexander A. Klimov 7c481742f4 icinga2 daemon: w/o --dump-objects just check for circular refs
and don't malloc() anything.
2022-11-30 10:45:50 +01:00
Alexander A. Klimov e53ec2a50f SerializeInternal(): allow to optionally not malloc() anything
This effectively just checks for circular refs.
2022-11-30 10:45:50 +01:00
Alexander A. Klimov 145ee890df Just get paths from existing objects for modification and deletion
instead of computing from scratch if they're in the _api package.

For now this changes literally nothing as paths of existing objects still follow
the scheme of paths of new objects which didn't change. Now Icinga only doesn't expect
existing objects at particular paths. However, with the latter in v2.14+ (agent,
satellite) we can just change the path scheme of new objects in v2.16+ (master)
as we wish. The child nodes will just follow the new scheme of paths of new objects.
2022-11-28 16:39:16 +01:00
Yonas Habteab c1f73fbc1d FilterUtility: Replace some nested raw pointers by our `unique_ptr<X>*` 2022-11-28 14:50:54 +01:00
Yonas Habteab 834709543a ApplyRule: Make `m_HasMatches` atomic
This prevents the `m_HasMatches` property from being altered simultaneously.
This might seem harmless (since this property can only be set to true by any calling thread),
however, from a technical (C++) point of view, this constitutes a data race.
2022-11-28 14:13:58 +01:00
Alexander A. Klimov eaa3cd83ad Influx DB: don't unneccessarily truncate timestamps to whole seconds
Instead send timestamps with the highest possible precision (ns).
Useful for check intervals <1s.
2022-11-28 12:27:01 +01:00
Julian Brost ae32b3cbbd
Merge pull request #9586 from Icinga/9363
icinga2 daemon: write icinga2.debug only if --dump-objects given
2022-11-24 16:03:42 +01:00
Alexander A. Klimov f71612d8f3 icinga2 object list: warn on possibly outdated config 2022-11-24 10:50:17 +01:00
Alexander A. Klimov 0767c6ef87 icinga2 daemon -C: write icinga2.debug only if --dump-objects given
to save config (re)load time.
2022-11-23 12:54:33 +01:00
Julian Brost dd99a5ace9
Merge pull request #9577 from Icinga/ConfigItem-CommitNewItems
ConfigItem::CommitNewItems(): allow fast search of pending items by type
2022-11-23 12:34:51 +01:00
Alexander A. Klimov ae693cb7e1 ConfigItem::CommitNewItems(): allow fast search of pending items by type 2022-11-21 15:07:39 +01:00
Alexander A. Klimov 33e609d791 Type#GetLoadDependencies(): avoid malloc()
- cache result
- return it by const ref
- do Type::GetByName() for the callers
2022-11-21 15:07:39 +01:00
Julian Brost a958a735d7
Merge pull request #9555 from Icinga/ApplyRule-GetDebugInfo
ApplyRule#GetDebugInfo(): return by const ref to avoid malloc()
2022-11-16 13:35:04 +01:00
Alexander A. Klimov e97a5d59e0 ApplyRule#GetFVVar(): return by const ref
to avoid malloc().
2022-11-08 12:48:13 +01:00
Alexander A. Klimov 738662338f ApplyRule#GetFKVar(): return by const ref
to avoid malloc().
2022-11-08 12:45:21 +01:00
Julian Brost 98902b2ff0
Merge pull request #9545 from Icinga/targeted-apply-rules
Separately handle apply rules targetting only specific parent objects
2022-11-04 14:06:15 +01:00
Yonas Habteab a8d46e6d47 Use service short name for evaluating targeted service rules 2022-11-04 10:19:26 +01:00
Yonas Habteab 2610fb1285 Avoid evaluating the same filter twice for the same target 2022-11-04 10:15:22 +01:00
Alexander A. Klimov 27a559c5fe ApplyRule#GetDebugInfo(): return by const ref to avoid malloc() 2022-10-28 15:33:44 +02:00
Alexander A. Klimov a698b9c3da ApplyRule::RuleMap: reduce complexity, save unnecessary lookups 2022-10-28 14:27:53 +02:00
Alexander A. Klimov a907c2ac9a Targeted apply rules: don't unnecessarily eval filter 2022-10-28 14:27:53 +02:00
Alexander A. Klimov dacd6a206d VariableExpression#GetVariable(): return by const ref not to unnecessarily malloc() 2022-10-28 14:27:53 +02:00
Alexander A. Klimov 038a5e8ef6 Unify storages of regular/targeted apply rules: std::vector<ApplyRule::Ptr> 2022-10-28 14:27:53 +02:00
Alexander A. Klimov a56ad38ad3 Separately handle apply rules targetting only specific parent objects
not to unnecessarily run e.g. the filter assign where host.name=="example.com"
for all hosts being not example.com.
2022-10-28 14:27:53 +02:00
Alexander A. Klimov fd7ac4e5ca Allow hashmaps of String 2022-10-21 10:28:41 +02:00
Alexander A. Klimov 449a3c14cf Allow intrusive pointers to ApplyRule 2022-10-21 10:28:41 +02:00
Julian Brost 987bb22397
Merge pull request #9543 from Icinga/apply-rules-lookup
Lookup apply rules faster by Type*, not String and by map instead of ==/!=
2022-10-21 09:53:35 +02:00
Alexander A. Klimov c7d656716f Remove unused ApplyRule#m_TargetType 2022-10-19 13:43:51 +02:00
Alexander A. Klimov d468d7993c Lookup apply rules faster by Type*, not String and by map instead of ==/!=
1. The lookup of apply rules per source type now implies
   no String(const char*) (no malloc()) and just pointer (uint64) comparisions
2. Apply rules are now also grouped by target type via a nested map, that obsoletes
   checking the target type while iterating over all rules per source type
2022-10-19 13:43:51 +02:00
Alexander A. Klimov 90fe4e5bea ApplyRule::GetTargetTypes(): return by const ref not to malloc() 2022-10-19 13:43:51 +02:00
Julian Brost f2563cc890
Merge pull request #9542 from Icinga/context-evaluating-apply-rules-for-host
Construct string once, not unnecessarily N times
2022-10-17 19:57:09 +02:00
Alexander A. Klimov ce1a122618 Construct string once, not unnecessarily N times 2022-10-17 15:54:02 +02:00
Yonas Habteab 400117e2f6 ConfigItem: Don't add items to the new items vector before committing
This also improves the performance a bit, as we longer have to iterate over the items
and copy them into the new items vector.
2022-10-12 13:27:41 +02:00
Yonas Habteab f7298e85d2 ConfigItem: Fix infinite recursion caused by `ignore_on_error` when committing an item
When committing an item with `ignore_on_error` flag set fails, the `Commit()` method only returns `nullptr`
and the current item is not being dropped from `m_Items`. `CommittNewItems()` also doesn't check the return
value of `Commit()` but just continues and tries to commit all items from `m_Items` in recursive call. Since
this corrupt item is never removed from `m_Items`, it ends up in an endless recursion till it finally crashes.
2022-10-12 13:15:09 +02:00
Julian Brost 91cbb856fe
Merge pull request #9521 from Icinga/noop-log-msgs
Logger: don't render log messages which will be disposed anyway
2022-10-11 19:05:03 +02:00
Alexander Aleksandrovič Klimov 363f4d3fde
Merge pull request #9408 from Icinga/bugfix/match-api-permissions-against-join-relations
ObjectQueryHandler: Check user permissions on joined relations
2022-10-11 13:42:27 +02:00
Yonas Habteab a656444d78 RedisConnection: Don't log queries that are going to be discarded 2022-10-11 13:28:08 +02:00
Alexander A. Klimov 0fbb0332a6 Logger: don't render log messages which will be disposed anyway
by caching the total minimum log severity of all loggers in a
"global variable" and whether a message's severity is large enough for any of
the loggers in a per-message no-op flag.
2022-10-11 13:28:08 +02:00
Julian Brost 9be02e3f04
Merge pull request #9518 from Icinga/9481
StartUnixWorker(): watch forked child via waitpid(), not SIGCHLD handler
2022-10-10 14:36:52 +02:00
Yonas Habteab 72e6894bbb Evaluate permission filters also on all joined relations 2022-10-10 12:33:33 +02:00
Yonas Habteab 607f7ab5ca ObjectQueryHandler: Check user permissions on joined relations 2022-10-10 12:33:33 +02:00
Yonas Habteab 1bb2d65a8d FilterUtility: Outsource permission matching from CheckPermission() to a separate method 2022-10-10 12:33:33 +02:00
Julian Brost 465da17060
Merge pull request #9407 from Icinga/bugfix/don-not-allow-changing-object-relations-at-runtime
Don't allow to change object navigation fields at runtime
2022-10-10 12:27:57 +02:00
Alexander A. Klimov 61f7e029cb Replace two-variants enum with bool 2022-10-07 15:14:33 +02:00
Julian Brost 87a4925997
Merge pull request #9519 from Icinga/utf8cp
Utility::ValidateUTF8(): move a string instead of copying a vector
2022-10-07 10:21:37 +02:00
Julian Brost 2a4dc083ae
Merge pull request #9524 from Icinga/introduce-object-idx
Introduce object identifier attr
2022-10-07 10:19:59 +02:00
Julian Brost 0ed9c09a1d
Merge pull request #9513 from Icinga/9501
Icinga DB: on every check result update state only 1x, not 3x in a row
2022-10-07 10:18:56 +02:00
Yonas Habteab 85c77bd878 IcingaDB: Cache generated object hash 2022-09-12 17:23:06 +02:00
Yonas Habteab 07e60c1961 ConfigObject: Introduce new `icingadb_identifier` attr 2022-09-12 17:22:57 +02:00
Yonas Habteab 28c29c1fbc Don't allow to change object parent,host/service_name at runtime 2022-09-09 18:26:28 +02:00
Alexander A. Klimov a6b36a2d7b Utility::ValidateUTF8(): move a string instead of copying a vector
less malloc() = more speed

Especially as JsonEncode() validates every single input string.
2022-09-09 10:50:42 +02:00
Alexander A. Klimov 22bfcf9ac5 icinga2 daemon: remove no-op SIGCHLD handling
1. Don't set a custom handler for SIGCHLD (in the umbrella process)
   as that handler doesn't actually handle SIGCHLD anymore
2. Don't reset the SIGCHLD handler (in the worker process)
   as there's nothing to reset anymore due to the above change
3. Don't block SIGCHLD across fork(2) as its handler doesn't change anymore
   due to the above changes
2022-09-07 12:12:09 +02:00
Alexander A. Klimov 3de714489c Remove unused UnixWorkerState::Failed 2022-09-07 12:08:33 +02:00
Alexander A. Klimov df9008bfc4 StartUnixWorker(): watch forked child via waitpid(), not SIGCHLD handler
Before:

On SIGCHLD from the forked worker the umbrella process sets a failure flag.
StartUnixWorker() recognises that and does waitpid(), failure message, etc..
On OpenBSD we can't tell the signal source, so we always set the failure flag.
That's not how our IPC shall work, that breaks the IPC sooner or later.

After:

No SIGCHLD handling and no failure flag setting.
Instead StartUnixWorker()'s wait loop uses waitpid(x,y,WNOHANG)
to avoid false positives while watching the forked worker.
2022-09-07 11:46:46 +02:00
Yonas Habteab 31785b48fd Expression: Decrease `frame.Depth` only when calling `IncreaseStackDepth()` succeeds
This ensures that `frame.Depth` is only decreased when preceding `frame.IncreaseStackDepth()` callee was successful.
This way, `frame.Depth` will have the same depth prior to and after evaluating a frame.
2022-09-07 09:41:16 +02:00
Alexander A. Klimov 5e9f95c007 Icinga DB: on every check result update state only 1x, not 3x in a row
Before (time: vertical, stack: horizontal):

* Checkable::ExecuteCheck
  * Checkable::UpdateNextCheck
    * IcingaDB::NextCheckChangedHandler
      * HSET icinga:host:state
      * HSET icinga:checksum:host:state
      * ZADD icinga:nextupdate:host
  * RandomCheckTask::ScriptFunc
    * Checkable::ProcessCheckResult
      * Checkable::UpdateNextCheck
        * IcingaDB::NextCheckChangedHandler
          * HSET icinga:host:state
          * HSET icinga:checksum:host:state
          * ZADD icinga:nextupdate:host
      * IcingaDB::NewCheckResultHandler
        * HSET icinga:host:state
        * HSET icinga:checksum:host:state
        * ZADD icinga:nextupdate:host
  * IcingaDB::StateChangeHandler
    * XADD icinga:runtime:state
    * IcingaDB::ForwardHistoryEntries
      * XADD icinga:history:stream:state

After:

* Checkable::ExecuteCheck
  * Checkable::UpdateNextCheck
  * RandomCheckTask::ScriptFunc
    * Checkable::ProcessCheckResult
      * Checkable::UpdateNextCheck
      * IcingaDB::NewCheckResultHandler
        * HSET icinga:host:state
        * HSET icinga:checksum:host:state
        * ZADD icinga:nextupdate:host
  * IcingaDB::StateChangeHandler
    * XADD icinga:runtime:state
    * IcingaDB::ForwardHistoryEntries
      * XADD icinga:history:stream:state

The first state + nextupdate (for overdue) update comes from next_check being
set to now + interval immediately before doing the actual check (not to trigger
it twice). This update is not only not important for the end user, but even
inappropriate. The end user SHALL see next_check being e.g. in -4s, not 5m, as
the check is running at the moment.

The second one is just redundant as IcingaDB::NewCheckResultHandler (the third
one) is called anyway and will update state + nextupdate as well.
2022-09-06 10:10:14 +02:00
Alexander A. Klimov 01bc7d4043 Application::Exit(): don't exit(), but _exit(), even in debug build mode
Case:

1. icinga2 api setup
2. icinga2 daemon -C -x debug

Before: Second commands crashes at exit.
After: No crash.

As the comment between the removed lines clearly says:
Our destructors haven't been built for static data.

This is build type independent.
2022-08-23 13:12:21 +02:00
Alexander A. Klimov 790bad9250 Fix compile error on Solaris 11.4
by not using LOG_FTP which is not defined there.
2022-08-16 12:07:05 +02:00
Julian Brost d3cca0e621
Merge pull request #9409 from Icinga/feature/disallow-empty-object-names
Disallow empty object names
2022-08-11 16:53:28 +02:00
Alexander A. Klimov a2362ebf17 IcingaDB::VersionChangedHandler(): don't handle not synced types
not to surprise (and crash) the Icinga DB daemon with unknown types.
2022-08-10 13:24:44 +02:00
Alexander A. Klimov 32871ca40c IcingaDB::SendCustomVarsChanged(): don't delete custom vars of not synced types
not to surprise (and crash) the Icinga DB daemon with unknown types.
2022-08-10 11:40:53 +02:00
Alexander A. Klimov c9d6eecc7f Dump state file atomically not to corrupt it
by using fsync(2) before close(2) and rename(2).
2022-07-28 18:00:37 +02:00
Alexander A. Klimov 600fb0e3c2 Introduce AtomicFile 2022-07-28 18:00:37 +02:00
Julian Brost 913566cbfa Windows: output useful error message for syscall errors 2022-07-28 17:00:57 +02:00
Yonas Habteab 148f5b8416 ConfigObject: Mark object names as required
This prevents a user from creating an object without a valid name such as `"", null`.
2022-07-15 15:51:58 +02:00
Julian Brost a927ba39b7 Windows: only include critical messages in early log messages
The point of logging to the Windows Event Log was to catch errors that happen
before the full logging configuration has been loaded and enabled. Messages
like the number of loaded objects per type just cause noise in the log and
provide little benefit. Therefore raise the required log level at this stage.

Note that this commit removes the (never documented) ability to use the -x flag
to change the level. But doing so would require patching the command line of
the service in the registry anyways.
2022-07-14 14:07:56 +02:00
Julian Brost bd2118c4cd
Merge pull request #9420 from Icinga/IcingaDB-soft_state
Icinga DB: icinga:*:state: rename state to soft_state
2022-06-29 12:24:52 +02:00
Alexander A. Klimov ba9a5c614c Icinga DB: icinga:*:state: rename state to soft_state 2022-06-29 11:49:06 +02:00
Julian Brost 9b24056e05
Merge pull request #9346 from Icinga/icingadb-check
Introduce Icinga DB check (like the IDO one)
2022-06-28 18:24:29 +02:00
Julian Brost 3222fab05a Icinga DB Check: don't check runtime update backlog during full sync 2022-06-28 13:33:00 +02:00
Julian Brost 4f125753bf Icinga DB Check: ignore suppressed queries in Redis backlog check
If some kind of query is not supposed to be processed at the moment, there is
little point in checking it. During a full dump, state updates are suppressed
(i.e. delayed), so when a dump takes very long, this would have resulted in a
false Redis backlog warning.
2022-06-28 13:33:00 +02:00
Julian Brost 5550fb713c Icinga DB Check: include ongoing dumps in OK message
Also use the "current" and "full dump/sync" terminology in the other messages.
2022-06-28 13:33:00 +02:00
Julian Brost 3ded7a9268 Icinga DB Check: rename dump/sync related perfdata values
Scope all values using current/last instead of takes/took.
2022-06-28 13:33:00 +02:00
Julian Brost e36bc92a2c Icinga DB Check: add unit hints to all rates 2022-06-28 13:33:00 +02:00
Julian Brost eaae7d5863 Icinga DB Check: update not connected message
The check makes no attempt to explicitly connect to Redis, it uses the
connection of the IcingaDB feature, so this message better describes the state
in this situation.
2022-06-28 13:33:00 +02:00
Julian Brost 2fafffb85f Icinga DB Check: fix race-condition with IcingaDB::Start()
IcingaDB::GetConnection() uses IcingaDB::m_Rcon which is only initialized in
IcingaDB::Start(), therefore add a nullptr check to the check command.
Additionally, as m_Rcon is potentially accessed concurrently, add a copy of the
value that is safe for concurrent use.
2022-06-28 13:33:00 +02:00
Julian Brost 953e113465 Icinga DB Check: remove markdown headings from output
icingadb-web shows multiple lines from the check output collapsed into a single
line. The lines containing just minuses make this look cluttered and making
making it a heading provides little to no benefit. Even when rendering markdown
in the check output at some point, having the lists labeled using normal
paragraphs would look just fine.
2022-06-28 13:33:00 +02:00
Julian Brost c59d44cd8b Icinga DB Check: rename perfdata values
- Add icinga2_ and icingadb_ prefixes to make clear which component is
  responsible for the value.
- Rename heartbeat_lag to heartbeat_age, describes it better in my opinion and
  sound a bit less like something that should be as close to zero as possible.
- Rename redis_dump/database_sync into full_dump/full_sync as this is how these
  operations are refered to in log messages as well.
- Rename Redis backlog into Redis query backlog, makes it a bit clearer in my
  opinion.
- Rename runtime_backlog into runtime_update_backlog, as the component in
  Icinga DB is called that way and this naming is also exposed in log messages.
- Rename dump_config/state/history into config/state/history_dump, makes it
  sound more natural.
2022-06-28 13:33:00 +02:00
Julian Brost d0382f71ab Icinga DB Check: rename variables from takes to duration
Sounds more natural in my opinion and I doubt that many users would get that
due to the difference between takes/took, this refers to ongoing dumps.
2022-06-28 13:33:00 +02:00
Julian Brost 3c29b15214 Icinga DB Check: use more natural names for sync/cleanup metrics 2022-06-28 13:33:00 +02:00
Julian Brost d70a27b982 Icinga DB Check: report history and runtime update backlog separately
Probably makes little difference for an end-user, but for support and
development it's great to know which of the two is causing problems.
2022-06-28 13:33:00 +02:00
Julian Brost 2a4605f4b7 Icinga DB Check: clearly state Icinga 2 Redis backlog
Should make it easier to understand that this refers to Redis queries issued by
Icinga 2.
2022-06-28 13:33:00 +02:00
Julian Brost 5613412b81 Icinga DB Check: replace nested calls to fmax() with std::max()
Improves readability, even more so after splitting it into separate lines.
2022-06-28 13:33:00 +02:00