Skip to content

Commit

Permalink
[TRELLO-2117] Implements probes to detect anomalies
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescd committed Jan 17, 2024
1 parent f77945b commit 43f20e9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
5 changes: 4 additions & 1 deletion app/config/TaskConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ case class TaskConfiguration(
reportClosure: ReportClosureTaskConfiguration,
reportReminders: ReportRemindersTaskConfiguration,
inactiveAccounts: InactiveAccountsTaskConfiguration,
companyUpdate: CompanyUpdateTaskConfiguration
companyUpdate: CompanyUpdateTaskConfiguration,
probe: ProbeConfiguration
)

case class SubscriptionTaskConfiguration(startTime: LocalTime, startDay: DayOfWeek)
Expand All @@ -38,3 +39,5 @@ case class ReportRemindersTaskConfiguration(
mailReminderDelay: Period // 7days.

)

case class ProbeConfiguration(active: Boolean)
39 changes: 22 additions & 17 deletions app/loader/SignalConsoApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -701,23 +701,28 @@ class SignalConsoComponents(
)

// Probes
val probeRepository = new ProbeRepository(dbConfig)
new LowRateReponseConsoTask(
actorSystem,
applicationConfiguration.task,
taskRepository,
probeRepository,
userRepository,
mailService
).schedule()
new LowRateLanceurDAlerteTask(
actorSystem,
applicationConfiguration.task,
taskRepository,
probeRepository,
userRepository,
mailService
).schedule()
if (applicationConfiguration.task.probe.active) {
logger.debug("Probes are enabled")
val probeRepository = new ProbeRepository(dbConfig)
new LowRateReponseConsoTask(
actorSystem,
applicationConfiguration.task,
taskRepository,
probeRepository,
userRepository,
mailService
).schedule()
new LowRateLanceurDAlerteTask(
actorSystem,
applicationConfiguration.task,
taskRepository,
probeRepository,
userRepository,
mailService
).schedule()
} else {
logger.debug("Probes are disabled")
}

// Routes
lazy val router: Router =
Expand Down
2 changes: 1 addition & 1 deletion app/tasks/probe/LowRateLanceurDAlerteTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LowRateLanceurDAlerteTask(
userRepository: UserRepositoryInterface,
mailService: MailService
)(implicit executionContext: ExecutionContext)
extends ScheduledTask(10, "low_rate_lanceur_dalerte", taskRepository, actorSystem, taskConfiguration) {
extends ScheduledTask(101, "low_rate_lanceur_dalerte", taskRepository, actorSystem, taskConfiguration) {

override val logger: Logger = Logger(this.getClass)
override val startTime: LocalTime = LocalTime.of(2, 0)
Expand Down
2 changes: 1 addition & 1 deletion app/tasks/probe/LowRateReponseConsoTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LowRateReponseConsoTask(
userRepository: UserRepositoryInterface,
mailService: MailService
)(implicit executionContext: ExecutionContext)
extends ScheduledTask(10, "low_rate_reponse_conso", taskRepository, actorSystem, taskConfiguration) {
extends ScheduledTask(100, "low_rate_reponse_conso", taskRepository, actorSystem, taskConfiguration) {

override val logger: Logger = Logger(this.getClass)
override val startTime: LocalTime = LocalTime.of(2, 0)
Expand Down
5 changes: 5 additions & 0 deletions conf/common/task.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ task {
etablissement-api-key = ${ETABLISSEMENT_API_KEY}
}

probe {
active = true
active = ${?SIGNAL_CONSO_SCHEDULED_PROBES_ACTIVE}
}

}
4 changes: 3 additions & 1 deletion test/tasks/report/ReportRemindersTaskUnitSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tasks.report

import akka.actor.testkit.typed.scaladsl.ActorTestKit
import config.ProbeConfiguration
import config.ReportRemindersTaskConfiguration
import config.TaskConfiguration
import models.company.AccessLevel
Expand Down Expand Up @@ -49,7 +50,8 @@ class ReportRemindersTaskUnitSpec extends Specification with FutureMatchers {
mailReminderDelay = Period.ofDays(7)
),
inactiveAccounts = null,
companyUpdate = null
companyUpdate = null,
probe = ProbeConfiguration(false)
)

val testKit = ActorTestKit()
Expand Down

0 comments on commit 43f20e9

Please sign in to comment.