Skip to content

Commit

Permalink
chore(java17): upgrade java runtime to JRE17 and compilation using JD…
Browse files Browse the repository at this point in the history
…K17, but target remains Java11

While upgrading java 17, encountered below error during the test execution process of keel-core-test and keel-sql modules:
```
retrieves timestamp successfully

SqlArtifactRepositoryTests retrieves timestamp successfully FAILED (11.5s)

  ▼ Expect that 2024-11-04T16:23:59.680067Z:
    ✗ is equal to 2024-11-04T16:23:59.680066531Z
            found 2024-11-04T16:23:59.680067Z
```

```
SqlDeliveryConfigRepositoryTests deletes data successfully for known application FAILED (11.5s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:17.740578522Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:17.740578522Z' for function str_to_date

SqlDeliveryConfigRepositoryTests throws exception for unknown application FAILED (12.8s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:29.434469839Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:29.434469839Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related application events FAILED (12s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:42.199694193Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:42.199694193Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related resource events FAILED (12.6s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:47:54.338147807Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:47:54.338147807Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related application pause records FAILED (11.5s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:06.896010045Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:06.896010045Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes related resource pause records FAILED (12.6s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:18.409434437Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:18.409434437Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes any older versions of resources FAILED (11.8s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:31.166252032Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:31.166252032Z' for function str_to_date

SqlDeliveryConfigRepositoryTests deletes data successfully for known delivery config FAILED (11.7s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:42.855107042Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:42.855107042Z' for function str_to_date

SqlDeliveryConfigRepositoryTests throws exception for unknown delivery config FAILED (12.1s)

  org.jooq.exception.DataAccessException: SQL [insert into `keel`.`event` (`uid`, `scope`, `json`) values (?, ?, ?)]; Incorrect datetime value: '2024-11-04T16:48:54.920960756Z' for function str_to_date

  Caused by: java.sql.SQLException: Incorrect datetime value: '2024-11-04T16:48:54.920960756Z' for function str_to_date

```
The error occurred due to change in behaviour of `java.time.Instant` class from Java 11 to Java 17. In Java 17, Instant class returns clock with precision of microsecond and nanosecond based on underlying system, which is not the case with Java 11. This causes the MYSQL str_to_date function fail while data insertion.
In order to fix this issue, truncated the microseconds from the Instant.

https://stackoverflow.com/questions/74781495/changes-in-instant-now-between-java-11-and-java-17-in-aws-ubuntu-standard-6-0
  • Loading branch information
