Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icinga2 daemon: write icinga2.debug only if --dump-objects given #9586

Merged
merged 2 commits into from
Nov 24, 2022

Conversation

Al2Klimov
Copy link
Member

to save config (re)load time.

fixes #9363

@cla-bot cla-bot bot added the cla/signed label Nov 21, 2022
@icinga-probot icinga-probot bot added area/configuration DSL, parser, compiler, error handling enhancement New feature or request labels Nov 21, 2022
@Al2Klimov
Copy link
Member Author

➜  icinga2 git:(9363) ✗ prefix/sbin/icinga2 daemon -C
[2022-11-21 12:29:24 +0100] information/cli: Icinga application loader (version: v2.13.0-480-ga6b05059a; debug)
[2022-11-21 12:29:24 +0100] information/cli: Loading configuration file(s).
[2022-11-21 12:29:24 +0100] information/ConfigItem: Committing config item(s).
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 244 CheckCommands.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 FileLogger.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 Endpoint.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 CheckerComponent.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 Host.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 2 HostGroups.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 IcingaApplication.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 User.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 2 NotificationCommands.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 3 Zones.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 3 ServiceGroups.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 3 TimePeriods.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 UserGroup.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 NotificationComponent.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 12 Notifications.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 1 ScheduledDowntime.
[2022-11-21 12:29:24 +0100] information/ConfigItem: Instantiated 11 Services.
[2022-11-21 12:29:24 +0100] information/ScriptGlobal: Dumping variables to file '/Users/aklimov/NET/WS/icinga2/prefix/var/cache/icinga2/icinga2.vars'
[2022-11-21 12:29:24 +0100] information/cli: Finished validating the configuration file(s).
➜  icinga2 git:(9363) ✗ ls -l prefix/var/cache/icinga2
total 8
-rw-------  1 aklimov  staff  855 21 Nov 12:29 icinga2.vars
➜  icinga2 git:(9363) ✗

@Al2Klimov
Copy link
Member Author

➜  icinga2 git:(9363) ✗ prefix/sbin/icinga2 daemon -C --dump-objects
[2022-11-21 12:33:44 +0100] information/cli: Icinga application loader (version: v2.13.0-480-ga6b05059a; debug)
[2022-11-21 12:33:44 +0100] information/cli: Loading configuration file(s).
[2022-11-21 12:33:45 +0100] information/ConfigItem: Committing config item(s).
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 244 CheckCommands.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 FileLogger.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 Endpoint.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 CheckerComponent.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 Host.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 2 HostGroups.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 IcingaApplication.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 User.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 2 NotificationCommands.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 3 Zones.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 3 ServiceGroups.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 3 TimePeriods.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 UserGroup.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 NotificationComponent.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 12 Notifications.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 1 ScheduledDowntime.
[2022-11-21 12:33:45 +0100] information/ConfigItem: Instantiated 11 Services.
[2022-11-21 12:33:45 +0100] information/ScriptGlobal: Dumping variables to file '/Users/aklimov/NET/WS/icinga2/prefix/var/cache/icinga2/icinga2.vars'
[2022-11-21 12:33:45 +0100] information/cli: Finished validating the configuration file(s).
➜  icinga2 git:(9363) ✗ ls -l prefix/var/cache/icinga2
total 2056
-rw-------  1 aklimov  staff  1045698 21 Nov 12:33 icinga2.debug
-rw-------  1 aklimov  staff      855 21 Nov 12:33 icinga2.vars
➜  icinga2 git:(9363) ✗

@julianbrost
Copy link
Contributor

I doubt that there's really no other place in the documentation that would benefit from mentioning the new command explicitly. So if the documentation suggests to use icinga2 object list, it should now also suggest to do a icinga2 daemon -C --dump-objects first.

Additionally, it would be great if icinga2 object list could warn if it's using outdated information.

Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the following data structure is generated for nothing unless started with --dump-objects, you might want to optimize this:

