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

Fix date format in Wave containers meta #5903

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package nextflow.container.resolver

import java.time.Instant

import java.time.OffsetDateTime

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString

/**
* Model container usage metadata
*
Expand All @@ -40,5 +40,5 @@ class ContainerMeta {
String scanId
Boolean cached
Boolean freeze
Instant requestTime
OffsetDateTime requestTime
}
1 change: 1 addition & 0 deletions plugins/nf-tower/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
testImplementation(testFixtures(project(":nextflow")))
testImplementation "org.apache.groovy:groovy:4.0.26"
testImplementation "org.apache.groovy:groovy-nio:4.0.26"
testImplementation "org.apache.groovy:groovy-json:4.0.26"
// wiremock required by TowerFusionEnvTest
testImplementation "org.wiremock:wiremock:3.5.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.seqera.tower.plugin

import java.nio.file.Path
import java.time.Instant
import java.time.OffsetDateTime

import groovy.json.DefaultJsonGenerator
Expand Down Expand Up @@ -48,6 +49,7 @@ class TowerJsonGenerator extends DefaultJsonGenerator {
.addConverter(Duration) { Duration d, String key -> d.durationInMillis }
.addConverter(NextflowMeta) { NextflowMeta m, String key -> m.toJsonMap() }
.addConverter(OffsetDateTime) { it.toString() }
.addConverter(Instant) { it.toString() }
.dateFormat(Const.ISO_8601_DATETIME_FORMAT).timezone("UTC")

return new TowerJsonGenerator(opts, scheme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

package io.seqera.tower.plugin

import java.time.Instant
import java.time.ZoneOffset

import groovy.json.JsonGenerator
import groovy.json.JsonSlurper
import nextflow.container.resolver.ContainerMeta
import nextflow.trace.ProgressRecord
import nextflow.trace.WorkflowStats
import spock.lang.Specification
Expand Down Expand Up @@ -243,4 +247,26 @@ class TowerJsonGeneratorTest extends Specification {
}
}

def 'should serialise container meta' () {
given:
def gen = TowerJsonGenerator.create([:])
and:
def ts = Instant.ofEpochSecond(1742421070).atOffset(ZoneOffset.UTC)
def c1 = new ContainerMeta(
requestId:'r-1',
requestTime:ts,
buildId: 'bd-2',
scanId: 'sc-3',
mirrorId: 'mr-4',
cached: false,
freeze: true,
sourceImage: 'debian:latest',
targetImage: 'wave/debian')

when:
def json = gen.toJson([containers: [c1]])
then:
json == '{"containers":[{"requestId":"r-1","sourceImage":"debian:latest","targetImage":"wave/debian","buildId":"bd-2","mirrorId":"mr-4","scanId":"sc-3","cached":false,"freeze":true,"requestTime":"2025-03-19T21:51:10Z"}]}'
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.nio.file.Path
import java.time.Duration
import java.time.Instant
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.temporal.ChronoUnit
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
Expand Down Expand Up @@ -678,7 +679,7 @@ class WaveClient {
return null
final resp = handle.response
final result = new ContainerMeta()
result.requestTime = handle.createdAt
result.requestTime = handle.createdAt?.atOffset(ZoneOffset.UTC)
result.requestId = resp.requestId
result.sourceImage = resp.containerImage
result.targetImage = resp.targetImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileTime
import java.time.Duration
import java.time.Instant
import java.time.ZoneOffset

import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpHandler
Expand Down Expand Up @@ -1390,7 +1391,7 @@ class WaveClientTest extends Specification {
and:
result == new ContainerMeta(
requestId: resp.requestId,
requestTime: handle.createdAt,
requestTime: handle.createdAt.atOffset(ZoneOffset.UTC),
sourceImage: resp.containerImage,
targetImage: resp.targetImage,
buildId: resp.buildId,
Expand Down Expand Up @@ -1426,7 +1427,7 @@ class WaveClientTest extends Specification {
and:
result == new ContainerMeta(
requestId: resp.requestId,
requestTime: handle.createdAt,
requestTime: handle.createdAt.atOffset(ZoneOffset.UTC),
sourceImage: resp.containerImage,
targetImage: resp.targetImage,
buildId: null,
Expand Down