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

Enable streaming of build logs #459

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ff70a52
add getlogs method
munishchouhan Apr 17, 2024
6f3cd8f
fixed builderName
munishchouhan Apr 17, 2024
16481a0
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Apr 18, 2024
8af97ef
fixed DockerBuildStrategyTest
munishchouhan Apr 18, 2024
22a574e
Merge remote-tracking branch 'origin/451-enable-streaming-of-build-lo…
munishchouhan Apr 18, 2024
d228dd9
added BuildLogLocalServiceImpl
munishchouhan Apr 18, 2024
a5ba7d9
added getCurrentLogsPod(String name)
munishchouhan Apr 18, 2024
6cb5e0e
fixed logs color issue
munishchouhan Apr 18, 2024
eafcb94
added build in progress phase and dynamic logs loading
munishchouhan Apr 18, 2024
c335997
minor change
munishchouhan Apr 18, 2024
26fdb65
changed to inputstream
munishchouhan Apr 19, 2024
93491f5
strip ansi escape codes
munishchouhan Apr 19, 2024
7869323
added docs
munishchouhan Apr 19, 2024
b287a56
fixed tests
munishchouhan Apr 19, 2024
a294b64
added test
munishchouhan Apr 19, 2024
94f40e7
corrected docs
munishchouhan Apr 19, 2024
db5afde
corrected docs
munishchouhan Apr 19, 2024
f6bb71c
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Apr 22, 2024
e7313e7
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Apr 22, 2024
1def98a
updated doc [ci skip]
munishchouhan Apr 22, 2024
a43a160
Merge remote-tracking branch 'origin/451-enable-streaming-of-build-lo…
munishchouhan Apr 22, 2024
a559584
reverted doc changes
munishchouhan Apr 22, 2024
0c06d3c
Merge branch 'master' into 451-enable-streaming-of-build-logs
pditommaso Apr 23, 2024
153b0df
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Apr 23, 2024
96afbb9
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan May 4, 2024
534da81
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan May 15, 2024
4859154
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Jun 11, 2024
fd9ea32
fix tests
munishchouhan Jun 11, 2024
7dedb5f
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Jul 22, 2024
aeb386c
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Aug 14, 2024
0c53ec5
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Aug 20, 2024
59f25e8
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Aug 29, 2024
1511ddb
fixed errors
munishchouhan Aug 29, 2024
167a9ad
fixed errors
munishchouhan Aug 30, 2024
1752d55
master merged
munishchouhan Oct 17, 2024
e09c9ec
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Oct 22, 2024
d6b19e5
fixed error
munishchouhan Oct 22, 2024
ed403ee
fixed error
munishchouhan Oct 22, 2024
1c304b1
fixed tests
munishchouhan Oct 22, 2024
7b09548
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Nov 5, 2024
505c303
Merge branch 'master' into 451-enable-streaming-of-build-logs
munishchouhan Jan 15, 2025
f92a301
fixed error
munishchouhan Jan 15, 2025
5942bd8
fixed tests
munishchouhan Jan 15, 2025
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 @@ -37,6 +37,8 @@ abstract class BuildStrategy {

abstract BuildResult build(BuildRequest req)

abstract String getLogs(String buildId)
pditommaso marked this conversation as resolved.
Show resolved Hide resolved

void cleanup(BuildRequest req) {
req.workDir?.deleteDir()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DockerBuildStrategy extends BuildStrategy {
? cmdForKaniko( req.workDir, credsFile, spack, req.platform)
: cmdForSingularity( req.workDir, credsFile, spack, req.platform)

return dockerCmd + launchCmd(req)
return dockerCmd + builderName(req.buildId) +launchCmd(req)
munishchouhan marked this conversation as resolved.
Show resolved Hide resolved
}

protected List<String> cmdForKaniko(Path workDir, Path credsFile, SpackConfig spackConfig, ContainerPlatform platform ) {
Expand Down Expand Up @@ -173,4 +173,19 @@ class DockerBuildStrategy extends BuildStrategy {
wrapper.add(buildConfig.singularityImage(platform))
return wrapper
}

protected List<String> builderName(String buildId) {
def name = "build-${buildId}".toString().replace('_', '-')
return List.of('--name', name)
}

@Override
String getLogs(String buildId) {
def logCmd = ['docker', 'logs'] + builderName(buildId)
final proc = new ProcessBuilder()
.command(logCmd)
.redirectErrorStream(true)
.start()
return proc.inputStream.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class KubeBuildStrategy extends BuildStrategy {
@Inject
private RegistryProxyService proxyService

protected String podName(BuildRequest req) {
return "build-${req.buildId}".toString().replace('_', '-')
protected String podName(String buildId) {
return "build-${buildId}".toString().replace('_', '-')
}

@Override
Expand All @@ -96,7 +96,7 @@ class KubeBuildStrategy extends BuildStrategy {
try {
final buildImage = getBuildImage(req)
final buildCmd = launchCmd(req)
final name = podName(req)
final name = podName(req.buildId)
final selector= getSelectorLabel(req.platform, nodeSelectorMap)
final spackCfg0 = req.isSpackBuild ? spackConfig : null
final pod = k8sService.buildContainer(name, buildImage, buildCmd, req.workDir, configFile, spackCfg0, selector)
Expand Down Expand Up @@ -130,7 +130,7 @@ class KubeBuildStrategy extends BuildStrategy {
@Override
void cleanup(BuildRequest req) {
super.cleanup(req)
final name = podName(req)
final name = podName(req.buildId)
try {
k8sService.deletePod(name)
}
Expand All @@ -139,4 +139,9 @@ class KubeBuildStrategy extends BuildStrategy {
}
}

@Override
String getLogs(String buildId) {
return k8sService.logsPod(podName(buildId))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class K8sServiceImpl implements K8sService {
}
}

/**
/**
* Fetch the logs of a pod
*
* @param name The pod name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import io.micronaut.objectstorage.request.UploadRequest
import io.micronaut.runtime.event.annotation.EventListener
import io.seqera.wave.service.builder.BuildEvent
import io.seqera.wave.service.builder.BuildRequest
import io.seqera.wave.service.builder.BuildStrategy
import io.seqera.wave.service.builder.KubeBuildStrategy
import io.seqera.wave.service.k8s.K8sService
import io.seqera.wave.service.persistence.PersistenceService
import jakarta.annotation.PostConstruct
import jakarta.inject.Inject
Expand All @@ -56,6 +59,9 @@ class BuildLogServiceImpl implements BuildLogService {
@Inject
private PersistenceService persistenceService

@Inject
private BuildStrategy buildStrategy

@Nullable
@Value('${wave.build.logs.prefix}')
private String prefix
Expand Down Expand Up @@ -107,7 +113,13 @@ class BuildLogServiceImpl implements BuildLogService {
private StreamedFile fetchLogStream0(String buildId) {
if( !buildId ) return null
final Optional<ObjectStorageEntry<?>> result = objectStorageOperations.retrieve(logKey(buildId))
return result.isPresent() ? result.get().toStreamedFile() : null
return result.isPresent() ? result.get().toStreamedFile() : fetchLogStream1(buildId)
}

private StreamedFile fetchLogStream1(String buildId) {
StreamedFile result = null
buildStrategy.getLogs(buildId)
return result
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class FutureContainerBuildServiceTest extends Specification {
BuildResult build(BuildRequest req) {
new BuildResult("", exitCode, "a fake build result in a test", Instant.now(), Duration.ofSeconds(3), 'abc')
}

@Override
String getLogs(String buildId) {
return "fake build logs"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class KubeBuildStrategyTest extends Specification {
req = req.withBuildId('1')

when:
def podName = strategy.podName(req)
def podName = strategy.podName(req.buildId)

then:
req.buildId == '143ee73bcdac45b1_1'
Expand Down
Loading