Instrumenting an API & having cardinality issues

influxdb

#1

Hi all,

we are instrumenting an API which returns a status for a given email address for a given API key.

Currently, we’re pushing one metric for ‘email_verification’ with the following:
values (1): duration
tags: status (one of 4), host (one of 4), accounts (one of many), domains (one of many)

As soon as we went from staging to production (with tens of thousands of queries per minute), we buried our poor InfluxDB Hobby plan. While upgrading to a more professional plan is doable, I wouldn’t want to do that unless I know I am doing things right.

Because of the many possible API keys and the many domains, we’re seeing a cardinality / product / indexing issue and the server can’t deal with it. Note that this is sent via UDP to a telegraf node that forwards the requests via HTTP to the InfluxDB host every 60 seconds.

I understand we could move domain and accounts (API keys) to values (which if I understand correctly are not indexed).

I am guessing this would mean we couldn’t run the following queries, right ?

SELECT domain,top(query_count,15) FROM (SELECT count("duration") AS query_count FROM "email_verification" WHERE ($timeFilter AND "env" =~ /^$env$/ AND "host" =~ /^$host$/ AND "account" =~ /^$api_key$/) GROUP BY "domain")

or

SELECT count("duration") FROM "autogen"."email_verification" WHERE ($timeFilter AND "env" =~ /^$env$/ AND "host" =~ /^$host$/ AND "account" =~ /^$api_key$/)) GROUP BY time($time_interval), "status" fill(0)

(The queries are copied from Grafana, api_keys & domains have a lot of values)

So essentially putting accounts & domains as values, would prevent me from using them in GROUP BY and WHERE clauses, right?

Any suggestion on how to best do this?

Thanks in advance!