Skip to content

Commit

Permalink
Merge pull request #1377 from guardian/grafana-annotation-urls
Browse files Browse the repository at this point in the history
Add link to deployment log to grafana logger
  • Loading branch information
jorgeazevedo authored Sep 23, 2024
2 parents c9e530e + d52f804 commit f901012
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion riff-raff/app/AppComponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class AppComponents(
deployments,
builds,
targetResolver,
new GrafanaAnnotationLogger,
new GrafanaAnnotationLogger(config.urls.publicPrefix),
hooksClient,
new SummariseDeploysHousekeeping(config, datastore),
continuousDeployment,
Expand Down
20 changes: 14 additions & 6 deletions riff-raff/app/notification/GrafanaAnnotationLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.logstash.logback.marker.Markers.appendEntries
import play.api.MarkerContext
import rx.lang.scala.Subscription

import java.util.UUID
import scala.jdk.CollectionConverters._

trait LogMarker {
Expand All @@ -18,27 +19,34 @@ trait LogMarker {
def markerContents: Map[String, Any]
}

class GrafanaAnnotationLogger extends Lifecycle with Logging {
class GrafanaAnnotationLogger(riffRaffUrl: String)
extends Lifecycle
with Logging {

val messageSub: Subscription = DeployReporter.messages.subscribe(message => {
val deployId = message.context.deployId
message.stack.top match {
case StartContext(Deploy(parameters)) =>
log.info("Started deploy")(buildMarker(parameters))
log.info("Started deploy")(buildMarker(deployId, parameters))
case FailContext(Deploy(parameters)) =>
log.info("Failed deploy")(buildMarker(parameters))
log.info("Failed deploy")(buildMarker(deployId, parameters))
case FinishContext(Deploy(parameters)) =>
log.info("Finished deploy")(buildMarker(parameters))
log.info("Finished deploy")(buildMarker(deployId, parameters))
case _ =>
}
})

private def buildMarker(parameters: DeployParameters): MarkerContext = {
private def buildMarker(
deployId: UUID,
parameters: DeployParameters
): MarkerContext = {
val params: Map[String, Any] =
Map(
"projectName" -> parameters.build.projectName,
"projectBuild" -> parameters.build.id,
"projectStage" -> parameters.stage.name,
"projectDeployer" -> parameters.deployer.name
"projectDeployer" -> parameters.deployer.name,
"projectDeploymentLink" -> s"<a target=\"_blank\" href=\"${riffRaffUrl}/deployment/view/$deployId\">${parameters.build.id}</a>"
)
MarkerContext(appendEntries(params.asJava))
}
Expand Down

0 comments on commit f901012

Please sign in to comment.