Double nested query yields unexpected results

Hello,

In influxdb, version 1.3.7 I’m collecting metrics of Kafka cluster. For each topic I have tag ‘partition’ - metrics for each parition are sent independently. One of them is offset - that is, total amount of messages that came to that topic. I’d like to make singlestat in grafana that shows how many messages were produced in last 15minutes.

The following query returns results for each partition separately:
select difference(last), partition from (SELECT last(“Value”) FROM “kafka_topic_offset” WHERE “topic” = ‘topic_name’ AND time >= now() - 30m GROUP BY “partition”, time(30m) fill(previous))

more or less like this:
results: [
{
statement_id: 0,
series: [
{
name: “kafka_topic_offset”,
tags: {partition: “0”},
columns: [ “time”, “difference”],
values: [ [1542981600000,640]]
},
{
name: “kafka_topic_offset”,
tags: {partition: “0”},
columns: [ “time”, “difference”],
values: [ [1542981600000,640]]
}

Now, I want to sum all these values:
select sum(“difference”) from ( select difference(last) from (SELECT last(“Value”) FROM “kafka_topic_offset” WHERE (“env” = ‘prod’ AND (“topic” = ‘cep.rtbs_c1.mtr’ )) AND time >= now() - 30m GROUP BY “partition”, time(30m) fill(previous)) group by partition)

  • but this return 0 as only value.
    Any idea what am I doing wrong?

thanks,
maciek