This is one of my other attempt of solving this problem. In this attempt to send protobuf payload I have written a custom extension using xk6 and in my custom Go code I am making a http request using GO(net/hhtp) package with protobuf payload. This works, but the problem is since it is not a k6/http call so http metrics are not being captured for that URL(http_connecting, http_req_duration etc). Is there any way to capture the http metrics in this case.
Yes, you can certainly do that.
The logic of making HTTP calls in k6 is split between 2 places: this part deals with parsing and validating the request from the JS script and then calls this function actually makes and measures HTTP requests. Your extension can do what the code from the first link does and directly use the code from the second package as a Go dependency. That will emit all of the metrics that a normal request started from k6/http
emits.
Thanks @ned. Will try this.
Hi @ned ,
I was trying the approach. In this, do I need to create a Client first and then attach my method to it since httpext.MakeRequest expects a Context and state along with request. I tried creating a client but somehow my state and Context values are coming out ‘nil’. My need was pretty simple where I have to hit one endpoint(sending GET and POST to one endpoint), so I was just wondering if there is some example where I can look how context, state and req is being set if we are making a http request directly from httpext.MakeRequest.
The example is in the /js/modules/k6/http/request.go
code - the first link in my previous post. I don’t think there is anything else I can point you to, sorry.
I got it working! Had to read a little more about goja and it’s implementation in k6 . Thanks.