Getting tag values Flux way

grafana

#1

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

into

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

But the response I get is this:
#datatype,string,string
#group,true,true
#default,
,error,reference
,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.


#2

@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.


#3

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


#4

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.


#5

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


#6

Hey @Vadim_Gusev, sorry for the delay. Here is the issue https://github.com/influxdata/flux/issues/356 .


#7

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


#8

@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

#9

Which version of Flux and InfluxDB are you using?


#10

@jlapacik Both are 1.7.1


#11

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


#12

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.


#13

@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:
action
download_type
source
type
unique
utm_campaign
utm_content
utm_medium
utm_source
utm_term

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


#14

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


#15

@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.


#16

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


#17

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