Skip to content

Commit 9a1c187

Browse files
authored
Merge pull request #180 from Icinga:feature/split_thread_content_local_usage_only
Feature: Ensure thread results are separated from each other by default In case multitple background daemons are running and executing check plugins, it can happen that results overlap from one thread to another. A CPU check might then include information from another service check for example. We fix this by locking each check result data into an own thread, preventing other threads from accessing the data.
2 parents 4c859cf + b5d518d commit 9a1c187

7 files changed

+24
-43
lines changed

doc/31-Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ documentation before upgrading to a new release.
77

88
Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-framework/milestones?state=closed).
99

10-
## 1.4.0 (pending)
10+
## 1.4.0 (2021-03-02)
1111

1212
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/11?closed=1)
1313

1414
### Enhancements
1515

16+
* [#180](https://github.com/Icinga/icinga-powershell-framework/pull/180) Ensure check data are separated from each thread and not accessible from one thread to another to prevent conflicting results
1617
* [#193](https://github.com/Icinga/icinga-powershell-framework/pull/193) Adds optional support for adding milliseconds to `Get-IcingaUnixTime` with the `-Milliseconds` argument for more detailed time comparison
1718
* [#198](https://github.com/Icinga/icinga-powershell-framework/pull/198) Adds support to flush the content of the Icinga Agent API directory with a single Cmdlet `Clear-IcingaAgentApiDirectory`
1819
* [#203](https://github.com/Icinga/icinga-powershell-framework/pull/203) Removes experimental state of the Icinga PowerShell Framework code caching and adds docs on how to use the feature

lib/core/framework/Get-IcingaCheckSchedulerPerfData.psm1

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@
1717

1818
function Get-IcingaCheckSchedulerPerfData()
1919
{
20-
if ($null -eq $IcingaDaemonData) {
20+
if ($null -eq $global:Icinga) {
2121
return $null;
2222
}
2323

24-
if ($IcingaDaemonData.ContainsKey('IcingaThreadContent') -eq $FALSE) {
25-
return $null;
26-
}
27-
28-
if ($IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler') -eq $FALSE) {
29-
return $null;
30-
}
31-
32-
if ($IcingaDaemonData.IcingaThreadContent.Scheduler.ContainsKey('PluginPerfData') -eq $FALSE) {
33-
return $null;
34-
}
35-
36-
$PerfData = $IcingaDaemonData.IcingaThreadContent.Scheduler.PluginPerfData;
37-
$IcingaDaemonData.IcingaThreadContent.Scheduler.PluginPerfData = @();
24+
$PerfData = $global:Icinga.PerfData;
25+
$global:Icinga.PerfData = @();
3826

3927
return $PerfData;
4028
}

lib/core/framework/Get-IcingaCheckSchedulerPluginOutput.psm1

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@
1717

1818
function Get-IcingaCheckSchedulerPluginOutput()
1919
{
20-
if ($null -eq $IcingaDaemonData) {
20+
if ($null -eq $global:Icinga) {
2121
return $null;
2222
}
2323

24-
if ($IcingaDaemonData.ContainsKey('IcingaThreadContent') -eq $FALSE) {
25-
return $null;
26-
}
27-
28-
if ($IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler') -eq $FALSE) {
29-
return $null;
30-
}
31-
32-
if ($IcingaDaemonData.IcingaThreadContent.Scheduler.ContainsKey('PluginCache') -eq $FALSE) {
33-
return $null;
34-
}
35-
36-
$CheckResult = [string]::Join("`r`n", $IcingaDaemonData.IcingaThreadContent.Scheduler.PluginCache);
37-
$IcingaDaemonData.IcingaThreadContent.Scheduler.PluginCache = @();
24+
$CheckResult = [string]::Join("`r`n", $global:Icinga.CheckResults);
25+
$global:Icinga.CheckResults = @();
3826

3927
return $CheckResult;
4028
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
function New-IcingaCheckSchedulerEnvironment()
22
{
3+
# Legacy code
34
$IcingaDaemonData.IcingaThreadContent.Add('Scheduler', @{ });
4-
if ($IcingaDaemonData.IcingaThreadContent['Scheduler'].ContainsKey('PluginCache') -eq $FALSE) {
5-
$IcingaDaemonData.IcingaThreadContent['Scheduler'].Add('PluginCache', @());
6-
$IcingaDaemonData.IcingaThreadContent['Scheduler'].Add('PluginPerfData', @());
5+
6+
if ($null -eq $global:Icinga) {
7+
$global:Icinga = @{};
78
}
9+
10+
$global:Icinga.Add('CheckResults', @());
11+
$global:Icinga.Add('PerfData', @());
812
}

lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ function Start-IcingaServiceCheckTask()
101101
try {
102102
& $CheckCommand @Arguments | Out-Null;
103103

104+
Get-IcingaCheckSchedulerPerfData | Out-Null;
105+
Get-IcingaCheckSchedulerPluginOutput | Out-Null;
106+
104107
$UnixTime = Get-IcingaUnixTime;
105108

106109
foreach ($result in $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'].Keys) {

lib/icinga/plugin/Write-IcingaPluginOutput.psm1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ function Write-IcingaPluginOutput()
77
if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) {
88
Write-IcingaConsolePlain $Output;
99
} else {
10-
if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) {
11-
$global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginCache'] += $Output;
12-
}
10+
# New behavior with local thread separated results
11+
$global:Icinga.CheckResults += $Output;
1312
}
1413
}

lib/icinga/plugin/Write-IcingaPluginPerfData.psm1

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ function Get-IcingaPluginPerfDataContent()
4545
$cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value);
4646

4747
if ($AsObject) {
48-
if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) {
49-
$global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginPerfData'] += $cachedresult;
50-
}
48+
# New behavior with local thread separated results
49+
$global:Icinga.PerfData += $cachedresult;
5150
}
5251
$PerfDataOutput += $cachedresult;
5352
}
@@ -56,9 +55,8 @@ function Get-IcingaPluginPerfDataContent()
5655
$compiledPerfData = (New-IcingaPerformanceDataEntry $data);
5756

5857
if ($AsObject) {
59-
if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) {
60-
$global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginPerfData'] += $compiledPerfData;
61-
}
58+
# New behavior with local thread separated results
59+
$global:Icinga.PerfData += $compiledPerfData;
6260
}
6361
$PerfDataOutput += $compiledPerfData;
6462
}

0 commit comments

Comments
 (0)