-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make k6 wait for loki to finish pushing before stopping #1694
Conversation
This is dependant on #1691 |
79ffeda
to
6475b7a
Compare
ec3d598
to
d9381c0
Compare
This is especially useful if there was an error that stopped the execution really fast but loki wouldn't had time to log it before it was stopped
96f24bf
to
44627c9
Compare
Codecov Report
@@ Coverage Diff @@
## master #1694 +/- ##
==========================================
- Coverage 71.42% 71.39% -0.04%
==========================================
Files 176 178 +2
Lines 13681 13751 +70
==========================================
+ Hits 9772 9817 +45
- Misses 3298 3322 +24
- Partials 611 612 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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, just some questions and nitpicks.
cmd/root.go
Outdated
if err != nil { | ||
return err | ||
} | ||
// This is get all for the main/root k6 command struct |
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 don't understand this comment. Typo?
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 I meant to write
This is to get all fields for the main/root k6 command struct
but I eat half the words ? I remember that this strut was 4 things in the begining so 🤷
cmd/root.go
Outdated
Long: BannerColor.Sprintf("\n%s", consts.Banner()), | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
PersistentPreRunE: c.persistentPerRunE, |
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.
PersistentPreRunE: c.persistentPerRunE, | |
PersistentPreRunE: c.persistentPreRunE, |
// TODO: figure out something else... currently, with the wrappers | ||
// below, we're stripping any colors from the output after we've | ||
// added them. The problem is that, besides being very inefficient, | ||
// this actually also strips other special characters from the | ||
// intended output, like the progressbar formatting ones, which | ||
// would otherwise be fine (in a TTY). | ||
// | ||
// It would be much better if we avoid messing with the output and | ||
// instead have a parametrized instance of the color library. It | ||
// will return colored output if colors are enabled and simply | ||
// return the passed input as-is (i.e. be a noop) if colors are | ||
// disabled... |
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.
Strong 👍 for fixing this. I didn't find an existing GH issue for it, so can you create one and link it here instead of the explanation?
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 just moved this around ... this was written by @na-- a while ago a9cc130 😉 I don't think having this in an issue will help anyone, if you start working on it, maybe make one and we can discuss it but in general I consider this a refactoring and having refactoring issues given the amount of issues we have that IMO we will never actually work on .. so they are basically "ideas" makes the issues hard to use so ... yeah, I don't think this needs to be added to an issue.
I myself have added issues (mostly refactoring ones) that again are hardly unlikely for us to ever work on ... and even if we did the fact that there is an issue would've not helped in any way.
On related note, I have a branch with 1 more commit where I get EVEN more of the global variables like noColor in a struct and get it passed around, but that will have to wait for v0.30.0 maybe I can try this then
cmd/root.go
Outdated
// RootCmd represents the base command when called without any subcommands. | ||
c.cmd = &cobra.Command{ |
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's no RootCmd
anymore, and I find the generic newCommand
/command
names slightly misleading since it's only for the root command, but maybe just:
// RootCmd represents the base command when called without any subcommands. | |
c.cmd = &cobra.Command{ | |
// The base command when called without any subcommands. | |
c.cmd = &cobra.Command{ |
@@ -282,7 +289,7 @@ func (h *lokiHook) loop() { | |||
case <-h.ctx.Done(): | |||
ch := make(chan int64) | |||
pushCh <- ch | |||
ch <- 0 | |||
ch <- time.Now().Add(time.Second).UnixNano() |
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.
Since this is the cutoff time, is the second to deal with time sync issues and get some last events? Should it be equal to the push period, so maybe h.pushPeriod
here instead?
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 ... the basic idea is that ... as far as I can see you can call time.Now() in two parallel goroutines ... and you won't exactly get ... sequential times even if in reality they were ... so I added some time to get "hopefully" everything.
I don't think that h.pushPeriod
is better ... if anything I am more for time.Hour
and a comment explaining why it is done at all (this took me 1 hour to figure out why I wasn't getting the last messages even though I was waiting for them and around 10 fmt.Printlns)
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, though I'd prefer if we have the global timeout as well... And I'm not sure I like the rootCommand
struct, but I guess it's better than globals and we're restricted by the structure imposed from cobra, so it's fine for now...
Long: BannerColor.Sprintf("\n%s", consts.Banner()), | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
PersistentPreRunE: c.persistentPreRunE, | ||
} | ||
|
||
confDir, err := os.UserConfigDir() |
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.
At some later point in this refactoring series, we should probably have an interface with some of the same methods as the os
package (Environ()
, Getwd()
and the other FS ones, etc.) and pass that in as a parameter to these constructors...
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 ... that is a good idea
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.
The 1s delay to get the last messages seems a bit arbitrary, and maybe we should increase it or consider more robust solutions, but we can come back to it if needed, so LGTM.
No description provided.