Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Commit

Permalink
[PLAT-26620] Log multiple instances of devbox to sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielrussoc committed Feb 1, 2021
1 parent eb0d7bb commit 62c03dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions devbox/common/src/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package devbox.common
import java.time.ZoneId
import java.time.format.{DateTimeFormatter, FormatStyle}

import io.sentry.event.Event

object Util {
val blockSize = 4 * 1024 * 1024

Expand Down Expand Up @@ -88,8 +90,13 @@ object Util {
}
.toMap
}

def sentryCapture(e: Throwable): Unit = {
io.sentry.Sentry.getContext().addTag("whoami", System.getProperty("user.name"))
io.sentry.Sentry.capture(e)
}

def sentryCapture(e: Event): Unit = {
io.sentry.Sentry.capture(e)
}
}
18 changes: 17 additions & 1 deletion launcher/src/Instance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import java.io.EOFException
import java.time.ZoneId
import java.time.format.DateTimeFormatter

import devbox.common.Util
import io.sentry.event.Event.Level
import io.sentry.event.EventBuilder
import software.amazon.awssdk.services.ec2.Ec2Client
import software.amazon.awssdk.services.ec2.model._

import scala.collection.JavaConverters._
import scala.collection.immutable.HashMap
import scala.concurrent.duration._

object Instance{
Expand Down Expand Up @@ -107,10 +111,22 @@ object Instance{
case _ => ???
}
case multiple =>
val event = new EventBuilder()
.withMessage("Multiple devbox instances running")
.withLevel(Level.WARNING)
.withTag("whoami", System.getProperty("user.name"))
val instanceOptions = multiple.zipWithIndex.map { case (instance, idx) =>
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z").withZone(ZoneId.systemDefault())
s"\t[${idx + 1}] ${instance.instanceId()} (${instance.placement().availabilityZone()}) launched at ${dateFormatter.format(instance.launchTime())}"
val launchTime = dateFormatter.format(instance.launchTime())
event.withExtra(s"instance-${idx}", Map(
"id" -> instance.instanceId,
"region" -> instance.placement().availabilityZone(),
"launchTime" -> launchTime,
"state" -> instance.state().nameAsString()
))
s"\t[${idx + 1}] ${instance.instanceId()} (${instance.placement().availabilityZone()}) launched at ${launchTime}"
}.mkString("\n")
Util.sentryCapture(event.build())
log(s"Multiple Devbox instances found. Which one would you like to keep? (enter 0 to discard all and get a new one)\n" + instanceOptions)
val chosen = readChoice(log)
val idsToDelete = (multiple.take(chosen) ++ multiple.drop(chosen + 1)).map(_.instanceId())
Expand Down

0 comments on commit 62c03dc

Please sign in to comment.