Skip to content

enhance logs functionality to handle build stage log - #48

Merged
benjaminhuo merged 3 commits into
OpenFunction:mainfrom
James-JLC:main
May 21, 2022
Merged

benjaminhuo merged 3 commits into
OpenFunction:mainfrom
James-JLC:main

Conversation

@James-JLC

Copy link
Copy Markdown
Contributor

Signed-off-by: Alex Ji [email protected]

defer logReader.Close()
readerList = append(readerList, logReader)
} else {
for _, container := range pod.Spec.Containers {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There're several kinds of containers in a Function pod:

  • the function container whose name is just function
  • the dapr sidecar container
  • the knative sidecar container

Normally we only output logs from the function container is enough. This is why we set container name to function in 21bea4c#diff-5c7fb0ae4b5f3afe942a2e3eed411e5a10ffff3e1dccbbf969947d98b79d60d7L54

If the user needs to view logs from dapr sidecar or knative sidecar, he can specify container name. If container name is not specified, the default one function will be used.

So we needn't to add a loop here to iterate all containers

Comment thread pkg/cmd/subcommand/logs.go Outdated
statusError, ok := err.(*k8serrors.StatusError)
// buildrun has been cleaned up
if ok && statusError.Status().Code == 404 {
goto serving

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goto serving logic here is to fetch serving logs continually after the build phase ends.

But I think we can make it simpler by removing the 'goto serving' logic:

  • If there is builder CR exists, just continually fetch build logs by adding -f option. The builder CR will not be deleted if the build fails and will be deleted when the build succeeds.
  • If there is no builder CR, and there is serving CR. This means the build is successful, so we only need to fetch serving logs
  • If there is no builder CR and no serving CR either, means this is in between the build and serving phase, and we needn't fetch any logs. And we needn't wait for the serving pod to be started either. The possibility of this scenario is small.

In short, we only need to fetch logs from the currently existing pod's function container by default.
No need to wait for the serving pod to up and running.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I totally agree with you! I thought too much before.

Thanks for your review!

@benjaminhuo

Copy link
Copy Markdown
Member

@jilichao Thanks for the PR. This is a big enhancement and we're going to release a new version after this PR!

@benjaminhuo
benjaminhuo merged commit bb3457d into OpenFunction:main May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants