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

fix: csv output for non indexable metrics #2829

Merged
merged 1 commit into from
Jan 13, 2023
Merged

fix: csv output for non indexable metrics #2829

merged 1 commit into from
Jan 13, 2023

Conversation

leonyork
Copy link
Contributor

@leonyork leonyork commented Dec 21, 2022

Description

Fix for #2827 without refactoring the CSV output or adding integration tests (which are waiting on #2821).

  • Removes the empty vu and iter columns from the CSV output if they are included as system tags.
  • Includes the vu and iter tags in the metadata column of the output if they are included as system tags.

Manual Testing

I've not added any integration tests as the integration tests are being refactored in #2821

Instead I get the follow results:

*** TEST 1 - vu and iter set in system tags ***

SCRIPT:

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

    export const options = {
      systemTags: ["vu", "iter"],
    };

    export default function () {
      http.get("https://test.k6.io");
      sleep(0.5);
    }

RESULTS (RAW):

metric_name,timestamp,metric_value,extra_tags,metadata
http_reqs,1671829510,1.000000,,vu=1&iter=0
http_req_duration,1671829510,209.901522,,vu=1&iter=0
http_req_blocked,1671829510,243.403270,,vu=1&iter=0
http_req_connecting,1671829510,101.651533,,vu=1&iter=0
http_req_tls_handshaking,1671829510,105.763562,,vu=1&iter=0
http_req_sending,1671829510,0.029080,,iter=0&vu=1
http_req_waiting,1671829510,209.601753,,vu=1&iter=0
http_req_receiving,1671829510,0.270689,,vu=1&iter=0
http_req_failed,1671829510,0.000000,,vu=1&iter=0
data_sent,1671829511,438.000000,,vu=1&iter=0
data_received,1671829511,16962.000000,,vu=1&iter=0
iteration_duration,1671829511,954.882908,,vu=1&iter=0
iterations,1671829511,1.000000,,vu=1&iter=0

RESULTS (FORMATTED):

metric_name               timestamp   metric_value  extra_tags  metadata
http_reqs                 1671829510  1.000000                  vu=1&iter=0
http_req_duration         1671829510  209.901522                vu=1&iter=0
http_req_blocked          1671829510  243.403270                vu=1&iter=0
http_req_connecting       1671829510  101.651533                vu=1&iter=0
http_req_tls_handshaking  1671829510  105.763562                vu=1&iter=0
http_req_sending          1671829510  0.029080                  iter=0&vu=1
http_req_waiting          1671829510  209.601753                vu=1&iter=0
http_req_receiving        1671829510  0.270689                  vu=1&iter=0
http_req_failed           1671829510  0.000000                  vu=1&iter=0
data_sent                 1671829511  438.000000                vu=1&iter=0
data_received             1671829511  16962.000000              vu=1&iter=0
iteration_duration        1671829511  954.882908                vu=1&iter=0
iterations                1671829511  1.000000                  vu=1&iter=0
*** TEST 2 - vu and iter set in system tags along with an extra tag ***

SCRIPT:

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

    export const options = {
      systemTags: ["vu", "iter"],
    };

    export default function () {
      http.get("https://test.k6.io", {
        tags: {
          "atesttag": "1"
        }
      });
      sleep(0.5);
    }

RESULTS (RAW):

metric_name,timestamp,metric_value,extra_tags,metadata
http_reqs,1671829512,1.000000,atesttag=1,iter=0&vu=1
http_req_duration,1671829512,196.976420,atesttag=1,vu=1&iter=0
http_req_blocked,1671829512,221.245422,atesttag=1,iter=0&vu=1
http_req_connecting,1671829512,105.763210,atesttag=1,iter=0&vu=1
http_req_tls_handshaking,1671829512,109.340836,atesttag=1,iter=0&vu=1
http_req_sending,1671829512,0.101357,atesttag=1,iter=0&vu=1
http_req_waiting,1671829512,196.618219,atesttag=1,iter=0&vu=1
http_req_receiving,1671829512,0.256844,atesttag=1,iter=0&vu=1
http_req_failed,1671829512,0.000000,atesttag=1,iter=0&vu=1
data_sent,1671829513,438.000000,,vu=1&iter=0
data_received,1671829513,16962.000000,,vu=1&iter=0
iteration_duration,1671829513,919.258656,,iter=0&vu=1
iterations,1671829513,1.000000,,vu=1&iter=0

