Skip to content

Commit

Permalink
Don't report sla 100 for a timeframe with no history events
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Feb 22, 2023
1 parent a53504f commit ffee32b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ protected function fetchReportData(DateTime $start, DateTime $end, array $config

$info = $objectInfo[$key];
if (
$report->sla === null
|| (
! $info->isFromBeforeInterval
&& count($timeline) <= 1
&& $slaWithBreakdown
$slaWithBreakdown
&& (
$report->sla === null
|| (
! $info->isFromBeforeInterval
&& count($timeline) <= 1
)
)
) {
// This is only the case when the object doesn't have any history events in a given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getResult(): float

$lastHardState = $this->initialHardState;
foreach ($this->events as $event) {
if ($event->previousHardState === 99) {
if ($event->previousHardState === 99 || ($lastHardState === 99 && $event->type !== static::STATE_CHANGE)) {
$totalTime -= $event->time - $lastEventTime;
} elseif (
(
Expand Down
13 changes: 13 additions & 0 deletions test/php/library/Icingadb/ProvidedHook/Reporting/SlaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ public function testIntermediatePendingStateReducesTotalTime()
$this->assertSame(60.0, $timeline->getResult());
}

public function testPendingStateAfterIntervalEndReducesTotalTime()
{
$this->insertSlaHistoryEvents([
'state' => [['event_time' => 2500000, 'hard_state' => 0, 'previous_hard_state' => 99]]
]);

$timeline = $this->report->getSlaTimeline($this->start, $this->end, 'host', $this->hostId);
$this->assertNull($timeline->getResult());

$timeline = $this->report->getSlaTimeline($this->start, $this->end, 'service', $this->serviceId);
$this->assertNull($timeline->getResult());
}

protected function makeId(): string
{
return random_bytes(20);
Expand Down

0 comments on commit ffee32b

Please sign in to comment.