Originally Proxy Server Issue, now Windows Powershell Compatibility Issue

All connections for our company outside our network must be made through a proxy server. How do I create a k6 script that will make a connection out through our proxy server?

I saw this issue, but I wasn’t sure how to utilize it.
https://github.com/loadimpact/k6/issues/220

Ex script.js

import { sleep } from “k6”;
import http from “k6/http”;

export HTTP_PROXY=http://PROXYSERVER:8080;
export HTTPS_PROXY=http://PROXYSERVER:8080;

export default function() {
http.get(“http://www.loadimpact.com”);
sleep(3);
}

When I try to “k6 run script.js” I get the following error:

SyntaxError: F:/temp/LoadImpact/script.js: Unexpected token, expected { (4:7)\n 2 | import http from “k6/http”;\n 3 | \n> 4 | export HTTP_PROXY=http://PROXYSERVER:8080\n | ^\n 5 | export
HTTPS_PROXY=http://PROXYSERVER:8080\n 6 | \n 7 | export default function() { at :2:28542(114)

As an update, I’m working on a windows PC trying to interface with K6 via powershell. I’ve found the following works:

set-item Env:HTTP_PROXY http://PROXYSERVER:8080
set-item Env:HTTPS_PROXY http://PROXYSERVER:8080
k6 run script.js

However, when the script is running (i.e. during test execution), powershell is interpreting the in progress messages as errors. This is what I see in my output window:

      /\      |‾‾|  /‾‾/  /‾/   
 /\  /  \     |  |_/  /  / /    
/  \/    \    |      |  /  ‾‾\  

/ \ | |‾\ \ | () |
/ __________ \ |__| _
\ ___/ .io

init [----------------------------------------------------------] runner
init [----------------------------------------------------------] options
init [----------------------------------------------------------] executor
init [----------------------------------------------------------]   engine
init [----------------------------------------------------------]   collector
init [----------------------------------------------------------]   server

execution: local
output: -
script: script.js

duration: -, iterations: 1
     vus: 1, max: 1

k6 : time=“2019-03-12T14:22:04-04:00” level=info msg=Running i=0 t=948.0543ms
At line:1 char:1

  • k6 run script.js
  •   + CategoryInfo          : NotSpecified: (time="2019-03-1...=0 t=948.0543ms:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

time=“2019-03-12T14:22:05-04:00” level=info msg=Running i=0 t=1.9481115s
time=“2019-03-12T14:22:06-04:00” level=info msg=Running i=0 t=2.9471686s
time=“2019-03-12T14:22:07-04:00” level=info msg=Running i=0 t=3.9482259s
time=“2019-03-12T14:22:08-04:00” level=info msg=Running i=0 t=4.9482831s
time=“2019-03-12T14:22:09-04:00” level=info msg=“Test finished” i=1 t=5.4523119s
init [----------------------------------------------------------] starting
data_received…: 52 kB 9.6 kB/s
data_sent…: 1.1 kB 198 B/s
http_req_blocked…: avg=278.5ms min=55ms med=278.5ms max=502ms p(90)=457.3ms p(95)=479.65ms
http_req_connecting…: avg=16.5ms min=16ms med=16.5ms max=17ms p(90)=16.9ms p(95)=16.95ms
http_req_duration…: avg=922ms min=147ms med=922ms max=1.69s p(90)=1.54s p(95)=1.61s
http_req_receiving…: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_sending…: avg=500µs min=0s med=500µs max=1ms p(90)=900µs p(95)=950µs
http_req_tls_handshaking…: avg=131.5ms min=0s med=131.5ms max=263ms p(90)=236.7ms p(95)=249.85ms
http_req_waiting…: avg=921.5ms min=146ms med=921.5ms max=1.69s p(90)=1.54s p(95)=1.61s
http_reqs…: 2 0.366817/s
iteration_duration…: avg=5.45s min=5.45s med=5.45s max=5.45s p(90)=5.45s p(95)=5.45s
iterations…: 1 0.183408/s
vus…: 1 min=1 max=1
vus_max…: 1 min=1 max=1

When I try to run it via command prompt, the output looks correct and I don’t see any errors/exceptions. So this appears to be an issue with how powershell interprets k6’s output. Is there any way k6 can be made to be compatible with powershell without throwing phantom errors?

Hi,
Yes you need to set the HTTP_PROXY as environmental variable not prepend export in the script :wink: .
From this it looks like this should only happen in powershell ISE … whatever that is. This happens because k6 writes to stderr not stdout and currently there is no way to change this but through redirecting output streams by adding 2>&1 to the end of the command line calling k6

Unfortunately (or fortunately for me :slight_smile: ) I am not running windows and haven’t for more than a decade, so debugging this will be much harder. Please open an issue and paste the output mark it all and click the insert code button that looks like <>. This is so we can better see how it truly looks as in here it looks like it got formatted a little bit by discourse :frowning:

Thank you for your response. I have opened an issue. Note: even if I redirect output using powershell, it still registers an error. Running from the command prompt works fine. However, I’m working on some exception handling logic.