RESULTS (FORMATTED):

metric_name               timestamp   metric_value  extra_tags  metadata
http_reqs                 1671829512  1.000000      atesttag=1  iter=0&vu=1
http_req_duration         1671829512  196.976420    atesttag=1  vu=1&iter=0
http_req_blocked          1671829512  221.245422    atesttag=1  iter=0&vu=1
http_req_connecting       1671829512  105.763210    atesttag=1  iter=0&vu=1
http_req_tls_handshaking  1671829512  109.340836    atesttag=1  iter=0&vu=1
http_req_sending          1671829512  0.101357      atesttag=1  iter=0&vu=1
http_req_waiting          1671829512  196.618219    atesttag=1  iter=0&vu=1
http_req_receiving        1671829512  0.256844      atesttag=1  iter=0&vu=1
http_req_failed           1671829512  0.000000      atesttag=1  iter=0&vu=1
data_sent                 1671829513  438.000000                vu=1&iter=0
data_received             1671829513  16962.000000              vu=1&iter=0
iteration_duration        1671829513  919.258656                iter=0&vu=1
iterations                1671829513  1.000000                  vu=1&iter=0
*** TEST 3 - no options or extra tags ***

SCRIPT:

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

    export default function () {
      http.get("https://test.k6.io");
      sleep(0.5);
    }

RESULTS (RAW):

metric_name,timestamp,metric_value,check,error,error_code,expected_response,group,method,name,proto,scenario,service,status,subproto,tls_version,url,extra_tags,metadata
http_reqs,1671829514,1.000000,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_duration,1671829514,213.399901,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_blocked,1671829514,225.515476,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_connecting,1671829514,108.347288,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_tls_handshaking,1671829514,112.205076,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_sending,1671829514,0.047558,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_waiting,1671829514,212.355127,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_receiving,1671829514,0.997216,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
http_req_failed,1671829514,0.000000,,,,true,,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
data_sent,1671829515,438.000000,,,,,,,,,default,,,,,,,
data_received,1671829515,16984.000000,,,,,,,,,default,,,,,,,
iteration_duration,1671829515,940.315375,,,,,,,,,default,,,,,,,
iterations,1671829515,1.000000,,,,,,,,,default,,,,,,,

RESULTS (FORMATTED):

metric_name               timestamp   metric_value  check  error  error_code  expected_response  group  method  name                proto     scenario  service  status  subproto  tls_version  url                 extra_tags  metadata
http_reqs                 1671829514  1.000000                                true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_duration         1671829514  213.399901                              true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_blocked          1671829514  225.515476                              true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_connecting       1671829514  108.347288                              true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_tls_handshaking  1671829514  112.205076                              true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_sending          1671829514  0.047558                                true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_waiting          1671829514  212.355127                              true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_receiving        1671829514  0.997216                                true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
http_req_failed           1671829514  0.000000                                true                      GET     https://test.k6.io  HTTP/1.1  default            200               tls1.3       https://test.k6.io              
data_sent                 1671829515  438.000000                                                                                              default                                                                           
data_received             1671829515  16984.000000                                                                                            default                                                                           
iteration_duration        1671829515  940.315375                                                                                              default                                                                           
iterations                1671829515  1.000000                                                                                                default                                                                           

from the script:

docker run -it golang:alpine sh -c 'sh <<EOC 
  apk add --no-cache --quiet git make util-linux
  git clone --depth 1 https://github.com/leonyork/k6.git
  cd k6
  make build

  cat <<EOF > test1.js
    import { sleep } from "k6";
    import http from "k6/http";

    export const options = {
      systemTags: ["vu", "iter"],
    };

    export default function () {
      http.get("https://test.k6.io");
      sleep(0.5);
    }
EOF
  ./k6 run test1.js -o csv=results1.csv

  cat <<EOF > test2.js
    import { sleep } from "k6";
    import http from "k6/http";

    export const options = {
      systemTags: ["vu", "iter"],
    };

    export default function () {
      http.get("https://test.k6.io", {
        tags: {
          "atesttag": "1"
        }
      });
      sleep(0.5);
    }
