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

Wait for file log to drain before k6 exits #2414

Merged
merged 1 commit into from
Mar 7, 2022
Merged

Wait for file log to drain before k6 exits #2414

merged 1 commit into from
Mar 7, 2022

Conversation

na--
Copy link
Member

@na-- na-- commented Mar 7, 2022

This closes #2413, a minor deficiency that slipped by in #2285

The integration test for this is unfortunately will have to wait until #2412 is merged. That is in fact how I found the issue, tried to write an integration for sending logs to a file and it failed because the file didn't contain the expected text at the end of the test 😅 So we'll have to merge this in v0.37.0 without a test 😞

@na-- na-- added this to the v0.37.0 milestone Mar 7, 2022
) (logrus.Hook, error) {
// TODO: fix this so it works correctly with relative paths from the CWD
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you mean by this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed that we don't explicitly check if we got a relative path here and instead just open exactly what we were given:

k6/log/file.go

Line 108 in 1e28a3e

file, err := os.OpenFile(h.path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o600)

This works, for now, since we're directly using the os package and it will properly handle relative paths based on the current working directory. However, after we switch to afero.Fs here, we will need to explicitly account for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you expand this comment there with that info :)

Copy link
Member Author

Choose a reason for hiding this comment

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

No need, I plan to fix it with a small commit in #2412 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW, this is the fix and the test to verify it: 7574bd2

log/file.go Outdated Show resolved Hide resolved
cmd/root.go Outdated Show resolved Hide resolved
}

// FileHookFromConfigLine returns new fileHook hook.
func FileHookFromConfigLine(
ctx context.Context, fallbackLogger logrus.FieldLogger, line string,
ctx context.Context, fallbackLogger logrus.FieldLogger, line string, done chan struct{},
Copy link
Contributor

@olegbespalov olegbespalov Mar 7, 2022

Choose a reason for hiding this comment

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

This done channel looks more like the internal state. Do you think we should accept it as input?

Can a signature be like?

FileHookFromConfigLine(ctx context.Context, fallbackLogger logrus.FieldLogger, line string) (logrus.Hook, chan struct{}, error)

Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, even with the doneCh <-chan sruct{}, but I guess it is outside of the scope of this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm yeah, that is slightly better 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

actually, I think I'll refactor both this and LokiFromConfigLine in a separate PR, so I'll leave it as it is for now

@na-- na-- changed the base branch from cleanup-1 to master March 7, 2022 11:34
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

👍

) (logrus.Hook, error) {
// TODO: fix this so it works correctly with relative paths from the CWD
Copy link
Contributor

Choose a reason for hiding this comment

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

can you expand this comment there with that info :)

@na-- na-- mentioned this pull request Mar 7, 2022
@na-- na-- merged commit fea17a1 into master Mar 7, 2022
@na-- na-- deleted the cleanup-1.5 branch March 7, 2022 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--log-output=file does not always flush all logs to the file after k6 is done
3 participants