Skip to content

Commit 2583e82

Browse files
authored
Merge pull request #318 from Icinga:feature/enforce_framework_cache
Feature: Always enforce Framework code caching To ensure we increase the performance of the loading and to introduce JEA profiles later on, we will now enforce the Icinga Framework Code cache starting with 1.6.0. By doing so, each new update will be forced to create a Framework Code Cache and only this file will be loaded during intialisation.
2 parents 4738aa8 + 40aecbd commit 2583e82

15 files changed

+43
-223
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cache/*
66
*.log
77

88
!cache/README.md
9+
!cache/framework_cache.psm1

cache/framework_cache.psm1

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<#
2+
### Note ###
3+
4+
This file is shipping plain with Icinga for Windows for each version.
5+
Once the module is loaded, this content will entirely be replaced with
6+
all modules and components shipped by the Icinga PowerShell Framework.
7+
8+
Manually enabling the feature is no longer required.
9+
#>
10+
11+
$Global:Icinga = @{
12+
'RebuildCache' = $TRUE;
13+
};
14+
15+
Write-IcingaFrameworkCodeCache;

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2323
* [#306](https://github.com/Icinga/icinga-powershell-framework/pull/306) Adds new Cmdlet `Exit-IcingaThrowCritical` to throw critical exit with a custom message, either by force or by using string filtering and adds storing of plugin exit codes internally
2424
* [#314](https://github.com/Icinga/icinga-powershell-framework/pull/314) Adds support to configure on which address TCP sockets are created on, defaults to `loopback` interface
2525
* [#316](https://github.com/Icinga/icinga-powershell-framework/pull/316) The reconfigure menu was previously present inside the Icinga Agent sub-menu and is now moved to the main installation menu for the Management Console
26+
* [#318](https://github.com/Icinga/icinga-powershell-framework/pull/318) We always enforce the Icinga Framework Code caching now and ship a plain file to build the cache on first loading
2627

2728
## 1.5.2 (2021-07-09)
2829

Original file line numberDiff line numberDiff line change
@@ -1,45 +1,21 @@
1-
# Enable Framework Code Caching
1+
# Framework Code Caching
22

3-
On certain systems with fewer CPU cores, there might be an impact while running Icinga for Windows because of long loading times for the Icinga PowerShell Framework. To mitigate this issue, we added the possibility to create a code cache file for the entire Icinga PowerShell Framework.
3+
By default, Icinga for Windows will compile all module files into a single cache file for quicker and easier loading. This ensures, that during startup all functions are available and can be used in combination with JEA profiles.
44

5-
What it does is to load every single module and content file into one single `cache.psm1` file which is loaded in case the caching is enabled.
5+
The location of the cache file is at
66

7-
## Pre-Cautions
8-
9-
By enabling this feature, you will have to generate a new cache file whenever you apply changes to any code for the Icinga PowerShell Framework. This can be done by running the Cmdlet
10-
11-
```powershell
12-
Write-IcingaFrameworkCodeCache
137
```
14-
15-
Please note that the code cache feature must be enabled first.
16-
17-
In case you upgrade to a newer version of the Icinga PowerShell Framework, you will only require to manually proceed in case the code cache feature was disabled beforehand. In case the code cache feature is enabled during the upgrade, the cache file will be generated and updated automatically.
18-
19-
## Enable Icinga Framework Code Cache
20-
21-
To enable the Icinga PowerShell Framework code cache, simply run the following command within an Icinga Shell:
22-
23-
```powershell
24-
Enable-IcingaFrameworkCodeCache
8+
.\cache\framework_cache.psm1
259
```
2610

27-
Once activated, you should make sure to generate a new cache file before using the Framework:
28-
29-
```powershell
30-
Write-IcingaFrameworkCodeCache
31-
```
32-
33-
If you leave the code caching feature enabled, future updates of the Framework will automatically generate a new cache file. If you disabled the feature in-between, please write the cache file manually.
11+
## Pre-Cautions
3412

35-
In case no cache file is present while the feature is activated, a cache file is generated on the first use of `Use-Icinga` or `icinga`.
13+
In case you are running custom modifications to the Framework or apply manual patches, you will **always** have to re-write the Icinga for Windows cache file! During upgrades by using the Icinga for Windows Cmdlets, the cache file is updated automatically.
3614

37-
## Disable Icinga Framework Code Cache
15+
## Updating Cache File
3816

39-
To disable the code caching feature again, you can simply run
17+
To re-write the cache file and update it to the latest version manually, you can use the following command:
4018

4119
```powershell
42-
Disable-IcingaFrameworkCodeCache
20+
Write-IcingaFrameworkCodeCache
4321
```
44-
45-
Please note that even though the cache file is no longer loaded it still remains. Therefor you will have to manually use `Write-IcingaFrameworkCodeCache` in case you activate the feature later again. This is especially required if you update the Icinga PowerShell Framework while the feature was disabled.

doc/frameworkusage/06-Update-Framework-And-Components.md

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Which version of the "Icinga Framework" do you want to install? (release/snapsho
4343
[Notice]: Unblocking Icinga PowerShell Files
4444
[Notice]: Cleaning temporary content
4545
[Notice]: Updating Framework cache file
46-
[Notice]: The code caching feature is currently not enabled. You can enable it with "Enable-IcingaFrameworkCodeCache"
4746
[Notice]: Framework update has been completed. Please start a new PowerShell instance now to complete the update
4847
[Passed]: Icinga Agent service is installed
4948
[Passed]: The specified user "NT Authority\NetworkService" is allowed to run as service

icinga-powershell-framework.psd1

+1-27
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,7 @@
88
Description = 'Icinga for Windows module which allows to entirely monitor the Windows Host system.'
99
PowerShellVersion = '4.0'
1010
NestedModules = @(
11-
'.\lib\core\framework\Get-IcingaFrameworkCodeCache.psm1',
12-
'.\lib\config\Get-IcingaPowerShellConfig.psm1',
13-
'.\lib\config\Read-IcingaPowerShellConfig.psm1',
14-
'.\lib\config\Test-IcingaPowerShellConfigItem.psm1',
15-
'.\lib\core\logging\Write-IcingaConsoleOutput.psm1',
16-
'.\lib\core\logging\Write-IcingaConsoleNotice.psm1',
17-
'.\lib\core\logging\Write-IcingaConsoleWarning.psm1',
18-
'.\lib\core\tools\Read-IcingaFileContent.psm1',
19-
'.\lib\core\framework\Invoke-IcingaInternalServiceCall.psm1',
20-
'.\lib\core\framework\Get-IcingaFrameworkApiChecks.psm1',
21-
'.\lib\daemon\Get-IcingaBackgroundDaemons.psm1',
22-
'.\lib\webserver\Enable-IcingaUntrustedCertificateValidation.psm1',
23-
'.\lib\core\logging\Write-IcingaEventMessage.psm1',
24-
'.\lib\icinga\plugin\Exit-IcingaExecutePlugin.psm1',
25-
'.\lib\icinga\exception\Exit-IcingaPluginNotInstalled.psm1',
26-
'.\lib\icinga\exception\Exit-IcingaThrowException.psm1',
27-
'.\lib\web\Set-IcingaTLSVersion.psm1',
28-
'.\lib\web\Disable-IcingaProgressPreference.psm1',
29-
'.\lib\core\tools\New-IcingaNewLine.psm1',
30-
'.\lib\core\logging\Write-IcingaConsolePlain.psm1',
31-
'.\lib\core\tools\Test-IcingaFunction.psm1',
32-
'.\lib\core\tools\Write-IcingaConsoleHeader.psm1',
33-
'.\lib\core\framework\Test-IcingaFrameworkConsoleOutput.psm1',
34-
'.\lib\core\tools\ConvertTo-IcingaSecureString.psm1',
35-
'.\lib\core\tools\ConvertTo-JsonUTF8Bytes.psm1',
36-
'.\lib\core\tools\ConvertFrom-JsonUTF8.psm1'
11+
'.\cache\framework_cache.psm1'
3712
)
3813
FunctionsToExport = @(
3914
'Use-Icinga',
@@ -52,7 +27,6 @@
5227
'Get-IcingaPowerShellModuleFile',
5328
'Start-IcingaShellAsUser',
5429
'Get-IcingaPowerShellConfig',
55-
'Get-IcingaFrameworkCodeCache',
5630
'Read-IcingaPowerShellConfig',
5731
'Test-IcingaPowerShellConfigItem',
5832
'Write-IcingaConsoleOutput',

icinga-powershell-framework.psm1

+11-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ function Use-Icinga()
1717
[switch]$Minimal = $FALSE
1818
);
1919

20+
if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('RebuildCache') -And $Global:Icinga.RebuildCache) {
21+
Remove-Module 'icinga-powershell-framework';
22+
Import-Module (Get-IcingaFrameworkCodeCacheFile) -Global -Force;
23+
}
24+
2025
Disable-IcingaProgressPreference;
2126

2227
if ($Minimal) {
@@ -42,9 +47,7 @@ function Use-Icinga()
4247
Use-IcingaPlugins;
4348
}
4449

45-
if ((Test-Path (Get-IcingaFrameworkCodeCacheFile)) -eq $FALSE -And (Get-IcingaFrameworkCodeCache)) {
46-
Write-IcingaFrameworkCodeCache;
47-
}
50+
Write-IcingaFrameworkCodeCache;
4851

4952
# This function will allow us to load this entire module including possible
5053
# actions, making it available within our shell environment
@@ -109,11 +112,7 @@ function Get-IcingaFrameworkCodeCacheFile()
109112

110113
function Write-IcingaFrameworkCodeCache()
111114
{
112-
if (Get-IcingaFrameworkCodeCache) {
113-
Import-IcingaLib '\' -Init -CompileCache;
114-
} else {
115-
Write-IcingaConsoleNotice 'The code caching feature is currently not enabled. You can enable it with "Enable-IcingaFrameworkCodeCache"';
116-
}
115+
Import-IcingaLib '\' -Init -CompileCache;
117116
}
118117

119118
function Import-IcingaLib()
@@ -129,16 +128,15 @@ function Import-IcingaLib()
129128
[switch]$CompileCache
130129
);
131130

132-
133131
# This is just to only allow a global loading of the module. Import-IcingaLib is ignored on every other
134132
# location. It is just there to give a basic idea within commands, of which functions are used
135133
if ($Init -eq $FALSE) {
136134
return;
137135
}
138-
136+
139137
$CacheFile = Get-IcingaFrameworkCodeCacheFile;
140138

141-
if ($Custom -eq $FALSE -And $CompileCache -eq $FALSE -And (Test-Path $CacheFile) -And (Get-IcingaFrameworkCodeCache)) {
139+
if ($Custom -eq $FALSE -And $CompileCache -eq $FALSE -And (Test-Path $CacheFile)) {
142140
Import-Module $CacheFile -Global;
143141
return;
144142
}
@@ -361,8 +359,8 @@ function Invoke-IcingaCommand()
361359
'User environment $UserDomain\$Username'
362360
);
363361

364-
if (Get-IcingaFrameworkCodeCache) {
365-
$Headers += [string]::Format('Note: Icinga Framework Code Caching is enabled');
362+
if ($null -eq (Get-Command -Name 'Write-IcingaConsoleHeader' -ErrorAction SilentlyContinue)) {
363+
Use-Icinga;
366364
}
367365

368366
Write-IcingaConsoleHeader -HeaderLines $Headers;

lib/core/framework/Disable-IcingaFrameworkCodeCache.psm1

-24
This file was deleted.

lib/core/framework/Enable-IcingaFrameworkCodeCache.psm1

-21
This file was deleted.

lib/core/framework/Get-IcingaFrameworkCodeCache.psm1

-28
This file was deleted.

lib/core/installer/Start-IcingaForWindowsInstallation.psm1

+1-18
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ function Start-IcingaForWindowsInstallation()
4343
$IcingaEndpoints = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsInstallerMenuEnterIcingaParentNodes';
4444
$IcingaPort = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsInstallationMenuEnterIcingaPort';
4545

46-
# Icinga for Windows PowerShell Framework
47-
$CodeCacheType = Get-IcingaForWindowsInstallerStepSelection -InstallerStep 'Show-IcingaForWindowsManagementConsoleEnableCodeCache';
48-
4946
$Hostname = '';
5047
$GlobalZones = @();
5148
$IcingaParentAddresses = @();
@@ -224,21 +221,7 @@ function Start-IcingaForWindowsInstallation()
224221
}
225222
}
226223

227-
switch ($CodeCacheType) {
228-
'0' {
229-
# Enable Code Cache
230-
Enable-IcingaFrameworkCodeCache;
231-
Write-IcingaConsoleNotice 'Writing Icinga Framework Code Cache file';
232-
Write-IcingaFrameworkCodeCache;
233-
break;
234-
};
235-
'1' {
236-
# Disable Code Cache
237-
Disable-IcingaFrameworkCodeCache;
238-
break;
239-
}
240-
}
241-
224+
Write-IcingaFrameworkCodeCache;
242225
Test-IcingaAgent;
243226

244227
if ($InstallAgent) {

lib/core/installer/menu/installation/AdvancedEntries.psm1

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function Add-IcingaForWindowsInstallationAdvancedEntries()
2121
Show-IcingaForWindowsInstallerMenuSelectIcingaPluginsSource -Automated -Advanced;
2222
Show-IcingaForWindowsInstallerMenuSelectWindowsServiceSource -Automated -Advanced;
2323
Show-IcingaForWindowsInstallationMenuEnterWindowsServiceDirectory -Automated -Advanced;
24-
Show-IcingaForWindowsManagementConsoleEnableCodeCache -Automated -Advanced;
2524

2625
Enable-IcingaFrameworkConsoleOutput;
2726

lib/core/installer/menu/installation/framework/EnableCodeCache.psm1

-32
This file was deleted.

lib/core/installer/menu/manage/framework/ManageFramework.psm1

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
function Show-IcingaForWindowsManagementConsoleManageFramework()
22
{
33
$FrameworkDebug = Get-IcingaFrameworkDebugMode;
4-
$FrameworkCodeCache = Get-IcingaFrameworkCodeCache;
54
$IcingaService = Get-Service 'icingapowershell' -ErrorAction SilentlyContinue;
65
$AdminShell = $global:Icinga.InstallWizard.AdminShell;
76
$ServiceStatus = $null;
@@ -30,21 +29,10 @@ function Show-IcingaForWindowsManagementConsoleManageFramework()
3029
}
3130
},
3231
@{
33-
'Caption' = ([string]::Format('Framework Code Cache: {0}', (& { if ($FrameworkCodeCache) { 'Enabled' } else { 'Disabled' } } )));
34-
'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework';
35-
'Help' = 'Disable or enable the Icinga PowerShell Framework Code cache feature. The code cache is written automatically once it is enabled';
36-
'Disabled' = $FALSE;
37-
'Action' = @{
38-
'Command' = 'Invoke-IcingaForWindowsMangementConsoleToogleFrameworkCodeCache';
39-
'Arguments' = @{ };
40-
}
41-
},
42-
@{
43-
'Caption' = 'Update Framework Code Cache';
44-
'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework';
45-
'Help' = 'Updates the Icinga PowerShell Framework Code Cache';
46-
'Disabled' = (-Not ($FrameworkCodeCache));
47-
'Action' = @{
32+
'Caption' = 'Update Framework Code Cache';
33+
'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework';
34+
'Help' = 'Updates the Icinga PowerShell Framework Code Cache';
35+
'Action' = @{
4836
'Command' = 'Write-IcingaFrameworkCodeCache';
4937
'Arguments' = @{ };
5038
}

lib/core/installer/menu/manage/framework/ToogleFrameworkCodeCache.psm1

-9
This file was deleted.

0 commit comments

Comments
 (0)