Dictionary::Ptr persistentItem = new Dictionary({
{ "type", type->GetName() },
{ "name", GetName() },
{ "properties", serializedObject },
{ "debug_hints", dhint },
{ "debug_info", new Array({
m_DebugInfo.Path,
m_DebugInfo.FirstLine,
m_DebugInfo.FirstColumn,
m_DebugInfo.LastLine,
m_DebugInfo.LastColumn,
}) }
});

lib/cli/objectlistcommand.cpp Outdated Show resolved Hide resolved
lib/cli/objectlistcommand.cpp Outdated Show resolved Hide resolved
lib/cli/objectlistcommand.cpp Show resolved Hide resolved
@Al2Klimov
Copy link
Member Author

Shall I also optimise Serialize()?

@julianbrost
Copy link
Contributor

Shall I also optimise Serialize()?

That will be the next step in this area, so ahead, will just be fun keeping the side effect of checking for circular references without making the code messy.

@Al2Klimov
Copy link
Member Author

So we shall (at least try to) preserve circular ref checks?

IMAO useless as you can make ones at runtime.

@julianbrost
Copy link
Contributor

You have to do something about it so that it behaves consistently.

Having configs that are valid if and only if you don't specify --dump-objects would be bad. This would reduce object list in usefulness for debugging as there would be valid configs you can't debug with it.

But I would be open to gracefully handling cyclic references in the debug file. Python for example does this:

>>> x = [23, 42]
>>> x.append(x)
>>> x
[23, 42, [...]]

@Al2Klimov
Copy link
Member Author

This would reduce object list in usefulness for debugging as there would be valid configs you can't debug with it.

Weeeell... you'd "just" have to remove the circular refs to start with debugging. You probably won't even need an actual Icinga 2 reload.

@julianbrost
Copy link
Contributor

Well, you already put "just" into quotation marks yourself. This means that it could happen that for a support ticket where you ask for the output of icinga2 object list, you could get the response that it shows an error and would then have to instruct them to change something completely unrelated in the config so that this can continue. I don't think that's a very good option.

@Al2Klimov
Copy link
Member Author

OK. Shall I allow Serialize() to optionally handle circular refs like this?

But I would be open to gracefully handling cyclic references in the debug file. Python for example does this:

@julianbrost
Copy link
Contributor

Please first share how you want to do this. Serialize() generates Array/Dictionary objects that are then serialized into JSON, so you can't have a magic value for "this was a circular reference".

Also, I feel like this might be a good cutoff point for this PR: put the initialization of persistentItem into an if in this PR and keep Serialize() as-is. Then this PR will do exactly as advertised: changes when icinga2.debug is written without other changes in behavior. This should be done rather quickly. And then later (after having agreed on a concept, see below), a second PR for potential changes to Serialize() to handle this.

IMAO useless as you can make ones at runtime.

Do you have an example for creating a circular reference in a place where it would be rejected if you write it into the config?

On second thought, allowing this (circular references inside of attributes of an object) might be problematic: API responses also use Serialize(), so you might run into this issue there (that's why I'm asking if you know an example for creating this as runtime).

On third thought: At the moment, Deserialize(Serialize(x)) == x doesn't hold (at least if function objects are involved) abd allowing this would put us even further apart from this (IMO desirable) property.

So after thinking about this in more detail, I'm not sure about this. If we'd want to do this, there should be a good concept that takes all of this into account.

@Al2Klimov
Copy link
Member Author

Would you prefer a no-op flag, so that it effectively just checks circular refs on demand?

@julianbrost
Copy link
Contributor

You mean for the serialization? Do you have more alternatives in mind than rewriting a separate function? I don't think I'm perfectly happy with either, but everything else that comes to my mind feels like it would end in total over-engineering.

But please only make it a flag for SerializeInternal() and not Serialize() and add a second function for that so that the interface at least looks nice on the outside.

lib/config/configitem.cpp Outdated Show resolved Hide resolved
lib/cli/objectlistcommand.cpp Show resolved Hide resolved
lib/cli/objectlistcommand.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just that small grammar error left: #9586 (comment)

Apart from that, should be good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration DSL, parser, compiler, error handling cla/signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't write icinga2.debug file
3 participants