-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add script to tail logs for pipelinerun and taskruns #336
Conversation
/test pull-knative-build-pipeline-integration-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, just one question (merely about the help notation 🙃 )
test/logs/README.md
Outdated
There is a "gotcha" about tailing logs for init container. Logs cannot be retrieved from pod that has been shut down for a while. In this case tailing logs will return error `Unable to retrieve container logs`. | ||
|
||
```shell | ||
go run test/logs/main.go [-n NAMESPACE] [[-pr PIPELINERUN-NAME] / [-tr TASKRUN_NAME]] [-f FILE-NAME] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either -pr
or -tr
is required right ? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes. Thanks for catching that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool! I know I'll use it a lot - and great docs too :D
A few comments about naming + how we can make sure this keeps working over time
test/logs/helpers/taskrun_logs.go
Outdated
return fmt.Errorf("waiting for container: %v", err) | ||
} | ||
|
||
container := pod.Status.InitContainerStatuses[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm we'll have to remember to update this once knative/build#470 lands!
since landing knative/build#470 could break this tool, what do you think about adding some kind of super basic sanity check test that will verify the tool keeps working? otherwise we could easily forget about it (if we're not using it regularly, which I bet we will be!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i also wonder if the shifting implementation could make it a good idea to abstract the init container based portion of this logic into a function or package that we can swap out when we land knative/build#470
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work after build PR lands. TaskRun status hold podname and that is used for tracking pod logs.
test/logs/main.go
Outdated
|
||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
|
||
tlogs "github.com/knative/build-pipeline/test/logs/helpers" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call the package something more specific than helpers
? I think helpers
is one of those package names that is hard to reason about and makes it difficult what should go there and what shouldn't (see "bad package names" at https://blog.golang.org/package-names)
The fact that you've imported this as tlogs
I feel is a hint that maybe we don't even need the helpers
package? We could have everything exist directly in test/logs
Or we could break helpers
up into more specific packages, e.g. test/logs/pods
, test/logs/pipelinerun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure makes sense. I will refactor to include all logs in one package for now.
@@ -6,6 +6,7 @@ | |||
- [How do I run a Pipeline?](#running-a-pipeline) | |||
- [How do I run a Task on its own?](#running-a-task) | |||
- [How do I troubleshoot a PipelineRun?](#troubleshooting) | |||
- [How do I follow logs](../test/logs/README.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess once we have #107 implemented this will change a bit 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2df1219
to
cefe0d5
Compare
@bobcatfish @vdemeester : I have addressed your comments. Ready for another review |
out = os.Stdout | ||
|
||
if (*pr == "" && *tr == "") || (*pr != "" && *tr != "") { | ||
errorMsg(fmt.Sprintf("Usage: %s [-n NAMESPACE] [-pr PIPELINERUN-NAME] / [-tr TASKRUN_NAME] [-f FILE-NAME]", os.Args[0]), nil, out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we may want to print a message "you can't have both -pr
/-tr
flags or non" maybe ?
test/logs/pipelinerun/logs.go
Outdated
"k8s.io/client-go/rest" | ||
) | ||
|
||
//tailPrLogs tails the logs for pipeline run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/tailPrLogs/TailLogs
test/logs/taskrun/logs.go
Outdated
"k8s.io/client-go/rest" | ||
) | ||
|
||
func TailLogs(ctx context.Context, cfg *rest.Config, trName, namespace string, out io.Writer) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a godoc would be good here (like on pipelineRun.TailLogs
)
- supports `-f` flag. Takes name of a file to create to dump logs - supports `-n` flag for namepsace. Default namespace is `default` - supports `-pr` to tail logs for pipelinerun and all sub taskruns - supports `-tr` to tail logs for taskrun only - Add note to help cli user understand about pr/tr option required - Enhance godoc thanks to @vdemeester
cefe0d5
to
8074f29
Compare
@vdemeester I have addressed your comments. Let me know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: shashwathi, vdemeester The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
||
```shell | ||
go run test/logs/main.go -tr my-taskrun | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm just seeing this now, v cool! thanks for adding this @shashwathi ! 🎉
Script to follow logs.
-f
flag. Takes name of a file to create to dump logs-n
flag for namepsace. Default namespace isdefault
-pr
to tail logs for pipelinerun and all sub taskruns-tr
to tail logs for taskrun onlyI have been using this locally to help my development. It does not have any tests and it uses
Build
logs script as the base with minor improvements.