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

Add failure_issue_threshold & recovery_threshold to MonitorConfig #1685

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/MonitorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ final class MonitorConfig
*/
private $timezone;

/**
* @var int|null The number of consecutive failed check-ins it takes before an issue is created
*/
private $failureIssueThreshold;

/**
* @var int|null The number of consecutive OK check-ins it takes before an issue is resolved
*/
private $recoveryThreshold;

public function __construct(
MonitorSchedule $schedule,
?int $checkinMargin = null,
?int $maxRuntime = null,
?string $timezone = null
?string $timezone = null,
?int $failureIssueThreshold = null,
?int $recoveryThreshold = null
) {
$this->schedule = $schedule;
$this->checkinMargin = $checkinMargin;
$this->maxRuntime = $maxRuntime;
$this->timezone = $timezone;
$this->failureIssueThreshold = $failureIssueThreshold;
$this->recoveryThreshold = $recoveryThreshold;
}

public function getSchedule(): MonitorSchedule
Expand Down Expand Up @@ -86,6 +100,30 @@ public function setTimezone(?string $timezone): self
return $this;
}

public function getFailureRecoveryThreshold(): ?int
{
return $this->failureIssueThreshold;
}

public function setFailureRecoveryThreshold(?int $failureIssueThreshold): self
{
$this->failureIssueThreshold = $failureIssueThreshold;

return $this;
}

public function getRecoveryThreshold(): ?int
{
return $this->recoveryThreshold;
}

public function setRecoveryThreshold(?int $recoveryThreshold): self
{
$this->recoveryThreshold = $recoveryThreshold;

return $this;
}

/**
* @return array<string, mixed>
*/
Expand All @@ -96,6 +134,8 @@ public function toArray(): array
'checkin_margin' => $this->checkinMargin,
'max_runtime' => $this->maxRuntime,
'timezone' => $this->timezone,
'failure_issue_threshold' => $this->failureIssueThreshold,
'recovery_threshold' => $this->recoveryThreshold,
];
}
}
8 changes: 7 additions & 1 deletion tests/MonitorConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public function testConstructor(): void
MonitorSchedule::crontab('* * * * *'),
10,
12,
'Europe/Amsterdam'
'Europe/Amsterdam',
5,
10
);

$this->assertEquals($monitorSchedule, $monitorConfig->getSchedule());
$this->assertEquals(10, $monitorConfig->getCheckinMargin());
$this->assertEquals(12, $monitorConfig->getMaxRuntime());
$this->assertEquals('Europe/Amsterdam', $monitorConfig->getTimezone());
$this->assertEquals(5, $monitorConfig->getFailureRecoveryThreshold());
$this->assertEquals(10, $monitorConfig->getRecoveryThreshold());
}

/**
Expand All @@ -46,6 +50,8 @@ public static function gettersAndSettersDataProvider(): array
['getCheckinMargin', 'setCheckinMargin', 10],
['getMaxRuntime', 'setMaxRuntime', 12],
['getTimezone', 'setTimezone', 'Europe/Amsterdam'],
['getFailureRecoveryThreshold', 'setFailureRecoveryThreshold', 5],
['getRecoveryThreshold', 'setRecoveryThreshold', 10],
];
}
}
6 changes: 4 additions & 2 deletions tests/Serializer/PayloadSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ public static function serializeAsEnvelopeDataProvider(): iterable
MonitorSchedule::crontab('0 0 * * *'),
10,
12,
'Europe/Amsterdam'
'Europe/Amsterdam',
5,
10
)
);

Expand All @@ -406,7 +408,7 @@ public static function serializeAsEnvelopeDataProvider(): iterable
<<<TEXT
{"event_id":"fc9442f5aef34234bb22b9a615e30ccd","sent_at":"2020-08-18T22:47:15Z","dsn":"http:\/\/[email protected]\/sentry\/1","sdk":{"name":"sentry.php","version":"$sdkVersion"}}
{"type":"check_in","content_type":"application\/json"}
{"check_in_id":"$checkinId","monitor_slug":"my-monitor","status":"ok","duration":10,"release":"1.0.0","environment":"dev","monitor_config":{"schedule":{"type":"crontab","value":"0 0 * * *","unit":""},"checkin_margin":10,"max_runtime":12,"timezone":"Europe\/Amsterdam"},"contexts":{"trace":{"trace_id":"21160e9b836d479f81611368b2aa3d2c","span_id":"5dd538dc297544cc"}}}
{"check_in_id":"$checkinId","monitor_slug":"my-monitor","status":"ok","duration":10,"release":"1.0.0","environment":"dev","monitor_config":{"schedule":{"type":"crontab","value":"0 0 * * *","unit":""},"checkin_margin":10,"max_runtime":12,"timezone":"Europe\/Amsterdam","failure_issue_threshold":5,"recovery_threshold":10},"contexts":{"trace":{"trace_id":"21160e9b836d479f81611368b2aa3d2c","span_id":"5dd538dc297544cc"}}}
TEXT
,
false,
Expand Down