Test wide defined tags doesn't appear in InfluxDB

Hi,

I’m using K6 scripts for loadtesting quite a while now. I use an InfluxDB backend to store the test data. I used test wide tags in the test script file to categorize my tests and that worked fine. But now, without any change from me, the tags doesn’t appear anymore in the InfluxDB. What can I do about it?

from test script

export const options = {

    "duration": "1m",
    "vus": v,
    insecureSkipTLSVerify: true,
    discardResponseBodies: true,
    tags: {
      HWconfig: '1M1W-4C16GB',
       Test: 'HW-1_AAS_max-AAS_TM-Element', 
       Read: 'false',
       Random: 'true', 
       VUs: ''+v,
       Sleep: ''+s,
       Parallelism: ''+p,
       Separate: 'false',
     },
  };

tags before in InfluxDB:

tags now in InfluxDB:

Hi @MariusB

Welcome on the forum :tada:

Could you please indicate which version of the k6 binary version you use, which version of InfluxDB you use, how you feed the k6 data into InfluxDB, and any other configuration that you would judge relevant (anonymized, of course!)?

It seems very unlikely that your pipeline would break without changing parts. Thus I’m looking for clues as to where things could have changed without being noticed, to try and isolate the issue itself :bowing_man:

Hi @oleiade ,

Thank you for the quick response! :slight_smile:

I use k6 v0.37.0 and InfluxDB v2.1.1-alpine.
I feed the data with the xk6-influxdb extension into the database. Because of that I use an custom image, which I build with k6 and xk6.

The whole setup runs in an kubernetes-cluster. The k6 clients and the InfluxDB are running in the same cluster, my test-target in another one.

My config-yaml looks like this:

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6-sample
spec:
  parallelism: 1
  script:
    configMap:
      name: example-test
      file: example-test.js
  separate: false
  arguments: --out xk6-influxdb=http://xxxxx
  #--no-summary --no-thresholds
  runner:
     image: xxmariusb21xx/k6-influxdb:ext
     env:
      - name: K6_INFLUXDB_ORGANIZATION
        value: "xxxx"
      - name: K6_INFLUXDB_BUCKET
        value: "xxxxx"
      - name: K6_INFLUXDB_TOKEN
        value: 'xxxxx'

My test-script like this:

import http from 'k6/http';
import { sleep } from 'k6';
import {
  randomIntBetween,
  randomString,
  randomItem,
  uuidv4,
  findBetween,
} from 'https://jslib.k6.io/k6-utils/1.3.0/index.js';

var x=0; //Variable to set range for random function
var s=0.1; //sleep Time in s
var p=1; //Parallelism in int
var v=10; //VU's in int
var value=0; //Random value for writing in the sm-element

  export const options = {

    "duration": "1m",
    "vus": v,
    insecureSkipTLSVerify: true,
    discardResponseBodies: true,
    tags: {
      HWconfig: 'xxxxx',
       Test: 'xxxxxx', 
       Read: 'false',
       Random: 'true', 
       VUs: ''+v,
       Sleep: ''+s,
       Parallelism: ''+p,
       Separate: 'false',
     },
  };


export default function () {
  
  x = randomIntBetween(1, 4000);
  value = randomIntBetween(-2147483648, 2147483647);
  const headers = { 'Content-Type': 'application/json' };
  var url = ('xxxxxxxxx');
  var data =  value;
  const res = http.put(url, JSON.stringify(data), { headers: headers }); 
  sleep(s);
}

And as you can see I define the tags in the test-script. I use the tags to filter my test results in Grafana (which also runs in Kubernetes with K6 and the InfluxDB). For example I have got an diagram for writing tests and another one for reading-tests.

As I said that worked fine until now. The tests itself working fine, no errors or missing data, the only thing which is missing are the tags for the datapoints.

1 Like

:wave: Just my 5 cents on topic :slight_smile:

AFAIS, this is an expected behaviour around test-wide tags described in the issue here. When using k6-operator (as it appears happens in this case), you need to pass the tags in CLI - in arguments parameter.

I’m not clear about this part though:

As I said that worked fine until now.

Did it work for you with the k6-operator or with k6?

1 Like

Hi @olha ,

My pipeline worked with the test-wide tags and with the k6-operator.
I defined the tags in my test-script, ran the test with the k6-operator in my kubernetes-cluster and got the tags in my InfluxDB afterwards. I didn’t put any tags with the CLI arguments in the tests. It worked this way for over 5 months now.

I dont understand why it shouldn’t work this way?
I dont overwrite my tags from the script with tags from the CLI. I neither use empty tags like described in the link. :thinking:

:thinking: That sounds very strange; were you perhaps using an old version of the operator before? Test-wide tags cannot be passed in JS options when using operator for about half a year now: because they are being overwritten by the operator itself. Operator attaches tags at CLI level so it has the highest order of preference in k6.

The k6 issue I linked above is suggesting to change k6 UX to allow people to pass tags in JS options while using operator. It also contains a workaround with env vars that should work with the operator as well:

Could you perhaps re-check versions you’re using and try out the workaround?

1 Like

Hi @olha ,

Yes that’s very strange indeed. :sweat_smile:
The workaround described in link didn’t work for me.
But I just put my tags now in the argument variable in the k6.yaml.

 arguments: "--out xk6-influxdb=http://10.28.88.46:8086
   --tag HWconfig=1M1W-4C16GB 
   --tag Test=HW-1_AAS_max-AAS_TM-Element 
   --tag Read=false 
   --tag Random=true 
   --tag VUs=10 
   --tag Sleep=0.1 
   --tag Parallelism=1 
   --tag Separate=false"

That works for me and my setup.
Thank you for the help!

3 Likes

Thanks, @MariusB, your setup sounds almost identical to mine.
The __ENV workaround within the script did not work for me either, but passing tags with --tag flag did!