Skip to content

Commit

Permalink
Merge 2576c5a into 2aba155
Browse files Browse the repository at this point in the history
  • Loading branch information
lbloder authored Feb 1, 2024
2 parents 2aba155 + 2576c5a commit 26a1b06
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 3 deletions.
7 changes: 7 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -1003,14 +1003,19 @@ public final class io/sentry/MemoryCollectionData {

public final class io/sentry/MonitorConfig : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/MonitorSchedule;)V
public fun <init> (Lio/sentry/MonitorSchedule;Ljava/lang/Long;Ljava/lang/Long;)V
public fun getCheckinMargin ()Ljava/lang/Long;
public fun getFailureIssueThreshold ()Ljava/lang/Long;
public fun getMaxRuntime ()Ljava/lang/Long;
public fun getRecoveryThreshold ()Ljava/lang/Long;
public fun getSchedule ()Lio/sentry/MonitorSchedule;
public fun getTimezone ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public fun setCheckinMargin (Ljava/lang/Long;)V
public fun setFailureIssueThreshold (Ljava/lang/Long;)V
public fun setMaxRuntime (Ljava/lang/Long;)V
public fun setRecoveryThreshold (Ljava/lang/Long;)V
public fun setSchedule (Lio/sentry/MonitorSchedule;)V
public fun setTimezone (Ljava/lang/String;)V
public fun setUnknown (Ljava/util/Map;)V
Expand All @@ -1024,7 +1029,9 @@ public final class io/sentry/MonitorConfig$Deserializer : io/sentry/JsonDeserial

