Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link to deployment log to grafana logger #1377

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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