-
Notifications
You must be signed in to change notification settings - Fork 242
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
Conversation
[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 |
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.
Couple of comments, most of them can be done in a follow-up:
- We may want to use
golang.org/x/xerrors
instead ofgithub.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 toclierrors
or something to not conflicts withpkg/errors
(or if we usexerrors
, the conflict goes away 😅 )pkg/helper/…
feels weird to me.pkg/helper/pipelinerun
is more of a "watch pipelinerun logs", same goes forpkg/helper/taskrun
, … They should move in another package (pkg/watch/pipelinerun
) and splited (having thehandleEvent
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/cmd/pipelinerun/log_reader.go
Outdated
"sync/atomic" | ||
|
||
"github.com/tektoncd/cli/pkg/errors" | ||
|
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: extra space not needed 😝
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.
👍
pkg/cmd/pipelinerun/log_reader.go
Outdated
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{}) | ||
|
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: extra space not needed 😝
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.
👍
pkg/cmd/pipelinerun/log_reader.go
Outdated
defer close(errC) | ||
|
||
prTracker := pipelinerun.NewTracker(pr.Name, lr.Ns, lr.Clients.Tekton) | ||
//TODO: return error err chan/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.
Is this todo still valid ? what does it refer ?
|
||
} | ||
|
||
func (lr *LogReader) readLiveLogs(pr *v1alpha1.PipelineRun) (<-chan Log, <-chan error, 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.
I feel this funtion could be splitted a tiny bit as it is kinda complex. But that could be done in a follow-up
pkg/errors/logerror.go
Outdated
msg string | ||
} | ||
|
||
func NewWarning(message string) *WarningError { |
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.
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 👼
pkg/formatted/colors.go
Outdated
@@ -0,0 +1 @@ | |||
package formatted |
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.
better to name it as format
?
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.
My ":thinking:" was about the fact that this file is empty :angel:
pkg/helper/tasks/tasks.go
Outdated
@@ -0,0 +1,94 @@ | |||
package tasks |
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.
shouldn't this package be taskrun
s ?
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.
👍
pkg/helper/tasks/tasks.go
Outdated
|
||
import ( | ||
"github.com/tektoncd/cli/pkg/cli" | ||
"github.com/tektoncd/cli/pkg/cmd/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.
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 👼
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.
+1 .. these refactors will happen as soon the feature starts to work. It works mostly but doesn't handle edge cases properly.
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.
@sthaha yep, they can even happen in a follow-up 😉
pkg/logs/logs.go
Outdated
} | ||
|
||
type Streams struct { | ||
// TODO: move this to CLI |
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.
To the cli
package ?
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.
yes, so that Params interface has a Streams() Streams
so that tests can fake the stream as bytes.Buffer
for both Out
and Err
bash_completion.sh
Outdated
@@ -0,0 +1,676 @@ | |||
# bash completion for tkn -*- shell-script -*- |
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.
was this checked in by mistake?
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.
yeah I guess ... 🤔
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. ℹ️ Googlers: Go here for more info. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
/test pull-tekton-cli-integration-tests |
1 similar comment
/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
pkg/cmd/pipelinerun/log_writer.go
Outdated
continue | ||
} | ||
|
||
if l.Log == "LOGEOF" { |
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 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..}
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 isn't true anymore .
🤔
@sthaha @vdemeester added final changes, could you please review it? |
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
💃
} | ||
|
||
//Sort taskruns, to display the taskrun logs as per pipeline tasks order | ||
ordered := trh.SortTasksBySpecOrder(pl.Spec.Tasks, pr.Status.TaskRuns) |
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.
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 { |
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 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 😉
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