From 5e04ee8e63c5617dbc4c2b9706b866e8823cec20 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Mon, 5 Feb 2024 17:37:10 +0100 Subject: [PATCH] Add new threshold parameters to monitor config (#3181) * add new threshold parameters to monitor config * add changelog * remove ctor overload in MonitorConfig, adapt tests --- CHANGELOG.md | 6 +++ sentry/api/sentry.api | 6 +++ .../main/java/io/sentry/MonitorConfig.java | 37 ++++++++++++++++++- .../io/sentry/CheckInSerializationTest.kt | 6 +++ .../java/io/sentry/util/CheckInUtilsTest.kt | 35 ++++++++++++++++++ .../test/resources/json/checkin_crontab.json | 4 +- .../test/resources/json/checkin_interval.json | 4 +- 7 files changed, 95 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c38d54c075..83d4886470 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Add new threshold parameters to monitor config ([#3181](https://github.com/getsentry/sentry-java/pull/3181)) + ## 7.3.0 ### Features diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 8dc0851098..03cd96ad0d 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -1004,13 +1004,17 @@ public final class io/sentry/MemoryCollectionData { public final class io/sentry/MonitorConfig : io/sentry/JsonSerializable, io/sentry/JsonUnknown { public fun (Lio/sentry/MonitorSchedule;)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 @@ -1024,7 +1028,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 ()V diff --git a/sentry/src/main/java/io/sentry/MonitorConfig.java b/sentry/src/main/java/io/sentry/MonitorConfig.java index c25884c2bd..faa391fcf9 100644 --- a/sentry/src/main/java/io/sentry/MonitorConfig.java +++ b/sentry/src/main/java/io/sentry/MonitorConfig.java @@ -15,7 +15,8 @@ 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 unknown; public MonitorConfig(final @NotNull MonitorSchedule schedule) { @@ -54,6 +55,22 @@ 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 { @@ -61,6 +78,8 @@ public static final class JsonKeys { 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 @@ -92,6 +111,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); @@ -111,6 +136,8 @@ public static final class Deserializer implements JsonDeserializer unknown = null; reader.beginObject(); @@ -129,6 +156,12 @@ public static final class Deserializer implements JsonDeserializer(); @@ -150,6 +183,8 @@ public static final class Deserializer implements JsonDeserializer + val hub = mock() + sentry.`when` { Sentry.getCurrentHub() }.thenReturn(hub) + val monitorConfig = MonitorConfig(MonitorSchedule.interval(7, MonitorScheduleUnit.DAY)).apply { + failureIssueThreshold = 10 + recoveryThreshold = 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() + } + } + } } diff --git a/sentry/src/test/resources/json/checkin_crontab.json b/sentry/src/test/resources/json/checkin_crontab.json index ee3bdf2ca9..8c39685878 100644 --- a/sentry/src/test/resources/json/checkin_crontab.json +++ b/sentry/src/test/resources/json/checkin_crontab.json @@ -14,7 +14,9 @@ }, "checkin_margin": 8, "max_runtime": 9, - "timezone": "Europe/Vienna" + "timezone": "Europe/Vienna", + "failure_issue_threshold": 10, + "recovery_threshold": 20 }, "contexts": { diff --git a/sentry/src/test/resources/json/checkin_interval.json b/sentry/src/test/resources/json/checkin_interval.json index b404d610c6..8281ca67ab 100644 --- a/sentry/src/test/resources/json/checkin_interval.json +++ b/sentry/src/test/resources/json/checkin_interval.json @@ -15,7 +15,9 @@ }, "checkin_margin": 8, "max_runtime": 9, - "timezone": "Europe/Vienna" + "timezone": "Europe/Vienna", + "failure_issue_threshold": 10, + "recovery_threshold": 20 }, "contexts": {