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 Object Action Module Performance Issue #338

Open
lucagubler opened this issue Oct 29, 2024 · 2 comments
Open

Icinga2 Object Action Module Performance Issue #338

lucagubler opened this issue Oct 29, 2024 · 2 comments
Assignees

Comments

@lucagubler
Copy link
Contributor

Hi all

I'm facing some performance issues with the icinga2_object.py action module and the task roles/icinga2/tasks/objects.yml at line 26 (unfortunately it doesn't have a name).

Problem Statement

1st Issue

I think one issue arises because we call this action plugin with a loop. So if we have n Icinga objects defined, we call this plugin n times.

2nd Issue

The second issue is that for each Icinga object we created, we simply copy it to the target host using the copy_action. The copy module is quite slow and since we copy each file individually, execution time increases significantly.

Possible Solutions

Here are some possible solutions

1st Issue

Instead of calling the icinga2_object.py action module from within a loop, we could call it just once and pass the whole tmp_objects. This means that we only call this plugin once and calculate all Icinga objects within that call. I was able to test that locally and the Ansible execution time was 50% faster.

2nd Issue

Here I'm not quite sure how this could be solved. I'm not even 100% sure if I fully understand the existing code. But basically we create all config fragments locally on our Ansible control node. Once everything is ready, we copy each file individually to the Icinga2 Host using the add custom config to assemble task in roles/icinga2/tasks/objects.yml. Each Icinga object is a file, so this could quickly scale up to several thousand files that need to be copied. Wouldn't it be faster and easier if we generate the fragments directly on the Icinga2 Host? This way we don't even have to copy them...

I hope my problem statement is clear. I'm looking forward to your comments and ideas how we can improve this :)

@Donien
Copy link
Collaborator

Donien commented Oct 30, 2024

Hi,

thanks for your input!
A colleague and I actually talked about this just yesterday. I also started changing the icinga2_object action plugin to:

  • Loop over the objects internally
  • Merge config objects that got to the same file in RAM
  • Write once per file

For what I am trying to change I think it would be best to get rid off the order key. This should not be a problem since Icinga 2 does not actually care whether you define the template or the object that imports the template first, for example.

Not writing a file per destination and per order would reduce the amount of write operations.
Additionally, if we decided to get rid off specific file destinations, we could reduce the time further I believe.

What I mean by file destinations: Currently you can choose whatever file you wish for the object to end up in.
If we make it more static, we can for example put all objects of a certain type (hosts.conf) in a destination directory. Basically: All hosts that go to local.d/ will end up in local.d/hosts.conf.

You could of course still use e.g. local.d/linux/ and local.d/windows/ if you really wanted separation here.

Once I rework the icinga2 role to work with the new approach completely, I will share the PoC.

Side note - 2nd Issue: icinga2_object actually does create the files on the target host directly. They are just located at /var/tmp/icinga/ first, for verification.
I have to look into the whole logic more deeply myself though.

@Donien Donien self-assigned this Oct 30, 2024
@lucagubler
Copy link
Contributor Author

Hi Donien

I added all my changes and created a PR #339. I tested it locally and it's working as expected. However, I'm not sure if it's 100% finished. It mainly fixes the 1st issue. I hope this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants