Skip to content

Commit

Permalink
Add view logs support, bold button for start/pause, bump Kotlin/Gradle (
Browse files Browse the repository at this point in the history
#415)

The latest Misk was causing failures when trying to start the
development service so the Kotlin/Gradle upgrade was necessary to
unblock forward development.

View logs link now works and there are bolder start/pause buttons in the
Backfill Show page.

<img width="1230" alt="Screenshot 2025-01-29 at 15 00 37"
src="https://github.com/user-attachments/assets/e3b457ce-202f-47c0-b1a4-0c52206b9f7a"
/>

<img width="670" alt="Screenshot 2025-01-29 at 15 00 50"
src="https://github.com/user-attachments/assets/782a31a6-6ef6-4f07-840f-5f51d4e603cc"
/>
  • Loading branch information
adrw authored Feb 11, 2025
1 parent eb76634 commit 5b5f564
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 54 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ jobs:
# happen in practice.
run: docker run -d -p 3306:3306 --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 mysql:5.7 --sql-mode=""

- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Test
run: gradle build check -i --parallel --build-cache

Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/Publish-Website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ jobs:
- name: Hermit
run: ./bin/hermit env -r >> $GITHUB_ENV

- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Prep mkdocs
run: .github/workflows/prepare_mkdocs.sh

Expand Down
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.allopen.gradle.AllOpenExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
Expand Down Expand Up @@ -39,8 +40,8 @@ subprojects {

tasks.withType<KotlinCompile> {
dependsOn("spotlessKotlinApply")
kotlinOptions {
jvmTarget = "11"
compilerOptions {
jvmTarget = JvmTarget.JVM_11
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.io.Serializable
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package app.cash.backfila.client.sqldelight.plugin

import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File

abstract class GenerateBackfilaRecordSourceSqlTask : DefaultTask() {
@get:Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sqldelight {
dialect(libs.sqldelightMysqlDialect)
srcDirs.setFrom(listOf("resources/migrations"))
deriveSchemaFromMigrations.set(true)
migrationOutputDirectory.set(file("$buildDir/resources/main/migrations"))
migrationOutputDirectory.set(layout.buildDirectory.dir("resources/main/migrations"))
verifyMigrations.set(true)
}
}
Expand All @@ -36,4 +36,4 @@ dependencies {
implementation("app.cash.backfila:client-sqldelight:${project.property("backfilaVersion")}")
implementation("app.cash.backfila:client:${project.property("backfilaVersion")}")
implementation(libs.sqldelightJdbcDriver)
}
}
2 changes: 1 addition & 1 deletion client-sqldelight-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sqldelight {
dialect(libs.sqldelightMysqlDialect)
srcDirs.setFrom(listOf("src/main/sqldelight", "src/main/resources/migrations"))
deriveSchemaFromMigrations.set(true)
migrationOutputDirectory.set(file("$buildDir/resources/main/migrations"))
migrationOutputDirectory.set(layout.buildDirectory.dir("resources/main/migrations"))
verifyMigrations.set(true)
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

sourceSets {
val main by getting {
java.srcDir("$buildDir/generated/source/wire/")
java.srcDir(layout.buildDirectory.dir("generated/source/wire"))
}
}

Expand Down
18 changes: 9 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
jooq = "3.18.1"
ktlint = "0.47.1"
jooq = "3.18.25"
kotlin = "1.9.23"
ktlint = "0.47.1"
misk = "2025.01.09.184726-680bca2"
okhttp = "5.0.0-alpha.14"
wire = "5.0.0"
sqldelight = "2.0.2"
wire = "5.2.1"

[libraries]
apacheCommonsLang3 = { module = "org.apache.commons:commons-lang3", version = "3.12.0" }
Expand Down Expand Up @@ -40,15 +40,15 @@ moshiKotlin = { module = "com.squareup.moshi:moshi-kotlin", version = "1.13.0" }
mysql = { module = "mysql:mysql-connector-java", version = "8.0.30" }
okHttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okHttpMockWebServer = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okhttp" }
okio = { module = "com.squareup.okio:okio", version = "3.9.0" }
okio = { module = "com.squareup.okio:okio", version = "3.9.1" }
openTracing = { module = "io.opentracing:opentracing-api", version = "0.33.0" }
openTracingMock = { module = "io.opentracing:opentracing-mock", version = "0.33.0" }
openTracingOkHttp = { module = "io.opentracing.contrib:opentracing-okhttp3", version = "3.0.0" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version = "2.9.0" }
retrofitGuavaAdapter = { module = "com.squareup.retrofit2:adapter-guava", version = "2.9.0" }
retrofitMock = { module = "com.squareup.retrofit2:retrofit-mock", version = "2.9.0" }
retrofitMoshi = { module = "com.squareup.retrofit2:converter-moshi", version = "2.9.0" }
retrofitWire = { module = "com.squareup.retrofit2:converter-wire", version = "2.9.0" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version = "2.11.0" }
retrofitGuavaAdapter = { module = "com.squareup.retrofit2:adapter-guava", version = "2.11.0" }
retrofitMock = { module = "com.squareup.retrofit2:retrofit-mock", version = "2.11.0" }
retrofitMoshi = { module = "com.squareup.retrofit2:converter-moshi", version = "2.11.0" }
retrofitWire = { module = "com.squareup.retrofit2:converter-wire", version = "2.11.0" }
shadowJarPlugin = { module = "gradle.plugin.com.github.johnrengelman:shadow", version = "7.1.2" }
slf4jApi = { module = "org.slf4j:slf4j-api", version = "2.0.3" }
sqldelightGradlePlugin = { module = "app.cash.sqldelight:gradle-plugin", version.ref = "sqldelight" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ class ViewLogsAction @Inject constructor(
fun viewLogs(
@PathParam id: Long,
): Response<ResponseBody> {
val url = transacter.transaction { session ->
val backfillRun = session.loadOrNull<DbBackfillRun>(Id(id))
?: throw BadRequestException("backfill $id doesn't exist")
viewLogsUrlProvider.getUrl(session, backfillRun)
}
val url = getUrl(id)
return Response(
body = "go to $url".toResponseBody(),
statusCode = HttpURLConnection.HTTP_MOVED_TEMP,
headers = Headers.headersOf("Location", url),
)
}

fun getUrl(id: Long) = transacter.transaction { session ->
val backfillRun = session.loadOrNull<DbBackfillRun>(Id(id))
?: throw BadRequestException("backfill $id doesn't exist")
viewLogsUrlProvider.getUrl(session, backfillRun)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ class BackfillShowButtonHandlerAction @Inject constructor(
companion object {
const val PATH = "/api/backfill/{id}/update"
fun path(id: String) = PATH.replace("{id}", id)
fun path(id: Long) = path(id.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app.cash.backfila.ui.pages

import app.cash.backfila.dashboard.GetBackfillStatusAction
import app.cash.backfila.dashboard.GetBackfillStatusResponse
import app.cash.backfila.dashboard.ViewLogsAction
import app.cash.backfila.service.persistence.BackfillState
import app.cash.backfila.ui.actions.BackfillShowButtonHandlerAction
import app.cash.backfila.ui.components.AutoReload
Expand Down Expand Up @@ -45,14 +46,15 @@ import misk.web.mediatype.MediaTypes
class BackfillShowAction @Inject constructor(
private val getBackfillStatusAction: GetBackfillStatusAction,
private val dashboardPageLayout: DashboardPageLayout,
private val viewLogsAction: ViewLogsAction,
) : WebAction {
@Get(PATH)
@ResponseContentType(MediaTypes.TEXT_HTML)
@Authenticated(capabilities = ["users"])
fun get(
@PathParam id: String,
@PathParam id: Long,
): Response<ResponseBody> {
val backfill = getBackfillStatusAction.status(id.toLong())
val backfill = getBackfillStatusAction.status(id)
val label =
if (backfill.variant == "default") backfill.service_name else "${backfill.service_name} (${backfill.variant})"

Expand All @@ -79,12 +81,12 @@ class BackfillShowAction @Inject constructor(
)
.buildHtmlResponseBody {
AutoReload {
PageTitle("Backfill", id) {
PageTitle("Backfill", id.toString()) {
a {
href = BackfillCreateAction.path(
service = backfill.service_name,
variantOrBackfillNameOrId = if (backfill.variant != "default") backfill.variant else id,
backfillNameOrId = if (backfill.variant != "default") id else "",
variantOrBackfillNameOrId = if (backfill.variant != "default") backfill.variant else id.toString(),
backfillNameOrId = if (backfill.variant != "default") id.toString() else "",
)

button(classes = "rounded-full bg-indigo-600 px-3 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600") {
Expand Down Expand Up @@ -241,26 +243,26 @@ class BackfillShowAction @Inject constructor(
val updateFieldId: String? = null,
)

private fun getStateButton(state: BackfillState, id: String): Link? {
private fun getStateButton(state: BackfillState): Link? {
return when (state) {
BackfillState.PAUSED -> Link(
label = "Start",
label = START_STATE_BUTTON_LABEL,
href = BackfillState.RUNNING.name,
)

BackfillState.COMPLETE -> null
else -> Link(
label = "Pause",
label = PAUSE_STATE_BUTTON_LABEL,
href = BackfillState.PAUSED.name,
)
}
}

private fun GetBackfillStatusResponse.toConfigurationRows(id: String) = listOf(
private fun GetBackfillStatusResponse.toConfigurationRows(id: Long) = listOf(
DescriptionListRow(
label = "State",
description = state.name,
button = getStateButton(state, id),
button = getStateButton(state),
updateFieldId = "state",
),
DescriptionListRow(
Expand Down Expand Up @@ -319,10 +321,9 @@ class BackfillShowAction @Inject constructor(
DescriptionListRow(
label = "Logs",
description = "",
// TODO add link real URL
button = Link(
label = "View",
href = "#",
label = VIEW_LOGS_BUTTON_LABEL,
href = viewLogsAction.getUrl(id),
),
),
) + if (parameters?.isNotEmpty() == true) {
Expand All @@ -348,7 +349,7 @@ class BackfillShowAction @Inject constructor(
}
}

private fun TagConsumer<*>.ConfigurationRows(id: String, it: DescriptionListRow) {
private fun TagConsumer<*>.ConfigurationRows(id: Long, it: DescriptionListRow) {
div("px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0") {
attributes["data-controller"] = "toggle"

Expand Down Expand Up @@ -420,6 +421,21 @@ class BackfillShowAction @Inject constructor(
+"Cancel"
}
}
} else if (button.label == VIEW_LOGS_BUTTON_LABEL) {
span("ml-4 flex-shrink-0") {
// View logs button will link to external logs provider
a {
href = button.href
target = "_blank"

button(
classes = "rounded-md font-medium text-indigo-600 hover:text-indigo-500",
) {
type = ButtonType.submit
+button.label
}
}
}
} else {
span("ml-4 flex-shrink-0") {
// Button when clicked updates without additional form
Expand All @@ -440,8 +456,14 @@ class BackfillShowAction @Inject constructor(
}
}

val buttonStyle = if (it.updateFieldId == "state") {
val color = if (it.button.label == START_STATE_BUTTON_LABEL) "green" else "yellow"
"rounded-full bg-$color-600 px-3 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-$color-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-$color-600"
} else {
"rounded-md font-medium text-indigo-600 hover:text-indigo-500"
}
button(
classes = "rounded-md font-medium text-indigo-600 hover:text-indigo-500",
classes = buttonStyle,
) {
type = ButtonType.submit
+button.label
Expand All @@ -457,7 +479,11 @@ class BackfillShowAction @Inject constructor(
companion object {
private const val PATH = "/backfills/{id}"
fun path(id: String) = PATH.replace("{id}", id)
fun path(id: Long) = path(id.toString())

const val START_STATE_BUTTON_LABEL = "Start"
const val PAUSE_STATE_BUTTON_LABEL = "Pause"
const val UPDATE_BUTTON_LABEL = "Update"
const val VIEW_LOGS_BUTTON_LABEL = "View Logs"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.html.button
import misk.scope.ActionScoped
import misk.security.authz.Authenticated
import misk.tailwind.Link
import misk.tokens.TokenGenerator
import misk.web.Get
import misk.web.HttpCall
import misk.web.PathParam
Expand All @@ -31,7 +30,6 @@ class ServiceShowAction @Inject constructor(
private val clientHttpCall: ActionScoped<HttpCall>,
private val dashboardPageLayout: DashboardPageLayout,
private val getBackfillRunsAction: GetBackfillRunsAction,
private val tokenGenerator: TokenGenerator,
) : WebAction {
private val path by lazy {
clientHttpCall.get().url.encodedPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fun main(args: Array<String>) {

internal class DevelopmentViewLogsUrlProvider : ViewLogsUrlProvider {
override fun getUrl(session: Session, backfillRun: DbBackfillRun): String {
return "/"
return "/${backfillRun.service.registry_name}/${backfillRun.service.variant}/${backfillRun.id}/logs"
}
}

Expand Down

0 comments on commit 5b5f564

Please sign in to comment.