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

Adds pipelinerun/taskrun logs follow mode and refactors logs code #76

Merged
merged 5 commits into from
Jun 17, 2019

Conversation

hrishin
Copy link
Member

@hrishin hrishin commented Jun 13, 2019

Changes

It's difficult to keep up with the progress of pipelinerun/taskrun
execution if user is not able to see progressive/ongoing logs.

This patch adds follow flag to taskrun/pipelinerun commands.
So use could fetch those logs in real-time.

tkn tr logs -f
tkn pr logs -f

Fixes

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide
for more details.

Release Notes

To follow the pipelinerun logs tkn  in real time 
tkn pr logs <name> -f


To follow the taskrun logs tkn  in real time 
tr logs <name> -f

@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hrishin

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

@tekton-robot tekton-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 13, 2019
@vdemeester vdemeester added this to the 0.1.0 🐱 milestone Jun 13, 2019
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.

Couple of comments, most of them can be done in a follow-up:

  • We may want to use golang.org/x/xerrors instead of github.com/pkg/errors as this package will be in the standard library in the future — can be done in a follow-up.
  • pkg/errors should be aliased to clierrors or something to not conflicts with pkg/errors (or if we use xerrors, the conflict goes away 😅 )
  • pkg/helper/… feels weird to me. pkg/helper/pipelinerun is more of a "watch pipelinerun logs", same goes for pkg/helper/taskrun, … They should move in another package (pkg/watch/pipelinerun) and splited (having the handleEvent extracted and passed as a function, or at least the part the filters the taskruns based on if we are logging it or not) ?
  • This is gonna need some godoc 👼
  • There is a need to move some package around and have some sort of guidelines on which packages are fine to import from wihch (cf my comment about pkg/cmd, …)

pkg/helper/pods/container_test.go Outdated Show resolved Hide resolved
"sync/atomic"

"github.com/tektoncd/cli/pkg/errors"

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra space not needed 😝

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

func (lr *LogReader) Read() (<-chan Log, <-chan error, error) {
tkn := lr.Clients.Tekton
pr, err := tkn.TektonV1alpha1().PipelineRuns(lr.Ns).Get(lr.Run, metav1.GetOptions{})

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra space not needed 😝

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

defer close(errC)

prTracker := pipelinerun.NewTracker(pr.Name, lr.Ns, lr.Clients.Tekton)
//TODO: return error err chan/error
Copy link
Member

Choose a reason for hiding this comment

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

Is this todo still valid ? what does it refer ?


}

func (lr *LogReader) readLiveLogs(pr *v1alpha1.PipelineRun) (<-chan Log, <-chan error, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel this funtion could be splitted a tiny bit as it is kinda complex. But that could be done in a follow-up

msg string
}

func NewWarning(message string) *WarningError {
Copy link
Member

Choose a reason for hiding this comment

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

We should provide a IsWarning function that would "assert errors for behaviour, not type".
Ref: https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully 👼

@@ -0,0 +1 @@
package formatted
Copy link
Member

Choose a reason for hiding this comment

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

🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

better to name it as format?

Copy link
Member

Choose a reason for hiding this comment

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

My ":thinking:" was about the fact that this file is empty :angel:

@@ -0,0 +1,94 @@
package tasks
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this package be taskruns ?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍


import (
"github.com/tektoncd/cli/pkg/cli"
"github.com/tektoncd/cli/pkg/cmd/taskrun"
Copy link
Member

Choose a reason for hiding this comment

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

Having this import pkg/cmd/* makes me think the LogReader should be extracted in another package. My rational being pkg/cmd/… should import other package, not the other way around 👼

Copy link
Member

Choose a reason for hiding this comment

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

+1 .. these refactors will happen as soon the feature starts to work. It works mostly but doesn't handle edge cases properly.

Copy link
Member

Choose a reason for hiding this comment

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

@sthaha yep, they can even happen in a follow-up 😉

pkg/logs/logs.go Outdated
}

type Streams struct {
// TODO: move this to CLI
Copy link
Member

Choose a reason for hiding this comment

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

To the cli package ?

Copy link
Member

Choose a reason for hiding this comment

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

yes, so that Params interface has a Streams() Streams so that tests can fake the stream as bytes.Buffer for both Out and Err

@@ -0,0 +1,676 @@
# bash completion for tkn -*- shell-script -*-
Copy link
Member

Choose a reason for hiding this comment

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

was this checked in by mistake?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I guess ... 🤔

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@hrishin hrishin marked this pull request as ready for review June 14, 2019 12:25
@vdemeester
Copy link
Member

/test pull-tekton-cli-integration-tests

1 similar comment
@hrishin
Copy link
Member Author

hrishin commented Jun 14, 2019

/test pull-tekton-cli-integration-tests

Its difficult to keep up with progress of pipelinerun/taskrun
execution if user not able to see progressive/ongoing logs.

This patch adds follow flag to taskrun/pipelinerun commands.
So use could fetch the those logs in realtime.

tkn tr logs <name> -f
tkn pr logs <name> -f

Fixes
 - tektoncd#75
continue
}

if l.Log == "LOGEOF" {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't true anymore .. Do we have a special "LOGEOF" ? If so, perhaps we should think of passing "events" in a better way .. events: {started, ended..}

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't true anymore .

🤔

@hrishin
Copy link
Member Author

hrishin commented Jun 17, 2019

@sthaha @vdemeester added final changes, could you please review it?

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
💃

}

//Sort taskruns, to display the taskrun logs as per pipeline tasks order
ordered := trh.SortTasksBySpecOrder(pl.Spec.Tasks, pr.Status.TaskRuns)
Copy link
Member

Choose a reason for hiding this comment

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

As a follow-up, we may want to move this function in tektoncd/pipeline (like tektoncd/pipeline@8552f8b#diff-ccd231265a8c68ecb3e8bae3a6e565cf). Can be useful for other go packages.

Name: pipelineRunName,
Ns: namespace,
Clients: clients,
func (lo *LogOptions) run() error {
Copy link
Member

Choose a reason for hiding this comment

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

This could be done with a method that doesn't take any cobra related struct (aka LogOptions and other params) ? The end result is the same, so all good to me anyway 😉

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 17, 2019
@tekton-robot tekton-robot merged commit 1cabe60 into tektoncd:master Jun 17, 2019
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. cla: yes 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.

None yet

5 participants