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

Add script to tail logs for pipelinerun and taskruns #336

Merged
merged 1 commit into from
Dec 21, 2018

Conversation

shashwathi
Copy link
Contributor

Script to follow logs.

  • -f flag. Takes name of a file to create to dump logs
  • -n flag for namepsace. Default namespace is default
  • -pr to tail logs for pipelinerun and all sub taskruns
  • -tr to tail logs for taskrun only

I 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.

@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 17, 2018
@shashwathi
Copy link
Contributor Author

/test pull-knative-build-pipeline-integration-tests

Copy link
Member

@vdemeester vdemeester left a 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 🙃 )

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]
Copy link
Member

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 ? 🤔

Copy link
Contributor Author

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

Copy link
Collaborator

@bobcatfish bobcatfish left a 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

return fmt.Errorf("waiting for container: %v", err)
}

container := pod.Status.InitContainerStatuses[i]
Copy link
Collaborator

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!)

Copy link
Collaborator

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

Copy link
Contributor Author

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.


_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

tlogs "github.com/knative/build-pipeline/test/logs/helpers"
Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

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 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is for tracking logs from pod directly. #107 issue is about uploading logs to external bucket. I do not think they are related. After #107 I could see another "How do I access logs of taskruns?" point which should hold instructions on how to fetch logs from bucket.

@shashwathi shashwathi force-pushed the tail-logs branch 2 times, most recently from 2df1219 to cefe0d5 Compare December 20, 2018 22:38
@shashwathi
Copy link
Contributor Author

@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)
Copy link
Member

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 ?

"k8s.io/client-go/rest"
)

//tailPrLogs tails the logs for pipeline run.
Copy link
Member

Choose a reason for hiding this comment

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

s/tailPrLogs/TailLogs

"k8s.io/client-go/rest"
)

func TailLogs(ctx context.Context, cfg *rest.Config, trName, namespace string, out io.Writer) error {
Copy link
Member

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
@shashwathi
Copy link
Contributor Author

@vdemeester I have addressed your comments. Let me know

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 21, 2018
@knative-prow-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 8725a1a into tektoncd:master Dec 21, 2018

```shell
go run test/logs/main.go -tr my-taskrun
```
Copy link
Collaborator

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 ! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants