Skip to content

Commit 3963044

Browse files
committed
More fixes
1 parent c301320 commit 3963044

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Diff for: service-self-backfill/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dependencies {
6161
implementation(project(":client-misk-hibernate"))
6262
implementation(project(":service"))
6363

64+
testImplementation(testFixtures(libs.miskAuditClient))
6465
testImplementation(libs.miskTesting)
6566
testImplementation(libs.miskHibernateTesting)
6667
testImplementation(libs.junitApi)

Diff for: service-self-backfill/src/test/kotlin/app/cash/backfila/service/selfbackfill/SelfBackfillTestingModule.kt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import app.cash.backfila.service.runner.BackfillRunnerLoggingSetupProvider
1717
import app.cash.backfila.service.runner.BackfillRunnerNoLoggingSetupProvider
1818
import misk.MiskCaller
1919
import misk.MiskTestingServiceModule
20+
import misk.audit.FakeAuditClientModule
21+
import misk.config.AppNameModule
2022
import misk.environment.DeploymentModule
2123
import misk.hibernate.HibernateTestingModule
2224
import misk.inject.KAbstractModule
@@ -50,6 +52,8 @@ class SelfBackfillTestingModule : KAbstractModule() {
5052
)
5153

5254
install(BackfilaListenerModule())
55+
install(AppNameModule("self-backfila"))
56+
install(FakeAuditClientModule())
5357

5458
bind<BackfilaConfig>().toInstance(config)
5559
install(DeploymentModule(TESTING))

Diff for: service/src/main/kotlin/app/cash/backfila/service/listener/AuditClientListener.kt

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,63 @@ import misk.hibernate.Id
1010
import misk.hibernate.Transacter
1111
import misk.hibernate.load
1212

13-
class AuditClientListener @Inject constructor(
13+
internal class AuditClientListener @Inject constructor(
1414
@BackfilaDb private val transacter: Transacter,
1515
private val auditClient: AuditClient,
1616
private val backfilaConfig: BackfilaConfig,
1717
) : BackfillRunListener {
1818
override fun runStarted(id: Id<DbBackfillRun>, user: String) {
19-
val (backfillName, run, description) = transacter.transaction { session ->
19+
val (backfillName, serviceName, description) = transacter.transaction { session ->
2020
val run = session.load<DbBackfillRun>(id)
21-
AuditEvent(run.registered_backfill.name, run, "Backfill started by $user ${dryRunPrefix(run)}${nameAndId(run)}")
21+
AuditEventInputs(run.registered_backfill.name, serviceName(run), "Backfill started by $user ${dryRunPrefix(run)}${nameAndId(run)}")
2222
}
2323
auditClient.logEvent(
2424
target = backfillName,
2525
description = description,
2626
requestorLDAP = user,
27-
applicationName = serviceName(run),
27+
applicationName = serviceName,
2828
detailURL = idUrl(id),
2929
)
3030
}
3131

3232
override fun runPaused(id: Id<DbBackfillRun>, user: String) {
33-
val (backfillName, run, description) = transacter.transaction { session ->
33+
val (backfillName, serviceName, description) = transacter.transaction { session ->
3434
val run = session.load<DbBackfillRun>(id)
35-
AuditEvent(run.registered_backfill.name, run, "Backfill paused by $user ${dryRunPrefix(run)}${nameAndId(run)}")
35+
AuditEventInputs(run.registered_backfill.name, serviceName(run), "Backfill paused by $user ${dryRunPrefix(run)}${nameAndId(run)}")
3636
}
3737
auditClient.logEvent(
3838
target = backfillName,
3939
description = description,
4040
requestorLDAP = user,
41-
applicationName = serviceName(run),
41+
applicationName = serviceName,
4242
detailURL = idUrl(id),
4343
)
4444
}
4545

4646
override fun runErrored(id: Id<DbBackfillRun>) {
47-
val (backfillName, run, description) = transacter.transaction { session ->
47+
val (backfillName, serviceName, description) = transacter.transaction { session ->
4848
val run = session.load<DbBackfillRun>(id)
49-
AuditEvent(run.registered_backfill.name, run, "Backfill paused due to error ${dryRunPrefix(run)}${nameAndId(run)}")
49+
AuditEventInputs(run.registered_backfill.name, serviceName(run), "Backfill paused due to error ${dryRunPrefix(run)}${nameAndId(run)}")
5050
}
5151
auditClient.logEvent(
5252
target = backfillName,
5353
description = description,
5454
automatedChange = true,
55-
applicationName = serviceName(run),
55+
applicationName = serviceName,
5656
detailURL = idUrl(id),
5757
)
5858
}
5959

6060
override fun runCompleted(id: Id<DbBackfillRun>) {
61-
val (backfillName, run, description) = transacter.transaction { session ->
61+
val (backfillName, serviceName, description) = transacter.transaction { session ->
6262
val run = session.load<DbBackfillRun>(id)
63-
AuditEvent(run.registered_backfill.name, run, "Backfill completed ${dryRunPrefix(run)}${nameAndId(run)}")
63+
AuditEventInputs(run.registered_backfill.name, serviceName(run), "Backfill completed ${dryRunPrefix(run)}${nameAndId(run)}")
6464
}
6565
auditClient.logEvent(
6666
target = backfillName,
6767
description = description,
6868
automatedChange = true,
69-
applicationName = serviceName(run),
69+
applicationName = serviceName,
7070
detailURL = idUrl(id),
7171
)
7272
}
@@ -94,9 +94,9 @@ class AuditClientListener @Inject constructor(
9494

9595
private fun idUrl(id: Id<DbBackfillRun>): String = backfilaConfig.web_url_root + BackfillShowAction.path(id.id)
9696

97-
private data class AuditEvent(
97+
private data class AuditEventInputs(
9898
val backfillName: String,
99-
val run: DbBackfillRun,
99+
val serviceName: String,
100100
val description: String,
101101
)
102102
}

Diff for: service/src/test/kotlin/app/cash/backfila/service/listener/AuditClientListenerTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.assertj.core.api.Assertions.assertThat
2828
import org.junit.jupiter.api.Test
2929

3030
@MiskTest(startService = true)
31-
class AuditClientListenerTest {
31+
internal class AuditClientListenerTest {
3232
@Suppress("unused")
3333
@MiskTestModule
3434
val module: Module = BackfilaTestingModule()
@@ -114,7 +114,7 @@ class AuditClientListenerTest {
114114
timestampSent = 2147483647,
115115
applicationName = "deep-fryer",
116116
// Fix fake client to not provide approver unless explicitly present
117-
approverLDAP = "molly",
117+
approverLDAP = null,
118118
automatedChange = false,
119119
description = "Backfill started by molly [dryRun=true][service=deep-fryer][backfill=ChickenSandwich][id=${response.backfill_run_id}]",
120120
richDescription = null,
@@ -134,7 +134,7 @@ class AuditClientListenerTest {
134134
eventTarget = "ChickenSandwich",
135135
timestampSent = 2147483647,
136136
applicationName = "deep-fryer",
137-
approverLDAP = "molly",
137+
approverLDAP = null,
138138
automatedChange = false,
139139
description = "Backfill paused by molly [dryRun=true][service=deep-fryer][backfill=ChickenSandwich][id=${response.backfill_run_id}]",
140140
richDescription = null,
@@ -154,14 +154,14 @@ class AuditClientListenerTest {
154154
eventTarget = "ChickenSandwich",
155155
timestampSent = 2147483647,
156156
applicationName = "deep-fryer",
157-
approverLDAP = "molly",
157+
approverLDAP = null,
158158
automatedChange = true,
159159
description = "Backfill paused due to error [dryRun=true][service=deep-fryer][backfill=ChickenSandwich][id=${response.backfill_run_id}]",
160160
richDescription = null,
161161
environment = "testing",
162162
detailURL = "/backfills/${response.backfill_run_id}",
163163
region = "us-west-2",
164-
requestorLDAP = "molly",
164+
requestorLDAP = null,
165165
),
166166
fakeAuditClient.sentEvents.last(),
167167
)
@@ -174,14 +174,14 @@ class AuditClientListenerTest {
174174
eventTarget = "ChickenSandwich",
175175
timestampSent = 2147483647,
176176
applicationName = "deep-fryer",
177-
approverLDAP = "molly",
177+
approverLDAP = null,
178178
automatedChange = true,
179179
description = "Backfill completed [dryRun=true][service=deep-fryer][backfill=ChickenSandwich][id=${response.backfill_run_id}]",
180180
richDescription = null,
181181
environment = "testing",
182182
detailURL = "/backfills/${response.backfill_run_id}",
183183
region = "us-west-2",
184-
requestorLDAP = "molly",
184+
requestorLDAP = null,
185185
),
186186
fakeAuditClient.sentEvents.last(),
187187
)

0 commit comments

Comments
 (0)