Tzadik Even
Tzadik Even

Reputation: 121

InfluxDB2 flux tasks scheduling

I have these two Flux tasks:

# 24-hour policy hits aggregation
influx task create -o myorg -t "$API_TOKEN" -n "task_policy_hits_24h" --every 10m -f <(echo '
option task = {name: "task_policy_hits_24h", every: 10m}
from(bucket: "four_hours")
  |> range(start: -10m)
  |> filter(fn: (r) => r._measurement == "policy_hits_continuous")
  |> filter(fn: (r) => r._field == "count")
  |> aggregateWindow(
      every: 1h,
      fn: sum,
      createEmpty: false,
      offset: duration(v: 0h)
    )
  |> group(columns: ["policy_id"])
  |> map(fn: (r) => ({
      _time: r._time,
      _measurement: "policy_hits_24h",
      _field: "count",
      _value: r._value,
      policy_id: r.policy_id
    }))
  |> to(bucket: "one_week")')

# Weekly policy hits aggregation
influx task create -o myorg -t "$API_TOKEN" -n "task_policy_hits_1w" --every 10m -f <(echo '
option task = {name: "task_policy_hits_1w", every: 10m}
from(bucket: "one_week")
  |> range(start: -10m)
  |> filter(fn: (r) => r._measurement == "policy_hits_24h")
  |> filter(fn: (r) => r._field == "count")
  |> aggregateWindow(
      every: 1d,
      fn: sum,
      createEmpty: false,
      offset: duration(v: 0h)
    )
  |> group(columns: ["policy_id"])
  |> map(fn: (r) => ({
      _time: r._time,
      _measurement: "policy_hits_1w",
      _field: "count",
      _value: r._value,
      policy_id: r.policy_id
    }))
  |> to(bucket: "one_month")')

First task move policy_hits from four_hours bucket to one_week bucket and second task moves policy_hits from one_week bucket to one_month bucket. The issue is that once one_week bucket gets the policy_hits data, I cannot see the policy_hits also in one_month bucket. I assume some scheduling needs to be done here so the second task will start running let's say 1 minute after the first task. What is the way to do that, so at the end of day, I could see same policy_hits in both buckets (one minute difference is fine). Thank you in advance!

Upvotes: 0

Views: 16

Answers (0)

Related Questions