0

这是生成流产率的查询。

  filter_metric = (metric_name) => {
    count = from(bucket: "application")
        |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
        |> filter(fn: (r) => r["_measurement"] == metric_name and r["_field"] == "value")
        |> filter(fn: (r) => contains(value: r["type"], set: ${types:json}))
        |> filter(fn: (r) => contains(value: r["org"], set: ${org:json}))
        |> keep(columns: ["_value", "_time"])
        |> aggregateWindow(every: ${groupEventsBy}, fn: count, createEmpty: true)
    return count
}
abortion_rate = () => {
    disc_count = filter_metric(metric_name: "discontinued")
    success_count = filter_metric(metric_name: "succeeded")

    return join(tables: {d: disc_count, s: success_count}, on: ["_time"])
        |> map(
            fn: (r) => ({
                _time: r._time,
                _value: if  r._value_d + r._value_s > 0 then float(v: r._value_d) / float(v: r._value_d + r._value_s) else float(v:0),
            }),
        )
}

abortion_rate()

当“成功”和“停止”有数据时,每件事都很好。当我应用一些过滤器时,很可能其中一个表是空的,导致没有指标生成。count当过滤数据流为空白时,有没有办法为聚合函数生成记录。

4

0 回答 0