-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
209 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/scala/org/broadinstitute/dsde/workbench/sam/metrics/ApiEvent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.broadinstitute.dsde.workbench.sam.metrics | ||
|
||
import akka.http.scaladsl.server.Rejection | ||
import net.logstash.logback.argument.{StructuredArgument, StructuredArguments} | ||
|
||
import java.util | ||
import scala.jdk.CollectionConverters._ | ||
|
||
trait ApiEvent extends MetricsLoggable { | ||
|
||
def event: String | ||
def request: RequestEventDetails | ||
def response: Option[ResponseEventDetails] = None | ||
def rejections: Seq[Rejection] = Seq() | ||
|
||
override def toLoggableMap: util.Map[String, Any] = | ||
toScalaMap.asJava | ||
|
||
protected def toScalaMap: Map[String, Any] = { | ||
val baseMap = Map[String, Any]( | ||
"event" -> event | ||
) + ("request" -> request.toLoggableMap) | ||
|
||
val responseMap = response.map(headers => baseMap + ("response" -> headers.toLoggableMap)).getOrElse(baseMap) | ||
|
||
if (rejections.isEmpty) { | ||
responseMap | ||
} else { | ||
responseMap + ("rejections" -> rejections.map(_.getClass.getSimpleName).asJava) | ||
} | ||
} | ||
|
||
def toStructuredArguments: StructuredArgument = | ||
StructuredArguments.keyValue("eventProperties", toLoggableMap) | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/scala/org/broadinstitute/dsde/workbench/sam/metrics/MetricsLoggable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.broadinstitute.dsde.workbench.sam.metrics | ||
|
||
trait MetricsLoggable { | ||
|
||
def toLoggableMap: java.util.Map[String, Any] | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/scala/org/broadinstitute/dsde/workbench/sam/metrics/RegisteredUserApiEvent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.broadinstitute.dsde.workbench.sam.metrics | ||
|
||
import akka.http.scaladsl.server.Rejection | ||
import org.broadinstitute.dsde.workbench.model.WorkbenchUserId | ||
|
||
import java.util | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class RegisteredUserApiEvent( | ||
samUserId: WorkbenchUserId, | ||
override val event: String, | ||
override val request: RequestEventDetails, | ||
override val response: Option[ResponseEventDetails] = None, | ||
override val rejections: Seq[Rejection] = Seq() | ||
) extends ApiEvent { | ||
|
||
override def toLoggableMap: util.Map[String, Any] = | ||
(super.toScalaMap + ("samUserId" -> samUserId.value)).asJava | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/scala/org/broadinstitute/dsde/workbench/sam/metrics/RequestEventDetails.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.broadinstitute.dsde.workbench.sam.metrics | ||
|
||
import akka.http.scaladsl.model.HttpRequest | ||
import org.broadinstitute.dsde.workbench.sam.api.OIDCHeaders | ||
|
||
import java.util | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class RequestEventDetails(httpRequest: HttpRequest, oidcHeaders: Option[OIDCHeaders]) extends MetricsLoggable { | ||
override def toLoggableMap: util.Map[String, Any] = { | ||
val baseMap = Map[String, Any]( | ||
"uri" -> httpRequest.uri.toString, | ||
"method" -> httpRequest.method.value | ||
) | ||
oidcHeaders.map(headers => (baseMap + ("oidcHeaders" -> headers.toLoggableMap)).asJava).getOrElse(baseMap.asJava) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/scala/org/broadinstitute/dsde/workbench/sam/metrics/ResponseEventDetails.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.broadinstitute.dsde.workbench.sam.metrics | ||
|
||
import akka.http.scaladsl.model.HttpResponse | ||
|
||
import java.util | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class ResponseEventDetails(httpResponse: HttpResponse) extends MetricsLoggable { | ||
override def toLoggableMap: util.Map[String, Any] = Map[String, Any]( | ||
"status" -> httpResponse.status.intValue | ||
).asJava | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/scala/org/broadinstitute/dsde/workbench/sam/metrics/UnregisteredUserApiEvent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.broadinstitute.dsde.workbench.sam.metrics | ||
|
||
import akka.http.scaladsl.server.Rejection | ||
|
||
case class UnregisteredUserApiEvent( | ||
override val event: String, | ||
override val request: RequestEventDetails, | ||
override val response: Option[ResponseEventDetails] = None, | ||
override val rejections: Seq[Rejection] = Seq() | ||
) extends ApiEvent |