continuous-integrationgrafanainfluxdbcicdk6

How to add release number from pipeline into K6-InfluxDB-Grafana stack so that in grafana we can filter results based on Release Number as well


I have K6- InfluxDB - Grafana stack which was integrated into the Azure release pipeline. In Grafana, I can filter results based on timelines since Influxdb is a time-series database. But I would like to have the flexibility to filter results based on the release pipeline number as well. Is it possible to do it? Can we pass the release number as an environment variable? But what do I do with a release number, how do I integrate it in my k6 script or Influxdb so that Grafana can read it.

Any suggestions?


Solution

  • I'm doing something similar in my load tests. You can set a test wide tag in your options object, or if using scenarios, a tag per scenario. The tag value can be injected via environment variable.

    When using the InfluxDB output, tags are automatically added to every data point. Be careful though with the number of time series this will create.

    export const options = {
      tags = {
        pipeline_id = __ENV.AZURE_PIPELINE_ID || 'unknown',
      },
    };
    

    With scenarios:

    export const options = {
      scenarios: {
        executor: '…',
        tags: {
          pipeline_id = __ENV.AZURE_PIPELINE_ID || 'unknown',
        },
        …,
      },
    };
    

    Note that one of the two alternatives is sufficient, depending on your use case.

    You can then easily define filters on the tag "pipeline_id" in your Grafana dashboards with InfluxDB data sources:

    SELECT max("value") FROM "vus" WHERE ("pipeline_id" = '$pipeline_id') AND $timeFilter GROUP BY time($__interval) fill(none)
    

    (or by using the query builder)