public final class io/sentry/MonitorConfig$JsonKeys {
public static final field CHECKIN_MARGIN Ljava/lang/String;
public static final field FAILURE_ISSUE_THRESHOLD Ljava/lang/String;
public static final field MAX_RUNTIME Ljava/lang/String;
public static final field RECOVERY_THRESHOLD Ljava/lang/String;
public static final field SCHEDULE Ljava/lang/String;
public static final field TIMEZONE Ljava/lang/String;
public fun <init> ()V
Expand Down
46 changes: 45 additions & 1 deletion sentry/src/main/java/io/sentry/MonitorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ public final class MonitorConfig implements JsonUnknown, JsonSerializable {
private @Nullable Long checkinMargin;
private @Nullable Long maxRuntime;
private @Nullable String timezone;

private @Nullable Long failureIssueThreshold;
private @Nullable Long recoveryThreshold;
private @Nullable Map<String, Object> unknown;

public MonitorConfig(final @NotNull MonitorSchedule schedule) {
this.schedule = schedule;
}

public MonitorConfig(
final @NotNull MonitorSchedule schedule,
@Nullable Long failureIssueThreshold,
@Nullable Long recoveryThreshold) {
this.schedule = schedule;
this.failureIssueThreshold = failureIssueThreshold;
this.recoveryThreshold = recoveryThreshold;
}

public @NotNull MonitorSchedule getSchedule() {
return schedule;
}
Expand Down Expand Up @@ -54,13 +64,31 @@ public void setTimezone(@Nullable String timezone) {
this.timezone = timezone;
}

public @Nullable Long getFailureIssueThreshold() {
return failureIssueThreshold;
}

public void setFailureIssueThreshold(@Nullable Long failureIssueThreshold) {
this.failureIssueThreshold = failureIssueThreshold;
}

public @Nullable Long getRecoveryThreshold() {
return recoveryThreshold;
}

public void setRecoveryThreshold(@Nullable Long recoveryThreshold) {
this.recoveryThreshold = recoveryThreshold;
}

// JsonKeys

public static final class JsonKeys {
public static final String SCHEDULE = "schedule";
public static final String CHECKIN_MARGIN = "checkin_margin";
public static final String MAX_RUNTIME = "max_runtime";
public static final String TIMEZONE = "timezone";
public static final String FAILURE_ISSUE_THRESHOLD = "failure_issue_threshold";
public static final String RECOVERY_THRESHOLD = "recovery_threshold";
}

// JsonUnknown
Expand Down Expand Up @@ -92,6 +120,12 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
if (timezone != null) {
writer.name(JsonKeys.TIMEZONE).value(timezone);
}
if (failureIssueThreshold != null) {
writer.name(JsonKeys.FAILURE_ISSUE_THRESHOLD).value(failureIssueThreshold);
}
if (recoveryThreshold != null) {
writer.name(JsonKeys.RECOVERY_THRESHOLD).value(recoveryThreshold);
}
if (unknown != null) {
for (String key : unknown.keySet()) {
Object value = unknown.get(key);
Expand All @@ -111,6 +145,8 @@ public static final class Deserializer implements JsonDeserializer<MonitorConfig
Long checkinMargin = null;
Long maxRuntime = null;
String timezone = null;
Long failureIssureThreshold = null;
Long recoveryThreshold = null;
Map<String, Object> unknown = null;

reader.beginObject();
Expand All @@ -129,6 +165,12 @@ public static final class Deserializer implements JsonDeserializer<MonitorConfig
case JsonKeys.TIMEZONE:
timezone = reader.nextStringOrNull();
break;
case JsonKeys.FAILURE_ISSUE_THRESHOLD:
failureIssureThreshold = reader.nextLongOrNull();
break;
case JsonKeys.RECOVERY_THRESHOLD:
recoveryThreshold = reader.nextLongOrNull();
break;
default:
if (unknown == null) {
unknown = new HashMap<>();
Expand All @@ -150,6 +192,8 @@ public static final class Deserializer implements JsonDeserializer<MonitorConfig
monitorConfig.setCheckinMargin(checkinMargin);
monitorConfig.setMaxRuntime(maxRuntime);
monitorConfig.setTimezone(timezone);
monitorConfig.setFailureIssueThreshold(failureIssureThreshold);
monitorConfig.setRecoveryThreshold(recoveryThreshold);
monitorConfig.setUnknown(unknown);
return monitorConfig;
}
Expand Down
6 changes: 6 additions & 0 deletions sentry/src/test/java/io/sentry/CheckInSerializationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class CheckInSerializationTest {
checkinMargin = 8L
maxRuntime = 9L
timezone = ZoneId.of("Europe/Vienna").id
failureIssueThreshold = 10
recoveryThreshold = 20
}
}
}
Expand Down Expand Up @@ -90,6 +92,8 @@ class CheckInSerializationTest {
assertEquals(expectedConfig.maxRuntime, actualConfig.maxRuntime)
assertEquals(expectedConfig.checkinMargin, actualConfig.checkinMargin)
assertEquals(expectedConfig.timezone, actualConfig.timezone)
assertEquals(expectedConfig.failureIssueThreshold, actualConfig.failureIssueThreshold)
assertEquals(expectedConfig.recoveryThreshold, actualConfig.recoveryThreshold)
assertEquals(expectedSchedule.type, actualSchedule.type)
assertEquals(expectedSchedule.value, actualSchedule.value)
assertEquals(expectedSchedule.unit, actualSchedule.unit)
Expand All @@ -116,6 +120,8 @@ class CheckInSerializationTest {
assertEquals(expectedConfig.maxRuntime, actualConfig.maxRuntime)
assertEquals(expectedConfig.checkinMargin, actualConfig.checkinMargin)
assertEquals(expectedConfig.timezone, actualConfig.timezone)
assertEquals(expectedConfig.failureIssueThreshold, actualConfig.failureIssueThreshold)
assertEquals(expectedConfig.recoveryThreshold, actualConfig.recoveryThreshold)
assertEquals(expectedSchedule.type, actualSchedule.type)
assertEquals(expectedSchedule.value, actualSchedule.value)
assertEquals(expectedSchedule.unit, actualSchedule.unit)
Expand Down
32 changes: 32 additions & 0 deletions sentry/src/test/java/io/sentry/util/CheckInUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,36 @@ class CheckInUtilsTest {
}
}
}

@Test
fun `sends check-in for wrapped supplier with upsert and thresholds`() {
Mockito.mockStatic(Sentry::class.java).use { sentry ->
val hub = mock<IHub>()
sentry.`when`<Any> { Sentry.getCurrentHub() }.thenReturn(hub)
val monitorConfig = MonitorConfig(MonitorSchedule.interval(7, MonitorScheduleUnit.DAY), 10, 20)
val returnValue = CheckInUtils.withCheckIn("monitor-1", monitorConfig) {
"test1"
}

assertEquals("test1", returnValue)
inOrder(hub) {
verify(hub).pushScope()
verify(hub).configureScope(any())
verify(hub).captureCheckIn(
check {
assertEquals("monitor-1", it.monitorSlug)
assertSame(monitorConfig, it.monitorConfig)
assertEquals(CheckInStatus.IN_PROGRESS.apiName(), it.status)
}
)
verify(hub).captureCheckIn(
check {
assertEquals("monitor-1", it.monitorSlug)
assertEquals(CheckInStatus.OK.apiName(), it.status)
}
)
verify(hub).popScope()
}
}
}
}
4 changes: 3 additions & 1 deletion sentry/src/test/resources/json/checkin_crontab.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
},
"checkin_margin": 8,
"max_runtime": 9,
"timezone": "Europe/Vienna"
"timezone": "Europe/Vienna",
"failure_issue_threshold": 10,
"recovery_threshold": 20
},
"contexts":
{
Expand Down
4 changes: 3 additions & 1 deletion sentry/src/test/resources/json/checkin_interval.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
},
"checkin_margin": 8,
"max_runtime": 9,
"timezone": "Europe/Vienna"
"timezone": "Europe/Vienna",
"failure_issue_threshold": 10,
"recovery_threshold": 20
},
"contexts":
{
Expand Down

0 comments on commit 26a1b06

Please sign in to comment.