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

Feat/support scenarios #89

Merged
merged 15 commits into from
Dec 6, 2021
Merged

Feat/support scenarios #89

merged 15 commits into from
Dec 6, 2021

Conversation

w1kman
Copy link
Contributor

@w1kman w1kman commented Oct 29, 2021

Support for converting several archives with convert

convert now accepts an array of archives. Every archive will become its own function in the produced script.

I've added one optional properties on the Log interface to expose some kind of control over the result

interface Log {
  ...
  exportAs?: String // Name of the function that wraps the created script (default: 'main')
}

@w1kman w1kman marked this pull request as ready for review October 29, 2021 12:01
Copy link
Collaborator

@legander legander left a comment

Choose a reason for hiding this comment

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

Cool that we can now generate multiple scenario scripts 🤩
Left a few comments and some questions as well. There is one particular piece that I think needs to be addressed. The execution flow of the persistedImports was for me at least somewhat difficult to follow, more difficult than it needs to be I think.

TL;DR
The following is not a requirement, I just want to pick you and the other reviewers brains a little bit and see what you think.

We have talked about this earlier in the week but I'm going to mention it here again because I encountered it again now when re-reviewing.
So.. one thing that stood out when testing the feature was that it was not so easily tested compared to other features since it requires multiple archives passed in an array rather than one single archive (which means we cannot just simply run har-to-k6 examples/multi-scenario.har).
I understand that code tries to be as non intrusive as possible to the HAR spec and existing implementation but I think conceptually it would make more sense to have one single data structure for grouping the scenarios since the options needs to be shared.

In the current PR implementation a test can be generated by one or more HARarchives. If multiple archives are passed then the options from the first archive will be the options which end up in the script. @w1kman please correct me if this is wrong.

I think if we instead merge the data into one unit it would make not only the implementation simpler but also would allow CLI support (which is most likely not need tho) but also make it conceptually clearer.

Configuration examples

Current PR implementation (separate archives)

- archive1.har (holds the scenario options)
- archive2.har

convert([archive1, archive2])

Proposition (combined data)

// single HAR file
{
   options: {} // script options, scenario options etc..
   archives: [
      { Scenario1HAR },
      { Scenario2HAR },
   ]
}
convert(archive)

src/convert.js Outdated Show resolved Hide resolved
src/render/index.js Outdated Show resolved Hide resolved
src/make.js Outdated Show resolved Hide resolved
src/render/logic.js Outdated Show resolved Hide resolved
Copy link
Contributor

@allansson allansson left a comment

Choose a reason for hiding this comment

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

Left a few comments.

I think that the global state needs to be fixed, before I can approve this. It's unlikely to cause any issues, but if it does it's gonna be a pain to figure out why.

li-har.spec.md Outdated Show resolved Hide resolved
src/parse/exportAs.js Outdated Show resolved Hide resolved
src/render/prettify.js Outdated Show resolved Hide resolved
src/make.js Outdated Show resolved Hide resolved
src/render/logic.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@w1kman w1kman marked this pull request as draft November 5, 2021 13:44
@w1kman w1kman marked this pull request as ready for review November 8, 2021 15:16
Copy link
Collaborator

@legander legander left a comment

Choose a reason for hiding this comment

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

These are my change requests:

  1. Move resolving logic to convert.js but abstracted into a function resolveImports or something fitting.
  2. Only if this case is not already covered, add simple validation rule that prevents multiple default exports.

src/render/prettify.js Outdated Show resolved Hide resolved
options(main),
...logicFunctions,
]
.filter(item => item)
.join(`\n\n`)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, this is in line with what I requested 👍 I think it should be happening earlier in the cycle though. Rather than having this logic in render I think it makes more sense to have it all the way up in convert.js making the flow:

  1. normalize
  2. validate
  3. parse
  4. resolveImports
  5. render

I think it will require minimal changes since this added logic already works on the result from parse.
wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Come to think of it maybe it would make sense to not only validate the archives individually but also the set. If I'm not mistaken the current implementation would not complain if there were multiple archives configured to export default right?

Perhaps we should add a simple validation rule that checks the set then also runs each individual archive like today

function convert() {
  return normalize(archives, options)
    |> validate // validates both the set and also individual archives
    |> parse 
    |> resolveImports
    |> render
}

Copy link
Contributor Author

@w1kman w1kman Nov 15, 2021

Choose a reason for hiding this comment

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

The general idea is to allow an advanced user to convert several HAR objects into one script (rather than have to convert them one by one and then stitch them together). The intended output of a "multi conversion" is multiple test scenarios, excluding options.

Rather than having this logic in render I think it makes more sense to have it all the way up in convert.js making the flow

Sure. The same reasoning should also apply for the function names (moving that as well).

Come to think of it maybe it would make sense to not only validate the archives individually but also the set.

I don't see a case where two archives could pass validation as a single but cause a fail as a set (unless we're building scenario options).

If I'm not mistaken the current implementation would not complain if there were multiple archives configured to export default right?

There can only be one default export per script (no matter the configuration).

Perhaps we should add a simple validation rule that checks the set then also runs each individual archive like today

I cannot come up with anything to validate unless we want to throw on colliding names (which are now resolved instead).

@legander legander self-requested a review November 15, 2021 14:01
Copy link
Collaborator

@legander legander left a comment

Choose a reason for hiding this comment

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

Works well 👍 📦

Copy link
Contributor

@allansson allansson left a comment

Choose a reason for hiding this comment

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

Just a small question, but other than that I think it looks good.

Comment on lines +7 to +13
semi: false,
arrowParens: 'avoid',
parser: 'babel',
plugins: [babelParser],
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is technically a breaking change, as it means that the output will produce a different output from before. What was the reasoning behind it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Produced k6 script should look more like examples on k6.io.

typings/main.d.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@allansson allansson left a comment

Choose a reason for hiding this comment

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

LGTM! Great work! This is an awesome feature!

@w1kman w1kman merged commit b009254 into master Dec 6, 2021
@w1kman w1kman deleted the feat/support-scenarios branch December 6, 2021 10:03
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.

None yet

3 participants