influxdata / influxdata/kapacitor

Need help with unique scenario

Open
#2,543 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

```
I'm trying to calculate the percentage of error based on output from 2 queries.

Error query:
var error_count_sli = batch
|query('''SELECT sum("count") as count_error FROM "".""."" WHERE "Flag" = \'1\' AND "endResult" = \'Error\'''')
.period(28d)
.every(1h)
.groupBy(28d)
.fill(0)
.align()
|default()
.field('count', 0)
|last('count_error')
.as('error_count')
|log()

Total query:

var total_count_sli = batch
|query('SELECT sum("count") as count_error FROM "".""."" WHERE "Flag" = \'1\'')
.period(28d)
.every(1h)
.groupBy(28d)
.fill(0)
.align()
|default()
.field('count', 0)
|last('count_error')
.as('error_count')
|log()

Percentage calculation:
error_count_sli
|join(total_count)
.as('error_count_sli', 'total_count')
|eval(lambda: 100.0 - ((float("error_count") / float("total_count")) * 100.0))
.as('percent_total')
.keep()
|log()

There is possibility that the queries return "no records". So i've used the default() method.
Even with this default condition, i cant calculate the percentage. My eval expression variables for percentage calculation need to change with respect to the condition of records exist or not.

Cant figure out how to solve the issue.
```

Contributor guide

Open the contributing guide

Research direction

The issue provides no file, test, or entry point. Start by reproducing the two batch query pipelines and inspect default(), join(), and eval() when either query returns no records; done means establishing a verified way to calculate the percentage in that case.

Written by the indexing model from the issue text.

Assessment

Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.