Commit Graph

767 Commits

Author SHA1 Message Date
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 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 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
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 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
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
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 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 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 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 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
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
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
Julian Brost 2dcdae4470 Remove redundant call to Serialize() in ConfigItem::Commit()
The very same object is already serialized a few lines above, the result is
even stored in a variable, but that variable was not used before. Simply using
this variable results in a noticeable improvement of config validation times.
2022-04-28 17:09:16 +02:00
Yonas Habteab fb21345bfd ConfigItem: Use atomic variables for notified and commited items count 2022-02-25 15:17:33 +01:00
Julian Brost 36ce7d961f Rename silent parameter of ConfigItem::ActivateItems()
As silent now no longer only controls the generation of log messages, a better
name is required. This changes its name, inverts its value to reflect the new
name and adds a documentation comment.
2021-06-21 16:07:36 +02:00
Julian Brost 05ca30a6a0 Write early log messages to the Windows Event Log
When Icinga 2 is started as a service, the early log messages generated
until the FileLogger object is activated are lost and make it really
hard to debug issues that (only) occur when Icinga 2 reloads.

With this commit, these early log messages are written to the Windows
Event Log.
2021-06-21 15:15:54 +02:00
Alexander Aleksandrovič Klimov ef8619f76b
Merge pull request #8601 from Icinga/feature/replace-std-boost-bind-with-lambdas-7006
Feature: Replace std/boost::bind() with lambdas
2021-03-18 17:56:13 +01:00
Yonas Habteab 43ba2da39c Replace std/boost::bind() function with lambda expression 2021-03-10 16:29:40 +01:00
Alexander A. Klimov c3388e9af6 Use std::mutex, not boost::mutex 2021-02-03 09:54:57 +01:00
Julian Brost e727675aaf Remove incorrect assertion in ConfigItem::ActivateItems
There is an assertion that after activating items, all these items are
active, which sounds reasonable at first. However, with concurrent API
queries, some of these could already be deleted and therefore be
deactivated again.
2021-01-15 16:40:07 +01:00
Julian Brost 0c6abc817b Remove upq from ConfigItem::ActivateItems
Since commit d9010c7b9f, ActivateItems no
longer uses the WorkQueue upq to perform tasks but instead performs
these locally. One instance of `upq.Join()`/`upq.HasExceptions()`
remained in the function, but I believe this was just missed when
removing the `upq.Enqueue()` call just before.

This commit removes the corresponding parameter and updates all call
sites accordingly.
2021-01-13 15:19:55 +01:00
Alexander A. Klimov 530d84ae3b Make ConfigCompiler#m_LexBuffer a String
... to reduce malloc()s.
2020-01-21 13:38:59 +01:00
Alexander A. Klimov 9be3b60f76 DSL: allow ()use(x)=>x and ()use(x)=>{return x} 2019-12-03 11:19:34 +01:00
Alexander A. Klimov 5c347ef7bd DSL: introduce x?y:z 2019-11-15 13:38:01 +01:00
Alexander Aleksandrovič Klimov 3804f4edcc I like to move it, move it 2019-10-28 13:46:33 +01:00
Michael Friedrich e0ef5fe9de
Merge pull request #7458 from Icinga/feature/config-parser-cleanup
Config parser: introduce optional_newlines
2019-10-22 17:29:59 +02:00
Michael Friedrich 6103f53c5b
Merge pull request #7541 from Icinga/bugfix/heredoc-eof
Config lexer: complain on EOF in heredocs, i.e. {{{abc<EOF>
2019-10-22 17:19:27 +02:00
Alexander A. Klimov 768044a754 Replace std::shared_ptr<NamespaceValue> with NamespaceValue::Ptr
refs #7361
2019-10-21 17:10:51 +02:00
Alexander A. Klimov aa4cad7482 Replace std::shared_ptr<Expression> with Expression::Ptr
refs #7361
2019-10-21 17:10:51 +02:00
Michael Friedrich 3e6fc9bfa1
Merge pull request #7457 from Icinga/feature/config-parser-malloc
Config parser: save some memory allocations
2019-10-17 17:19:30 +02:00
Alexander A. Klimov 672f497c3a Config lexer: complain on EOF in heredocs, i.e. {{{abc<EOF> 2019-09-26 13:10:19 +02:00
Alexander A. Klimov b4e3736e31 WarnOnImplicitlySetGlobalVar(): warn only on sins inside actual DSL code 2019-09-23 15:09:57 +02:00