EOF
  ./k6 run test2.js -o csv=results2.csv

  cat <<EOF > test3.js
    import { sleep } from "k6";
    import http from "k6/http";

    export default function () {
      http.get("https://test.k6.io");
      sleep(0.5);
    }
EOF
  ./k6 run test3.js -o csv=results3.csv
  echo
  echo "*** TEST 1 - vu and iter set in system tags ***"
  echo
  echo "SCRIPT:"
  echo
  cat test1.js
  echo 
  echo "RESULTS (RAW):"
  echo
  cat results1.csv
  echo
  echo "RESULTS (FORMATTED):"
  echo
  cat results1.csv | column -t -s ,
  echo
  echo "*** TEST 2 - vu and iter set in system tags along with an extra tag ***"
  echo
  echo "SCRIPT:"
  echo
  cat test2.js
  echo
  echo "RESULTS (RAW):"
  echo 
  cat results2.csv
  echo
  echo "RESULTS (FORMATTED):"
  echo
  cat results2.csv | column -t -s ,
  echo
  echo "*** TEST 3 - no options or extra tags ***"
  echo
  echo "SCRIPT:"
  echo
  cat test3.js
  echo
  echo "RESULTS (RAW):"
  echo 
  cat results3.csv
  echo
  echo "RESULTS (FORMATTED):"
  echo
  cat results3.csv | column -t -s ,
EOC'

@CLAassistant
Copy link

CLAassistant commented Dec 21, 2022

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Dec 21, 2022

Codecov Report

Merging #2829 (e4ab2ce) into master (074b532) will decrease coverage by 0.10%.
The diff coverage is 20.00%.

❗ Current head e4ab2ce differs from pull request most recent head 4e1441c. Consider uploading reports for the commit 4e1441c to get more accurate results

@@            Coverage Diff             @@
##           master    #2829      +/-   ##
==========================================
- Coverage   76.04%   75.94%   -0.11%     
==========================================
  Files         215      213       -2     
  Lines       16564    16564              
==========================================
- Hits        12596    12579      -17     
- Misses       3199     3210      +11     
- Partials      769      775       +6     
Flag Coverage Δ
ubuntu 75.94% <20.00%> (-0.05%) ⬇️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
output/csv/output.go 65.38% <20.00%> (-1.82%) ⬇️
loader/filesystems.go 60.00% <0.00%> (-40.00%) ⬇️
js/common/initenv.go 66.66% <0.00%> (-33.34%) ⬇️
lib/executor/vu_handle.go 92.52% <0.00%> (-2.81%) ⬇️
lib/testutils/minirunner/minirunner.go 79.45% <0.00%> (-2.74%) ⬇️
lib/netext/httpext/error_codes.go 94.52% <0.00%> (-2.74%) ⬇️
js/initcontext.go 86.61% <0.00%> (-1.58%) ⬇️
lib/netext/httpext/error_codes_syscall_windows.go
ui/console/console_windows.go

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@na-- na-- added this to the v0.43.0 milestone Jan 3, 2023
aakashkaji
aakashkaji previously approved these changes Jan 5, 2023
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Hi @leonyork,
thanks for your contribution 🙇 The implemented code looks good to me.

I think we could unblock this PR if we extend the following unit test

func TestRun(t *testing.T) {

providing the vu tag in one of the sample and enabling the VU system tag here:
SystemTags: metrics.NewSystemTagSet(metrics.TagError | metrics.TagCheck),

An integration test is still nice to have but we could address it in another PR.

output/csv/output.go Outdated Show resolved Hide resolved
@leonyork
Copy link
Contributor Author

@codebien, thanks for the pointer to the unit test! I've updated that and removed the new line you suggested 🙂

@leonyork leonyork marked this pull request as ready for review January 12, 2023 21:05
Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

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

Thanks for your work debugging and fixing this @leonyork! 👏 The excellent steps to reproduce it, and that separate repo were of great help 👍

This looks great to me. It's an elegant and simple fix in an inelegant part of the codebase 😅

Like @codebien says, we can add the integration test if needed later, once we merge all related PRs, or decide to just leave it with the unit test, since it does cover the change.

Don't worry about the CI failure, it's a known flaky test 😞

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @leonyork 🙇

@codebien codebien merged commit f0d9b23 into grafana:master Jan 13, 2023
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.

7 participants