Skip to content

Commit

Permalink
Merge pull request #947 from hmrc/BDOG-3210
Browse files Browse the repository at this point in the history
BDOG-3210 gather deployment changes from config changes api
  • Loading branch information
Shnick authored Sep 20, 2024
2 parents b7ccdb9 + 5663ad4 commit a79d99b
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ class DeployServiceController @Inject()(
.recover:
case NonFatal(ex) => logger.error(s"Could not call git compare ${ex.getMessage}", ex); None
jvmChanges = (currentSlug.map(_.java), slugToDeploy.java)
deploymentChanges <- EitherT
.right[Result](serviceConfigsService.deploymentConfigChanges(formObject.serviceName, formObject.environment))
configChanges <- EitherT
.right[Result](serviceConfigsService.configChangesNextDeployment(formObject.serviceName, formObject.environment, formObject.version))
configWarnings <- EitherT
Expand All @@ -190,7 +188,7 @@ class DeployServiceController @Inject()(
latest,
releases,
environments,
Some((gitHubCompare, jvmChanges, deploymentChanges, configChanges, configWarnings, vulnerabilities))
Some((gitHubCompare, jvmChanges, configChanges, configWarnings, vulnerabilities))
))
).merge
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ class DeploymentGraphService @Inject() (
.get(timelineEvent.deploymentId)
.fold(timelineEvent): configEvent =>
timelineEvent.copy(
configChanged = configEvent.configChanged,
configId = configEvent.configId
configChanged = configEvent.configChanged,
deploymentConfigChanged = configEvent.deploymentConfigChanged,
configId = configEvent.configId
)

object DeploymentGraphService:

val notDeployedMessage = "Not Deployed"
val notDeployedMessage = "Not Deployed" // Note this version also exists in releases-api for un-deployment events

// generates a placeholder timeline event so that the timeline still shows the environment but with nothing deployed in it
def noEventsPlaceholder(env: String, start: Instant, end: Instant): Seq[DeploymentTimelineEvent] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package uk.gov.hmrc.cataloguefrontend.deployments

import cats.data.OptionT
import cats.implicits._
import play.api.Logging
import play.api.mvc._
Expand Down Expand Up @@ -82,18 +83,19 @@ class DeploymentTimelineController @Inject()(
def graphSelect(serviceName: ServiceName, deploymentId: String, fromDeploymentId: Option[String]) =
BasicAuthAction.async:
implicit request =>
for
configChanges <- serviceConfigsService.configChanges(deploymentId, fromDeploymentId)
previousVersion = configChanges.fromVersion.getOrElse(Version("0.1.0"))
deployedVersion = configChanges.toVersion
(for
configChanges <- OptionT(serviceConfigsService.configChanges(deploymentId, fromDeploymentId))
previousVersion = configChanges.app.from.getOrElse(Version("0.1.0"))
deployedVersion = configChanges.app.to
environment = configChanges.env.environment
deployedSlug <- serviceDependenciesConnector.getSlugInfo(serviceName, Some(deployedVersion))
previousSlug <- serviceDependenciesConnector.getSlugInfo(serviceName, Some(previousVersion))
gitHubCompare <- gitHubProxyConnector
.compare(serviceName.asString, v1 = previousVersion, v2 = deployedVersion)
.recover:
case NonFatal(ex) => logger.error(s"Could not call git compare ${ex.getMessage}", ex); None
jvmChanges = (previousSlug.map(_.java), deployedSlug.get.java)
deploymentChanges <- serviceConfigsService.deploymentConfigChanges(serviceName, environment)
deployedSlug <- OptionT(serviceDependenciesConnector.getSlugInfo(serviceName, Some(deployedVersion)))
oPreviousSlug <- OptionT.liftF(serviceDependenciesConnector.getSlugInfo(serviceName, Some(previousVersion)))
oGitHubCompare <- OptionT.liftF:
gitHubProxyConnector
.compare(serviceName.asString, v1 = previousVersion, v2 = deployedVersion)
.recover:
case NonFatal(ex) => logger.error(s"Could not call git compare ${ex.getMessage}", ex); None
jvmChanges = (oPreviousSlug.map(_.java), deployedSlug.java)
yield
Ok(deploymentTimelineSelectPage(serviceName, environment, Some(previousVersion), deployedVersion, gitHubCompare, jvmChanges, deploymentChanges, configChanges))
Ok(deploymentTimelineSelectPage(serviceName, environment, Some(previousVersion), deployedVersion, oGitHubCompare, jvmChanges, configChanges))
).getOrElse(NotFound("Could not compare deployments - data not found or initial deployment"))
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@import uk.gov.hmrc.cataloguefrontend.connector.GitHubProxyConnector
@import uk.gov.hmrc.cataloguefrontend.deployments.{DeployServiceForm, routes => appRoutes}
@import uk.gov.hmrc.cataloguefrontend.service.ServiceJdkVersion
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.{ConfigChanges, ConfigChange, DeploymentConfigChange, ServiceConfigsService}
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.{ConfigChanges, ServiceConfigsService}
@import uk.gov.hmrc.cataloguefrontend.vulnerabilities.VulnerabilitySummary
@import uk.gov.hmrc.cataloguefrontend.whatsrunningwhere.WhatsRunningWhereVersion
@import views.html.helper.{FieldConstructor, select}
Expand All @@ -33,7 +33,6 @@
, evaluations : Option[(
Option[GitHubProxyConnector.Compare]
, (Option[ServiceJdkVersion], ServiceJdkVersion)
, Seq[DeploymentConfigChange]
, ConfigChanges
, Seq[ServiceConfigsService.ConfigWarning]
, Option[Seq[VulnerabilitySummary]]
Expand Down Expand Up @@ -119,7 +118,7 @@ <h1 class="page-heading mt-4">Deploy Service</h1>
</div>
</div>
<div class="col-md-8">
@evaluations.map { case (oGitHubCompare, jvmChanges, deploymentConfigChanges, configChanges, configWarnings, oVulnerabilities) =>
@evaluations.map { case (oGitHubCompare, jvmChanges, configChanges, configWarnings, oVulnerabilities) =>
<div class="alert @if(form.get.environment == Environment.Production) {alert-danger} else {alert-warning}">
You are about to deploy <strong>@form.get.serviceName.asString:@form.get.version</strong> into <strong>@form.get.environment.displayString</strong>
@if(releases.isEmpty || !releases.map(_.environment).contains(form.get.environment)) {
Expand All @@ -136,7 +135,6 @@ <h1 class="page-heading mt-4">Deploy Service</h1>
, deployedVersion = form.get.version
, oGitHubCompare = oGitHubCompare
, jvmChanges = jvmChanges
, deploymentConfigChanges = deploymentConfigChanges
, configChanges = configChanges
, configWarnings = configWarnings
, oVulnerabilities = oVulnerabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
}
} else {
<textarea id="deploymentRows" style="width: 100%;display: none;">@events.map(e => s"${e.deploymentId},${e.version.original},${e.env.displayString},${e.userName},${e.displayStart.getOrElse(e.start).displayFormat},${e.displayEnd.getOrElse(e.end).displayFormat}").mkString("\n")</textarea>
<div id="history-chart" style="height: 260px;"></div>
<p id="historyChartHelp" style="display: none;" class="text-center">Click on a segment to see more info on changes</p>
<div id="historyChart" style="height: 260px;"></div>
<div id="deploymentSpinner" style="display: none" class="text-center">
<div class="spinner-border text-secondary" role="status">
<span class="visually-hidden">Loading...</span>
Expand Down Expand Up @@ -143,7 +144,9 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
@{java.time.Duration.between(e.displayStart.getOrElse(e.start), e.displayEnd.getOrElse(e.end)).toDays},
'@{slugInfo.find(_.version == e.version).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString}")}',
'@previousJavaVersion(e.env, e.deploymentId, events, slugInfo)',
'@{e.configChanged.getOrElse("undefined")}'
'@{e.deploymentConfigChanged.getOrElse("")}',
'@{e.configChanged.getOrElse("")}',

),
'@colorForVersion(e.version.toString)',
new Date(@{e.start.toEpochMilli}),
Expand All @@ -152,7 +155,7 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
];

let options = {tooltip: { isHtml: true }, enableInteractivity: true};
let container = document.getElementById('history-chart');
let container = document.getElementById('historyChart');
if (container == null) return
let chart = new google.visualization.Timeline(container);
let dataTable = new google.visualization.DataTable();
Expand All @@ -166,6 +169,8 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
dataTable.addRows(data);
chart.draw(dataTable, options);

document.getElementById('historyChartHelp').style.display = "";

const deploymentSpinner = document.getElementById("deploymentSpinner");
const deploymentInfo = document.getElementById("deploymentInfo");
const deploymentHeading = document.getElementById("deploymentInfoHeading");
Expand All @@ -184,12 +189,12 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
const deploymentEnd = deploymentRow[5];
const fromDeployment = deploymentRows[segmentIndex - 1];

deploymentHeading.innerHTML = `<code>${deploymentVersion}</code> was deployed in <strong>${deploymentEnv}</strong> by <a href="${usersTemplateUrl.replace("PLACEHOLDER", deploymentUser)}">${deploymentUser}</a> - ${deploymentStart} to ${deploymentEnd}`
deploymentHeading.innerHTML = `<code>${deploymentVersion}</code> was deployed in <strong>${deploymentEnv}</strong> by <a href="${usersTemplateUrl.replace("PLACEHOLDER", deploymentUser)}">${deploymentUser}</a> <br/> ${deploymentStart} to ${deploymentEnd}`

if (deploymentId) {
if (deploymentId && deploymentVersion != "@DeploymentGraphService.notDeployedMessage") {
const onSelectUrl =
fromDeployment && deploymentId.substring(0, deploymentId.lastIndexOf('-')) == fromDeployment[0].substring(0, fromDeployment[0].lastIndexOf('-')) ?
`deployment-timeline-select/@service.fold("")(_.asString)?deploymentId=${deploymentId}&fromDeploymentId=${fromDeployment[0]}`:
fromDeployment && fromDeployment.split(",")[2] === deploymentEnv ?
`deployment-timeline-select/@service.fold("")(_.asString)?deploymentId=${deploymentId}&fromDeploymentId=${fromDeployment.split(",")[0]}`:
`deployment-timeline-select/@service.fold("")(_.asString)?deploymentId=${deploymentId}`;

deploymentSpinner.style.display = '';
Expand All @@ -209,14 +214,7 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
});
}

function makeToolTip(ver, user, start, end, days, java, previousJava, configChanged) {
let javaVersionChange = (java !== previousJava) ? `Changed from ${previousJava} to ${java}` : `${java}`;
let configChangeRow = '';

if (configChanged !== "undefined") {
configChangeRow = `<tr><th class="text-dark">Config Changed</th><td>${configChanged === "true" ? 'Yes' : 'No'}</td></tr>`;
}
function makeToolTip(ver, user, start, end, days, java, previousJava, deploymentConfigChanged, configChanged) {
if (ver === "@DeploymentGraphService.notDeployedMessage") {
return `<div class="timeline-tooltip">No deployment events found in this date range</div>`
}
Expand All @@ -226,8 +224,9 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
<tr><th class="text-dark">By</th><td>${user}</td></tr>
<tr><th class="text-dark">From</th><td>${start} UTC</td></tr>
<tr><th class="text-dark">To</th><td>${end} UTC</td></tr>
<tr><th class="text-dark">Java</th><td>${javaVersionChange}</td></tr>
${configChangeRow}
<tr><th class="text-dark">Java</th><td>${(java !== previousJava) ? `Changed from ${previousJava} to ${java}` : `${java}`}</td></tr>
${deploymentConfigChanged ? `<tr><th class="text-dark">Deployment Config Changed</th><td>${deploymentConfigChanged === "true" ? 'Yes' : 'No'}</td></tr>`: ''}
${configChanged ? `<tr><th class="text-dark">Config Changed</th><td>${configChanged === "true" ? 'Yes' : 'No'}</td></tr>`: ''}
</table>
</div>`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@import uk.gov.hmrc.cataloguefrontend.connector.GitHubProxyConnector
@import uk.gov.hmrc.cataloguefrontend.service.ServiceJdkVersion
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.{ConfigChanges, DeploymentConfigChange }
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.ConfigChanges

@this()

Expand All @@ -27,7 +27,6 @@
, deployedVersion : Version
, oGitHubCompare : Option[GitHubProxyConnector.Compare]
, jvmChanges : (Option[ServiceJdkVersion], ServiceJdkVersion)
, deploymentConfigChanges: Seq[DeploymentConfigChange]
, configChanges : ConfigChanges
)(implicit request: Request[_])

Expand All @@ -40,7 +39,6 @@
, deployedVersion = deployedVersion
, oGitHubCompare = oGitHubCompare
, jvmChanges = jvmChanges
, deploymentConfigChanges = deploymentConfigChanges
, configChanges = configChanges
, showConfigWarnings = false
, showVulnerabilities = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@import uk.gov.hmrc.cataloguefrontend.connector.GitHubProxyConnector
@import uk.gov.hmrc.cataloguefrontend.service.ServiceJdkVersion
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.{ConfigChanges, ConfigChange, DeploymentConfigChange, ServiceConfigsService, routes => serviceConfigsRoutes }
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.{ConfigChanges, ConfigChange, ServiceConfigsService, routes => serviceConfigsRoutes }
@import uk.gov.hmrc.cataloguefrontend.vulnerabilities.VulnerabilitySummary
@import uk.gov.hmrc.cataloguefrontend.vulnerabilities.view.html.VulnerabilityDetails

Expand All @@ -27,7 +27,6 @@
, deployedVersion : Version
, oGitHubCompare : Option[GitHubProxyConnector.Compare]
, jvmChanges : (Option[ServiceJdkVersion], ServiceJdkVersion)
, deploymentConfigChanges : Seq[DeploymentConfigChange]
, configChanges : ConfigChanges
, configWarnings : Seq[ServiceConfigsService.ConfigWarning] = Nil
, oVulnerabilities : Option[Seq[VulnerabilitySummary]] = None
Expand Down Expand Up @@ -129,9 +128,9 @@

<div class="accordion-item">
<div class="accordion-header" id="headingDeploymentConfigUpdates">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDeploymentConfigUpdates" aria-expanded="false" aria-controls="collapseDeploymentConfigUpdates" @if(deploymentConfigChanges.isEmpty) {disabled} >
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDeploymentConfigUpdates" aria-expanded="false" aria-controls="collapseDeploymentConfigUpdates" @if(configChanges.deploymentChanges.isEmpty) {disabled} >
Deployment Config Updates
@changesBadge(deploymentConfigChanges.size)
@changesBadge(configChanges.deploymentChanges.size)
</button>
</div>
<div id="collapseDeploymentConfigUpdates" class="accordion-collapse collapse" aria-labelledby="headingDeploymentConfigUpdates" data-bs-parent="#accordion">
Expand All @@ -144,30 +143,30 @@
</tr>
</thead>
<tbody id="deployment-config-updates-rows">
@deploymentConfigChanges.map {
case DeploymentConfigChange.NewConfig(k, v) => {
<tr>
<td><code>@k</code></td>
<td>@v</td>
</tr>
}
case DeploymentConfigChange.DeletedConfig(k, previousV) => {
<tr>
<td><del><code>@k</code></del></td>
<td><del>@previousV</del></td>
</tr>
}
case DeploymentConfigChange.ChangedConfig(k, previousV, newV) => {
<tr>
<td><code>@k</code></td>
<td>
<ul class="list-unstyled">
<li><del>@previousV</del></li>
<li>@newV</li>
</ul>
</td>
</tr>
}
@for((key, ConfigChange(from, to)) <- configChanges.deploymentChanges.toList.sortBy(_._1.asString) ) {
<tr>
<td>
<code>
<a href="@serviceConfigsRoutes.ServiceConfigsController.configExplorer(serviceName, true, Some(key)).url" target="_blank">
@if(from.nonEmpty && to.isEmpty) {
<del>@key.asString</del>
} else {
@key.asString
}
</a>
</code>
</td>
<td>
<ul class="list-unstyled">
@from.map { c =>
<li>@displayConfigSourceValue(key, environment, c, isStriked = true)</li>
}
@to.map { c =>
<li>@displayConfigSourceValue(key, environment, c, isStriked = false)</li>
}
</ul>
</td>
</tr>
}
</tbody>
</table>
Expand All @@ -177,9 +176,9 @@

<div class="accordion-item">
<div class="accordion-header" id="headingConfigUpdates">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseConfigUpdates" aria-expanded="false" aria-controls="collapseConfigUpdates" @if(configChanges.changes.isEmpty) {disabled} >
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseConfigUpdates" aria-expanded="false" aria-controls="collapseConfigUpdates" @if(configChanges.configChanges.isEmpty) {disabled} >
Config Updates
@changesBadge(configChanges.changes.size)
@changesBadge(configChanges.configChanges.size)
</button>
</div>
<div id="collapseConfigUpdates" class="accordion-collapse collapse" aria-labelledby="headingConfigUpdates" data-bs-parent="#accordion">
Expand All @@ -192,7 +191,7 @@
</tr>
</thead>
<tbody id="config-updates-rows">
@for((key, ConfigChange(from, to)) <- configChanges.changes.toList.sortBy(_._1.asString) ) {
@for((key, ConfigChange(from, to)) <- configChanges.configChanges.toList.sortBy(_._1.asString) ) {
<tr>
<td>
<code>
Expand Down
Loading

0 comments on commit a79d99b

Please sign in to comment.