j-sandy committed Nov 13, 2024
1 parent bb3aa3f commit 97f5ba6
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 39 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
uses: docker/setup-buildx-action@v3
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: |
11
17
distribution: 'zulu'
cache: 'gradle'
- name: Prepare build variables
Expand All @@ -36,7 +38,7 @@ jobs:
- name: Build
env:
ORG_GRADLE_PROJECT_version: ${{ steps.build_variables.outputs.VERSION }}
run: ./gradlew build --stacktrace ${{ steps.build_variables.outputs.REPO }}-web:installDist
run: ./gradlew -PenableCrossCompilerPlugin=true build --stacktrace ${{ steps.build_variables.outputs.REPO }}-web:installDist
- name: Login to GAR
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
uses: docker/setup-buildx-action@v3
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: |
11
17
distribution: 'zulu'
cache: 'gradle'
- name: Prepare build variables
Expand All @@ -30,7 +32,7 @@ jobs:
- name: Build
env:
ORG_GRADLE_PROJECT_version: ${{ steps.build_variables.outputs.VERSION }}
run: ./gradlew build ${{ steps.build_variables.outputs.REPO }}-web:installDist
run: ./gradlew -PenableCrossCompilerPlugin=true build ${{ steps.build_variables.outputs.REPO }}-web:installDist
- name: Build slim container image
uses: docker/build-push-action@v6
with:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
uses: docker/setup-buildx-action@v3
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: |
11
17
distribution: 'zulu'
cache: 'gradle'
- name: Assemble release info
Expand All @@ -50,14 +52,14 @@ jobs:
ORG_GRADLE_PROJECT_nexusPgpSigningKey: ${{ secrets.NEXUS_PGP_SIGNING_KEY }}
ORG_GRADLE_PROJECT_nexusPgpSigningPassword: ${{ secrets.NEXUS_PGP_SIGNING_PASSWORD }}
run: |
./gradlew --info build ${{ steps.build_variables.outputs.REPO }}-web:installDist publishToNexus closeAndReleaseNexusStagingRepository
./gradlew --info -PenableCrossCompilerPlugin=true build ${{ steps.build_variables.outputs.REPO }}-web:installDist publishToNexus closeAndReleaseNexusStagingRepository
- name: Publish apt packages to Google Artifact Registry
env:
ORG_GRADLE_PROJECT_version: ${{ steps.release_info.outputs.RELEASE_VERSION }}
ORG_GRADLE_PROJECT_artifactRegistryPublishEnabled: true
GAR_JSON_KEY: ${{ secrets.GAR_JSON_KEY }}
run: |
./gradlew --info publish
./gradlew --info -PenableCrossCompilerPlugin=true publish
- name: Login to GAR
# Only run this on repositories in the 'spinnaker' org, not on forks.
if: startsWith(github.repository, 'spinnaker/')
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ allprojects {
apply(plugin: "com.diffplug.spotless")

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ testContainersVersion=1.15.3
okHttpVersion=4.5.0
resilience4jVersion=1.5.0
spinnakerGradleVersion=8.32.1
targetJava17=false

# Used to control whether to spin up docker to run liquibase before jooq
buildingInDocker=false
Expand Down
12 changes: 6 additions & 6 deletions gradle/kotlin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ apply plugin: "kotlin-allopen"

compileKotlin {
kotlinOptions {
languageVersion = "1.5"
jvmTarget = "11"
languageVersion = "1.6"
jvmTarget = "17"
// see https://kotlinlang.org/docs/java-to-kotlin-interop.html#compatibility-mode-for-default-methods
freeCompilerArgs += "-Xjvm-default=enable"
freeCompilerArgs += "-Xjvm-default=all"
}
}

compileTestKotlin {
kotlinOptions {
languageVersion = "1.5"
jvmTarget = "11"
freeCompilerArgs += "-Xjvm-default=enable"
languageVersion = "1.6"
jvmTarget = "17"
freeCompilerArgs += "-Xjvm-default=all"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import strikt.assertions.isNull
import strikt.assertions.isTrue
import java.time.Clock
import java.time.Instant
import java.time.temporal.ChronoUnit

abstract class ArtifactRepositoryTests<T : ArtifactRepository> : JUnit5Minutests {
val publisher: ApplicationEventPublisher = mockk(relaxed = true)
Expand Down Expand Up @@ -649,8 +650,7 @@ abstract class ArtifactRepositoryTests<T : ArtifactRepository> : JUnit5Minutests
}

context("artifact creation timestamp exists") {
val createdAt = Instant.now()

val createdAt = Instant.now().truncatedTo(ChronoUnit.MICROS)
before {
subject.register(versionedSnapshotDebian)
subject.storeArtifactVersion(versionedSnapshotDebian.toArtifactVersion(version1, SNAPSHOT, createdAt = createdAt))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
import java.time.Clock
import java.time.Instant
import com.netflix.spinnaker.keel.events.EventLevel.WARNING
import java.time.temporal.ChronoUnit

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
Expand Down Expand Up @@ -41,7 +42,7 @@ data class ApplicationActuationPaused(

constructor(application: String, triggeredBy: String, comment: String? = null, clock: Clock = Companion.clock) : this(
application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
triggeredBy,
comment
)
Expand All @@ -61,6 +62,6 @@ data class ApplicationActuationResumed(
constructor(application: String, triggeredBy: String, clock: Clock = Companion.clock) : this(
application,
triggeredBy,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.Clock
import java.time.Instant
import java.time.temporal.ChronoUnit

@JsonTypeInfo(
use = Id.NAME,
Expand Down Expand Up @@ -101,7 +102,7 @@ data class ResourceCreated(
resource.id,
resource.version,
resource.application,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -126,7 +127,7 @@ data class ResourceUpdated(
resource.version,
resource.application,
delta,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -143,7 +144,7 @@ data class ResourceDeleted(
resource.id,
resource.version,
resource.application,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand Down Expand Up @@ -175,7 +176,7 @@ data class ResourceMissing(
resource.id,
resource.version,
resource.application,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -202,7 +203,7 @@ data class ResourceDeltaDetected(
resource.version,
resource.application,
delta,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -229,7 +230,7 @@ data class ResourceActuationLaunched(
resource.application,
plugin,
tasks,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -253,13 +254,13 @@ data class ResourceActuationPaused(
resource.id,
resource.version,
resource.application,
timestamp,
timestamp.truncatedTo(ChronoUnit.MICROS),
triggeredBy
)

constructor(resource: Resource<*>, triggeredBy: String, clock: Clock = Companion.clock) : this(
resource,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
triggeredBy
)
}
Expand Down Expand Up @@ -293,7 +294,7 @@ data class ResourceActuationVetoed(
reason,
veto,
suggestedStatus,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -318,7 +319,7 @@ data class ResourceActuationResumed(
resource.version,
resource.application,
triggeredBy,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand Down Expand Up @@ -346,7 +347,7 @@ data class ResourceTaskFailed(
resource.application,
reason,
tasks,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -370,7 +371,7 @@ data class ResourceTaskSucceeded(
resource.version,
resource.application,
tasks,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -395,7 +396,7 @@ data class ResourceDeltaResolved(
resource.id,
resource.version,
resource.application,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -420,7 +421,7 @@ data class ResourceValid(
resource.id,
resource.version,
resource.application,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

Expand All @@ -446,7 +447,7 @@ data class ResourceCheckUnresolvable(
resource.id,
resource.version,
resource.application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
exception.message
)
}
Expand Down Expand Up @@ -499,7 +500,7 @@ data class ResourceCheckError(
resource.id,
resource.version,
resource.application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
exception.javaClass,
exception.message
)
Expand All @@ -523,7 +524,7 @@ data class ResourceDiffNotActionable(
resource.id,
resource.version,
resource.application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
message
)
}
Expand All @@ -545,7 +546,7 @@ data class VerificationBlockedActuation(
resource.id,
resource.version,
resource.application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
message = if(e.active.count() == 1) {
"there is an active verification against version ${e.active.first().version}"
} else {
Expand All @@ -570,7 +571,7 @@ class MaxResourceDeletionAttemptsReached(
) : ResourceEvent() {
constructor(resource: Resource<*>, attempts: Int, clock: Clock = Companion.clock) : this (
resource.application,
clock.instant(),
clock.instant().truncatedTo(ChronoUnit.MICROS),
resource.displayName,
resource.kind,
resource.id,
Expand Down Expand Up @@ -602,6 +603,6 @@ data class ResourceDeletionLaunched(
resource.application,
plugin,
tasks,
clock.instant()
clock.instant().truncatedTo(ChronoUnit.MICROS)
)
}

0 comments on commit 97f5ba6

Please sign in to comment.