-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add module to operate k6 project #1
Conversation
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
esgleam.new("./dist/static") | ||
|> esgleam.entry(project_name <> ".gleam") | ||
|> esgleam.target("es2020") | ||
|> esgleam.raw("--external:k6/http") |
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 know how to make it configurable but it's ok for now.
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.
Oh the external flag can use *
to match wildcard. Will find the time to try. 😃
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.
@tsloughter The PR is ready now. Let me know if you have any feedback. :) |
Should |
Also, maybe can be done later but I think Similarly Also, why |
Looks like another option to consider instead of using https://grafana.com/docs/k6/latest/using-k6/scenarios/#options |
Oh, but we probably can't even export |
Oh yes, it should remove. |
I thought about generating gleam code as well. When we call |
I remember that some runtime, they threat I also fine with either |
We might need to make |
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
src/k6_gleam_example.gleam
Outdated
@@ -1,6 +1,3 @@ | |||
// TODO: move it to k6/http.gleam. | |||
@external(javascript, "./k6_wrapper.js", "get") |
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 leave it for now. Will be revisit after working on binding. :)
So I don't think we'll be able to do the But maybe there are like anonymous structs I don't know about in Gleam that would convert from |
But, what I did to test to make sure this at least worked to call a non-default function was create a
Just annoying that you have to define a scenario (though maybe any tests beyond playing around with k6 would warrant this anyway). |
We might not need to convert to json but a do something in the |
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
I modify |
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
@tsloughter I just make options configuration works in Gleam. The idea is having a Gleam record that reflect to k6 configuration and in javascript runner file, calling the diff --git a/examples/basic_k6/hello_runner.js b/examples/basic_k6/hello_runner.js
index ffe6939..b5701b1 100644
--- a/examples/basic_k6/hello_runner.js
+++ b/examples/basic_k6/hello_runner.js
@@ -1,4 +1,14 @@
-import { main } from './dist/static/hello_runner.js'
+import * as hello_runner from "./dist/static/hello_runner.js";
-export default main
-
\ No newline at end of file
+if (!hello_runner.main) {
+ throw new Error("A main function is required");
+}
+
+let runner_options = hello_runner.options();
+export const options = {
+ duration: runner_options.duration[0],
+ vus: runner_options.vus[0],
+ vusMax: runner_options.vus_max[0],
+};
+
+export default hello_runner.main;
diff --git a/examples/basic_k6/src/hello_runner.gleam b/examples/basic_k6/src/hello_runner.gleam
index ab628e2..ea5f64b 100644
--- a/examples/basic_k6/src/hello_runner.gleam
+++ b/examples/basic_k6/src/hello_runner.gleam
@@ -1,4 +1,10 @@
+import gleam/option.{Some}
import k6/http
+import k6/options.{type Options, Options}
+
+pub fn options() -> Options {
+ Options(duration: Some("10s"), vus: Some(10))
+}
pub fn main() {
http.get("https://test.k6.io")
diff --git a/src/k6/options.gleam b/src/k6/options.gleam
new file mode 100644
index 0000000..65eafb1
--- /dev/null
+++ b/src/k6/options.gleam
@@ -0,0 +1,5 @@
+import gleam/option.{type Option}
+
+pub type Options {
+ Options(duration: Option(String), vus: Option(Int))
+} What we need to do next are:
What do you think? |
@@ -0,0 +1,5 @@ | |||
// Returns runner name including js and gleam file name. | |||
pub fn build_runner_name(name: String) -> #(String, String, String) { | |||
let name = name <> "_runner" |
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 name can be change on both js
and gleam
side.
Part of why I wanted an But this is great if the user can type check options even if they still need a runner. Another option, that doesn't get type checked but removes the need for a runner, is require the use of a file, like |
I still doubt on how to set it in the library. But yeah, it is interesting. :) |
Or generating the option file when calling k6/new?? |
@tsloughter I found the alternative way, embeded gleam into k6 extension and using The technique behind the scene is use the extension to hook See #3 for the implementation details. It's a quick hack, it might have a bug somewhere. 😂 |
Very nice! Looks like it'll take me a bit more time to review this :) |
This PR introduce 2 module commands:
k6/new
- a module command to generate a runner, an entrypoint file uses for running k6.k6/build
- building a gleam code into js module withesbuild
. Previously issrc/build.gleam
.The reason I move the commands to under
src/k6
because I want a namespace when running withgleam run -m
.Usage
gleam new
k6_gleam
to a dependencies list.gleam run -m k6/new
to generate necessary file.gleam run -m k6/build
to build javascript.k6 run --vu <vu> --duration <duration> runner.mjs
. You will get a ton of console.log. 🎉I also add an example to this PR. You can use
gleam run -m k6/build
andk6
to run the project.