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

MacroProcessor::ResolveMacro(): treat quasi-CV-object IcingaApplication as real CV-object #9779

Conversation

Al2Klimov
Copy link
Member

As MacroProcessor checked just for CustomVarObject base class, but IcingaApplication provided the vars attribute by itself, it had to also resolve CV macros by itself. That logic diverged from MacroProcessor so that macros inside IcingaApplication CVs weren't resolved. Until now.

ref/IP/46031

Test protocol

Config

object CheckerComponent "cc" { }

object IcingaApplication "app" {
	vars.myecho_1 = "42$$"
}

object CheckCommand "myecho" {
	command = [ "python3", "-c", "import sys; print(sys.argv); exit(128)" ]
	arguments = {
		myecho_1 = "$myecho_1$"
	}
}

object Host NodeName {
	check_command = "myecho"
}

Logs

[2023-05-31 11:57:08 +0200] warning/PluginCheckTask: Check command for object 'Alexanders-MacBook-Pro-2.local' (PID: 87725, arguments: 'python3' '-c' 'import sys; print(sys.argv); exit(128)' 'myecho_1' '42$') terminated with exit code 128, output: ['-c', 'myecho_1', '42$']

Conclusion

$$ now becomes $ as expected. (Before: $$ -> $$)

@Al2Klimov Al2Klimov added bug Something isn't working ref/IP area/runtime Downtimes, comments, dependencies, events labels May 31, 2023
@Al2Klimov Al2Klimov added this to the 2.14.0 milestone May 31, 2023
@cla-bot cla-bot bot added the cla/signed label May 31, 2023
@julianbrost
Copy link
Contributor

checked just for CustomVarObject base class, but IcingaApplication provided the vars attribute by itself

Could IcingaApplication just inherit from CustomVarObject? Otherwise, there could be more undesirable inconsistencies.

@Al2Klimov
Copy link
Member Author

If you ask this way: no. IcingaApplication couldn’t "just" inherit from CustomVarObject. A such inheritance could bring far more undesirable surprises. You had to insert CustomVarObject -> ConfigObject into the existing IcingaApplication -> Application -> ConfigObject tree. Application -> CustomVarObject? Would require the latter being in libbase. Forget it. Virtual inheritance? This would open a construction area on its own. CustomVarObject as mixin like ConfigType? You already dislike such existing stuff. Inconsistencies or not – nobody complained. At best this is a quality issue.

@julianbrost
Copy link
Contributor

I didn't consider that indirection in the inheritance of ConfigObject, so yes, that makes things ugly here.

So in summary, the ability to provide recursive macros is limited to within MacroProcessor, i.e. it does not expose *recursive_macro = true; to MacroResolver (which is implemented by IcingaApplication) so some of the code is moved.

@julianbrost
Copy link
Contributor

The only other places that seem to take special care of CustomVarObject seem to be Icinga DB (which doesn't write the IcingaApplication object the database) and the IDO (it probably doesn't either, but I didn't even bother to check), so the change should be fine in that respect.

Apart from that, it changes which hard-coded macros from IcingaApplication can be overridden from that vars attribute. But given that the vars lookup was somewhere in the middle, that felt quite arbitrary anyways and I guess nobody relies on that (I'm not sure if many users are even aware of IcingaApplication.vars).

@Al2Klimov
Copy link
Member Author

The only other places that seem to take special care of CustomVarObject seem to be Icinga DB (which doesn't write the IcingaApplication object the database) and the IDO (it probably doesn't either, but I didn't even bother to check), so the change should be fine in that respect.

Which change exactly? Also, does the latter imply that the remaining inconsistencies, if any, are at best pure code quality issues?

@julianbrost
Copy link
Contributor

Which change exactly?

Doing it this way instead of trying to make IcingaApplication a CustomVarObject.

Also, does the latter imply that the remaining inconsistencies, if any, are at best pure code quality issues?

That means that I haven't looked at the IDO code, I just found that it references CustomVarObject. This PR is unlikely to introduce any new problems there, and if there was some inconsistency in the IDO nobody ever noticed, it doesn't matter (but I guess the IDO doesn't dump custom vars of IcingaApplication either).

lib/icinga/macroprocessor.cpp Outdated Show resolved Hide resolved
@Al2Klimov Al2Klimov force-pushed the macroprocessor-resolvemacro-quasi-cv-object-icingaapplication branch from e2588b2 to 0464b7f Compare May 31, 2023 14:34
…on as real CV-object

As MacroProcessor checked just for CustomVarObject base class, but
IcingaApplication provided the vars attribute by itself, it had to also
resolve CV macros by itself. That logic diverged from MacroProcessor so that
macros inside IcingaApplication CVs weren't resolved. Until now.
@Al2Klimov Al2Klimov force-pushed the macroprocessor-resolvemacro-quasi-cv-object-icingaapplication branch from 0464b7f to a9c80ff Compare May 31, 2023 14:35
@julianbrost julianbrost merged commit 7c381ae into master May 31, 2023
@icinga-probot icinga-probot bot deleted the macroprocessor-resolvemacro-quasi-cv-object-icingaapplication branch May 31, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/runtime Downtimes, comments, dependencies, events bug Something isn't working cla/signed ref/IP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants