Getting tag values Flux way



I’m trying to convert one of my Grafana dashboards to use Flux as it provides features I need.
First thing I need to do is to get variables Flux way, so I’ve converted

SHOW TAG VALUES FROM promo WITH KEY = utm_source


from(bucket: “analytics”)
|> range(start: -7d)
|> filter(fn: ® => r._measurement == “promo”)
|> keyValues(keyColumns: [“utm_source”])

But the response I get is this:
,no columns matched by keyColumns parameter,

I don’t see obvious place I’ve messed up with spelling or something like that, so I think I might’ve misunderstood the docs in some way.


@Vadim_Gusev can you show some of the output from the from function (or the filter function)? If utm_source is a tag, from should convert it to a column.


from(bucket: “analytics”)
|> range(start: -7h)
|> filter(fn: ® =>
r._measurement == “promo” AND
r.utm_source =~ /\w+/)
|> group(none: true)
|> limit(n: 5)

Gives me:

_time _value _field _measurement action unique utm_source
2018-11-28T17:59:50.316Z 1 value promo download false adwords
2018-11-28T16:22:32.148Z 1 value promo download false adwords
2018-11-28T15:35:15.146Z 1 value promo download false adwords
2018-11-28T15:35:24.818Z 1 value promo download false adwords
2018-11-28T12:30:56.856Z 1 value promo download false adwords

I’ve removed _start, _stop and bunch of other tags for clarity


Thanks @Vadim_Gusev. This looks like a bug and my hunch is that it has something to do with an empty table getting passed into the keyValues function. I’ll investigate some more.


Is there any public Issue for that topic so I could set a watch on it?


Hey @Vadim_Gusev, sorry for the delay. Here is the issue .


@Vadim_Gusev have you tried running this query through the Flux REPL? Do you still get the same error?


@jlapacik if you mean CLI than yes:

from(bucket: "analytics")
|> range(start: -7h)
|> filter(fn: (r) =>
r._measurement == "promo")
|> keyValues(keyColumns: ["utm_source"])

Error: no columns matched by keyColumns parameter


Which version of Flux and InfluxDB are you using?


@jlapacik Both are 1.7.1


@Vadim_Gusev I can’t seem to reproduce that error. Does it only happen for that specific bucket and time range?


I’ve tried this out on different InfluxDB installation and it happens to work:

> from(bucket: "telegraf")
|> range(start: -1d)
|> filter(fn: (r) =>
r._measurement == "elasticsearch_jvm" AND
r._field == "mem_pools_old_used_in_bytes"
|> keyValues(keyColumns: ["host"])

Result: _result
Table: keys: [_start, _stop, _field, _measurement, cluster_name, host, node_host, node_id, node_name]

and result table follows with expected values (3 different hosts).

Also side note: if i don’t limit r._field and blindly follow classic expression SHOW TAG VALUES FROM elasticsearch_jvm WITH KEY = host I get pretty big table that seems to contain all permutation of table keys from response’s “header” AND those 3 hosts. Not sure how usable it will be in Grafana or if it’s handled at all.

Will try to investigate with different queries borders of what I can and cannot get key values for.


@jlapacik I’ve done some testing:

  1. different InfluxDB installation works
  2. same InfluxDB, different database works
  3. same database, different measurement works
  4. same measurement works… except tag contains underscore

Here is the list of tags in measurement:

Every tag with underscore produces error, while all other work fine.


@Vadim_Gusev thank you. I got the same error with tag names having an underscore. I will start investigating and work on a fix.


@Vadim_Gusev after further investigation I found that it’s not an issue with the underscore in the tag names, instead it is an issue with some of the Flux tables not having a “utm_source” column. keyValues expects that each table that it consumes will have all of the columns listed in its keyColumns parameter.


so what’s the drill? do group(none: true) before keyValues?


@Vadim_Gusev yes group(none: true) seems like the best option. I will update the specification of keyValues to reflect this.