From b9d3a7c3e04b874ff7e487f36eec78b9eb4af361 Mon Sep 17 00:00:00 2001 From: Corey Woodfield Date: Wed, 6 Mar 2024 13:24:28 -0700 Subject: [PATCH] PROD-2562 Get rid of Medium monitoring priority Any existing medium priorities will be interpreted as Low going forward --- .../admin/controllers/TriggerHelper.scala | 4 ++-- .../piezo/admin/controllers/Triggers.scala | 14 ++++++-------- .../piezo/admin/views/editTrigger.scala.html | 2 +- .../piezo/TriggerMonitoringModel.scala | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/admin/app/com/lucidchart/piezo/admin/controllers/TriggerHelper.scala b/admin/app/com/lucidchart/piezo/admin/controllers/TriggerHelper.scala index bc1d27b..a328e9a 100644 --- a/admin/app/com/lucidchart/piezo/admin/controllers/TriggerHelper.scala +++ b/admin/app/com/lucidchart/piezo/admin/controllers/TriggerHelper.scala @@ -54,7 +54,7 @@ object TriggerHelper { trigger.getKey, ).map { monitoringRecord => (monitoringRecord.priority, monitoringRecord.maxSecondsInError) - }.getOrElse((TriggerMonitoringPriority.Medium, 300)) + }.getOrElse((TriggerMonitoringPriority.Low, 300)) val jobDataMap = trigger.getJobDataMap val job = trigger.getJobKey Json.obj( @@ -65,7 +65,7 @@ object TriggerHelper { "name" -> triggerKey.getName, "description" -> trigger.getDescription, "job-data-map" -> JsObject(jobDataMap.getKeys.toSeq.map(key => key -> JsString(jobDataMap.getString(key)))), - "triggerMonitoringPriority" -> monitoringPriority.toString, + "triggerMonitoringPriority" -> monitoringPriority.name, "triggerMaxErrorTime" -> maxSecondsInError ) ++ schedule } diff --git a/admin/app/com/lucidchart/piezo/admin/controllers/Triggers.scala b/admin/app/com/lucidchart/piezo/admin/controllers/Triggers.scala index 65615b7..bfa9322 100644 --- a/admin/app/com/lucidchart/piezo/admin/controllers/Triggers.scala +++ b/admin/app/com/lucidchart/piezo/admin/controllers/Triggers.scala @@ -73,10 +73,10 @@ class Triggers(schedulerFactory: WorkerSchedulerFactory, cc: ControllerComponent triggerDetail.getKey ).map { triggerMonitoringRecord => (triggerMonitoringRecord.priority, triggerMonitoringRecord.maxSecondsInError) - }.getOrElse((TriggerMonitoringPriority.Medium, 300)) + }.getOrElse((TriggerMonitoringPriority.Low, 300)) }.getOrElse { logger.error("Failed to get trigger monitoring info") - (TriggerMonitoringPriority.Medium, 300) + (TriggerMonitoringPriority.Low, 300) } Ok( @@ -149,9 +149,7 @@ class Triggers(schedulerFactory: WorkerSchedulerFactory, cc: ControllerComponent jobGroup: String = "", jobName: String = "", templateGroup: Option[String] = None, - templateName: Option[String] = None, - triggerMonitoringPriority: TriggerMonitoringPriority.Value = TriggerMonitoringPriority.Medium, - triggerMaxErrorTime: Int = 300 + templateName: Option[String] = None ) = Action { implicit request => templateGroup match { case Some(group) => getEditTrigger(group, templateName.get, true) @@ -161,7 +159,7 @@ class Triggers(schedulerFactory: WorkerSchedulerFactory, cc: ControllerComponent case "simple" => new DummySimpleTrigger(jobGroup, jobName) } val newTriggerForm = triggerFormHelper.buildTriggerForm.fill( - (dummyTrigger, TriggerMonitoringPriority.Medium, 300) + (dummyTrigger, TriggerMonitoringPriority.Low, 300) ) Ok( com.lucidchart.piezo.admin.views.html.editTrigger( @@ -189,10 +187,10 @@ class Triggers(schedulerFactory: WorkerSchedulerFactory, cc: ControllerComponent triggerDetail.getKey, ).map { triggerMonitoringRecord => (triggerMonitoringRecord.priority, triggerMonitoringRecord.maxSecondsInError) - }.getOrElse((TriggerMonitoringPriority.Medium, 300)) + }.getOrElse((TriggerMonitoringPriority.Low, 300)) }.getOrElse { logger.error("Failed to get trigger monitoring info") - (TriggerMonitoringPriority.Medium, 300) + (TriggerMonitoringPriority.Low, 300) } val editTriggerForm = triggerFormHelper.buildTriggerForm.fill( (triggerDetail, triggerMonitoringPriority, triggerMaxErrorTime) diff --git a/admin/app/com/lucidchart/piezo/admin/views/editTrigger.scala.html b/admin/app/com/lucidchart/piezo/admin/views/editTrigger.scala.html index c217831..a10f1af 100644 --- a/admin/app/com/lucidchart/piezo/admin/views/editTrigger.scala.html +++ b/admin/app/com/lucidchart/piezo/admin/views/editTrigger.scala.html @@ -66,7 +66,7 @@

@triggerForm.errors.filter(_.key == "").map(_.message).m } } - @helper.select(triggerForm("triggerMonitoringPriority"), TriggerMonitoringPriority.values.toList.map(tp => tp.toString -> tp.toString), Symbol("_label") -> "Monitoring Priority", Symbol("labelClass") -> "col-sm-2 text-right", Symbol("inputDivClass") -> "col-sm-4", Symbol("class") -> "form-control", Symbol("value") -> triggerForm.data.get("triggerMonitoringPriority").getOrElse(TriggerMonitoringPriority.Medium), Symbol("placeholder") -> TriggerMonitoringPriority.Medium) + @helper.select(triggerForm("triggerMonitoringPriority"), TriggerMonitoringPriority.values.map(tp => tp.name -> tp.name), Symbol("_label") -> "Monitoring Priority", Symbol("labelClass") -> "col-sm-2 text-right", Symbol("inputDivClass") -> "col-sm-4", Symbol("class") -> "form-control", Symbol("value") -> triggerForm.data.get("triggerMonitoringPriority").getOrElse(TriggerMonitoringPriority.Low), Symbol("placeholder") -> TriggerMonitoringPriority.Low) @helper.input(triggerForm("triggerMaxErrorTime"), Symbol("_label") -> "Monitoring - Max Seconds Between Successes", Symbol("labelClass") -> "col-sm-2 text-right", Symbol("inputDivClass") -> "col-sm-4", Symbol("placeholder") -> "", Symbol("value") -> triggerForm.data.get("triggerMaxErrorTime").getOrElse(300)) { (id, name, value, args) => } diff --git a/worker/src/main/scala/com/lucidchart/piezo/TriggerMonitoringModel.scala b/worker/src/main/scala/com/lucidchart/piezo/TriggerMonitoringModel.scala index 302acea..a0d2f3e 100644 --- a/worker/src/main/scala/com/lucidchart/piezo/TriggerMonitoringModel.scala +++ b/worker/src/main/scala/com/lucidchart/piezo/TriggerMonitoringModel.scala @@ -5,12 +5,22 @@ import java.util.{Date, Properties} import org.quartz.TriggerKey import org.slf4j.LoggerFactory -object TriggerMonitoringPriority extends Enumeration { +object TriggerMonitoringPriority { + case class Value(id: Int, name: String) { + override def toString: String = name + } type TriggerMonitoringPriority = Value val Off = Value(0, "Off") val Low = Value(1, "Low") - val Medium = Value(2, "Medium") val High = Value(3, "High") + + val values = List(Off, Low, High) + + // map values that formerly identified a Medium priority to Low + val valuesById: Map[Int, Value] = Map(2 -> Low) ++ values.map(p => p.id -> p) + val valuesByName: Map[String, Value] = Map("Medium" -> Low) ++ values.map(p => p.name -> p) + + def withName: Function[String, Value] = valuesByName } case class TriggerMonitoringRecord ( @@ -101,7 +111,7 @@ class TriggerMonitoringModel(props: Properties) { prepared.setString(2, triggerKey.getGroup) val rs = prepared.executeQuery() if (rs.next()) { - TriggerMonitoringPriority.values.find(_.id == rs.getInt("priority")).map { priority => + TriggerMonitoringPriority.valuesById.get(rs.getInt("priority")).map { priority => TriggerMonitoringRecord( rs.getString("trigger_name"), rs.getString("trigger_group"), @@ -127,4 +137,4 @@ class TriggerMonitoringModel(props: Properties) { connection.close() } } -} \ No newline at end of file +}