Skip to content

Aggregator plugin executes twice per period on Docker Desktop for Windows #18066

@sahil-stellar

Description

@sahil-stellar

Relevant telegraf.conf

[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
 
  debug = true
  logfile = "/tmp/telegraf/telegraf.log"
  logformat = "structured"
 
#========================#
#       INPUTS           #
#========================#
[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = true
 
#========================#
#     AGGREGATION        #
#========================#
[[aggregators.starlark]]
    period = "1m"
    drop_original = true
    script = "/etc/telegraf/twa.star"
 
#========================#
#       OUTPUTS          #
#========================#
[[outputs.file]]
  files = ["/tmp/telegraf/metrics.out"]

Logs from Telegraf

{"time":"2025-11-28T08:12:59.998229537Z","level":"DEBUG","msg":"Updated aggregation range [2025-11-28 08:12:00 +0000 UTC, 2025-11-28 08:13:00 +0000 UTC]"}
{"time":"2025-11-28T08:13:00.031147576Z","level":"DEBUG","msg":"MMM Metric(\"test_metric\", tags={}, fields={\"e\": 43}, time=1764317580031095589)"}
{"time":"2025-11-28T08:13:00.054546694Z","level":"DEBUG","msg":"Updated aggregation range [2025-11-28 08:13:00 +0000 UTC, 2025-11-28 08:14:00 +0000 UTC]"}
{"time":"2025-11-28T08:13:00.060504064Z","level":"DEBUG","msg":"MMM Metric(\"test_metric\", tags={}, fields={\"e\": 43}, time=1764317580060450475)"}
{"time":"2025-11-28T08:13:02.263268189Z","level":"DEBUG","msg":"Wrote batch of 2 metrics in 26.069838ms"}

System info

  • Telegraf version: 1.36.4 - Platform: Docker Desktop on Windows - Docker image: telegraf:latest

Docker

services:
telegraf:
image: telegraf:latest
container_name: telegraf-aggregator
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
- ./output_logs:/tmp/telegraf
- ./twa.star:/etc/telegraf/twa.star:ro


### Steps to reproduce

**twa.star**
```python
state = {}

def add(metric):
    pass

def push():
    metrics = []
    m = Metric("test_metric")
    m.fields["e"] = 43
    print("MMM", m)
    return m

def reset():
    pass
  1. Create output directory: mkdir output_logs

  2. Run: docker-compose up

  3. Wait for 2-3 minutes and observe the logs

  4. Check the metrics output: cat output_logs/metrics.out

  5. Check the debug logs: cat output_logs/telegraf.log | grep "MMM"

Notice the timestamps are duplicated (first two have same timestamp, next two have same timestamp, etc.).

Timeline breakdown:

  • 08:12:59.998 - Aggregation range updated (still in previous period)
  • 08:13:00.031 - First push() execution → outputs first metric
  • 08:13:00.054 - Aggregation range updated (new period starts)
  • 08:13:00.060 - Second push() execution → outputs second metric
  • 08:13:02.263 - Batch of 2 metrics written (should be only 1!)

This pattern repeats at every minute boundary:

This pattern repeats at every minute boundary:

# Next period boundary
{"time":"2025-11-28T08:13:59.996166923Z","level":"DEBUG","msg":"Updated aggregation range [2025-11-28 08:13:00 +0000 UTC, 2025-11-28 08:14:00 +0000 UTC]"}
{"time":"2025-11-28T08:14:00.001036656Z","level":"DEBUG","msg":"MMM Metric(\"test_metric\", tags={}, fields={\"e\": 43}, time=1764317640001008349)"}
{"time":"2025-11-28T08:14:00.004767884Z","level":"DEBUG","msg":"Updated aggregation range [2025-11-28 08:14:00 +0000 UTC, 2025-11-28 08:15:00 +0000 UTC]"}
{"time":"2025-11-28T08:14:00.01071261Z","level":"DEBUG","msg":"MMM Metric(\"test_metric\", tags={}, fields={\"e\": 43}, time=1764317640010659408)"}
{"time":"2025-11-28T08:14:02.259031154Z","level":"DEBUG","msg":"Wrote batch of 2 metrics in 22.412102ms"}

Additional context

This issue appears to be specific to Docker Desktop on Windows. The double execution causes:

  • Duplicate metrics being generated
  • Incorrect aggregation results
  • Resource waste from redundant processing

The timing suggests a potential race condition or improper synchronization around period boundary transitions in the aggregator plugin when running in this specific environment.

Expected behavior

Expected behavior

The aggregator's push() function should execute once per configured period (1 minute). Each period boundary should produce exactly one metric output.

Expected output in metrics.out

Should see one metric per period:

test_metric e=43i 1764317580000000000
test_metric e=43i 1764317640000000000
test_metric e=43i 1764317700000000000

Actual behavior

Actual behavior

The aggregator executes twice per period, producing duplicate metrics:

In metrics.out, you'll see duplicate entries:

test_metric e=43i 1764317580000000000
test_metric e=43i 1764317580000000000
test_metric e=43i 1764317640000000000
test_metric e=43i 1764317640000000000
test_metric e=43i 1764317643000000000

Two metrics per period (duplicates):

test_metric e=43i 1764317580000000000
test_metric e=43i 1764317580000000000
test_metric e=43i 1764317640000000000
test_metric e=43i 1764317640000000000
test_metric e=43i 1764317643000000000

Additional info

No response

Metadata

Metadata

Assignees

Labels

bugunexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions