grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
25.16k stars 1.25k forks source link

Failed to send metrics to cloud #316

Closed MengLi619 closed 7 years ago

MengLi619 commented 7 years ago

I got a 'WARN[0048] Failed to send metrics to cloud error="An error occurred talking to Load Impact cloud"' when I output the result to the cloud, I already set the K6CLOUD_TOKEN properly, and my test was also shown in the insight but has no data.

artych commented 7 years ago

Hello @dream83619, could you share your script (or simplified version), so I'll try to reproduce the issue? Also try to check if a basic script works, like:

import http from "k6/http";
import { sleep } from "k6";

export let options = {
  stages: [
    { duration: "60s", target: 50 }
  ],

  ext: {
    loadimpact: {
      name: 'Simple test'
    }
  }
}

export default function() {
  http.get('http://test.loadimpact.com/pi.php?decimals=5');
  sleep(1);
};
MengLi619 commented 7 years ago

this is my code, thank you

import http from "k6/http";
import { check, sleep } from "k6";

export let options = {
    vus: 10,
    duration: "30s"
};

const BASE_URL = 'http://www.xiaoshuaizhi.com/xiaoshuaizhi-mobile/';
const TOKEN = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjI1MDU2MjQ3MDUsInVzZXJfbmFtZSI6IjI1MDMzNTI5LTlhMzctNDA0ZC04MDZlLWU3YmViMzg3MGVlNSIsImp0aSI6IjUzZjk4MTU3LTAxNzEtNGFmZS1hMDgzLTYxZmEzMTVkMWEyOCIsImNsaWVudF9pZCI6Im1vYmlsZSIsInNjb3BlIjpbIm1vYmlsZSJdfQ.XYKfhv-OuprdL_0mCZAnCbb59-Sey45nBlb_nMQ9ZIg";

export default function() {

    let res = http.get(`${BASE_URL}users/me`, { headers: { "Authorization": TOKEN } });
    check(res, {
        "status was 200": (r) => r.status == 200,
    });
};

I set K6CLOUD_TOKEN variable in the ~/.bash_profile. export K6CLOUD_TOKEN=...

and run script using k6 run -o cloud load-test.js

the console output:

  execution: local
     output: Load Impact (https://app.loadimpact.com/k6/runs/4631)
     script: /Users/mengli/Work/tests/k6-load-test/load-test.js (js)

   duration: 30s, iterations: 0
        vus: 10, max: 10

    web ui: http://127.0.0.1:6565/

WARN[0044] Failed to send metrics to cloud               error="An error occurred talking to Load Impact cloud"
WARN[0080] Failed to send metrics to cloud               error="An error occurred talking to Load Impact cloud"

My OS is macOS 10.12.4, if you can pass my script, I think it's probably because our government firewall, and I can't do anything with it.

Thanks a lot.

artych commented 7 years ago

I've run your script several times and once I've detected the issue above.

To avoid it I'd recommend you always to add some sleep time between iterations, like in the example above.

Without some delay fast responses from system under test can cause k6 to perform huge amount of reqs and finally to overflow LoadImpact Insights by the requests raw data.

Try to add

sleep(1);

after check(...); and run it, hope it helps.

If you have concerns about connectivity (as you mentioned government firewall) I'd say you can reach Load Impact cloud, otherwise you'll see another error message. So you just have to check your target system by running curl request manually or by using postman.

MengLi619 commented 7 years ago

I add the sleep(1)code, and the error is gone. thank you for your quick response. k6 is really an excellent work, and i wish you can continue to make it more and more excellent, and I will recommend our team to use it in the future, thank you.