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

Introduces Reader into k6deps.Source #69

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

olegbespalov
Copy link
Contributor

What?

While one of the internal reviews of another pull request that relies on that library, there was a valid concern raised that if we provide a go library it makes more sense to rely on the standard interfaces and use less file system, which is even currently seems to be possible, but it requires full copy of archive.

This minor change makes it possible to use directly io.Reader in the k6deps.Source

Why?

Make API more go idiomatic and potentially reduce some steps

@olegbespalov olegbespalov requested a review from a team as a code owner February 26, 2025 08:21
@olegbespalov olegbespalov requested review from szkiba and removed request for a team February 26, 2025 08:21
@olegbespalov
Copy link
Contributor Author

cc also: @pablochacin

@@ -70,7 +99,7 @@ func (opts *Options) lookupEnv(key string) (string, bool) {
}

func loadSources(opts *Options) error {
if !opts.Archive.Ignore && (len(opts.Archive.Contents) > 0 || len(opts.Archive.Name) > 0) {
if !opts.Archive.Ignore && !opts.Archive.IsEmpty() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, maybe a side-question for Ivan/Pablo, why the loadArchive is uniq the way we load, I mean it seems like if archive provided we completely ignore other paths, like manifest/env, could it cause any side effects? 🤔

@pablochacin pablochacin self-requested a review February 26, 2025 14:58
@pablochacin
Copy link
Contributor

pablochacin commented Feb 26, 2025

@olegbespalov I see the value of trying to move some work in-memory, but I fail to see how this PR accomplished this objective. Introducing the reader just skips the step of opening the archive, but it is still extracted into a temporary directory, where it's processed with k6pack.

I see the objective you propose could be achieved by using a file system abstraction to process the archive, allowing for an in-memory processing. There are even packages that implement the fs interface on top of an .tar file, so we could even remove the logic regarding processing the archive altogether.

@olegbespalov
Copy link
Contributor Author

olegbespalov commented Feb 26, 2025

but I fail to see how this PR accomplished this objective

This PR doesn't aim to fix everything, like you pointed out (and definitely I saw it in the code) we have a dependency of the k6pack which still works with FS and I mentioned that in #70

Where it still brings value, as the first step, is the way how we can reduce the steps when we use the analysis. Imagine the use case where you have an archive stored remotely.

So right now you have two options:

  • download the archive and store it as the temporary file and pass it to the analyse
  • get full []bytes of the archive and pass it as Content

The first option introduces additional overhead of managing the files, the second has the downside that you need to allocate the big chink of memory (imagine big archive) when passing the content. But working with reader, we can just pipe the response body and process it efficiently, or fully efficiently once everything will be adjusted.

Copy link
Contributor

@pablochacin pablochacin left a comment

Choose a reason for hiding this comment

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

LGTM

@pablochacin pablochacin merged commit f036211 into grafana:main Feb 27, 2025
5 checks passed
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.

2 participants