Skip to content

fix(agent): Skip output buffer initialization in test mode - #18918

Merged
skartikey merged 1 commit into
influxdata:masterfrom
WZH8898:fix-test-disk-buffer-init
May 19, 2026
Merged

skartikey merged 1 commit into
influxdata:masterfrom
WZH8898:fix-test-disk-buffer-init

Conversation

@WZH8898

@WZH8898 WZH8898 commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR updates telegraf --test and --test-wait to avoid initializing runtime output buffers during config loading, addressing issue #18917.

In test mode, outputs are not used. However, Telegraf still initialized output buffers while loading the configuration. When buffer_strategy = "disk" was configured, this attempted to create/open the disk-backed WAL under buffer_directory, causing telegraf --test to fail if the current user did not have write access to that directory.

This PR marks config loading as test mode for --test and --test-wait. Output configs still parse normally, including serializers, but runtime output buffer initialization is skipped for parsed-but-unused outputs in test mode.

This PR also adds an internal discard buffer for outputs parsed in test mode.

Tests added in this PR cover:

  • Config parsing in test mode with an unusable disk buffer path
  • CLI config loading in test mode
  • Serializer parsing in test mode
  • Ensuring disk-backed output buffers are not initialized during test-mode config loading

Checklist

  • No AI generated code was used in this PR
  • AI generated code used in this PR follows the InfluxData Policy on AI-Generated Code Contributions

Related issues

resolves #18917

@telegraf-tiger telegraf-tiger Bot added the fix pr to fix corresponding bug label May 15, 2026
@WZH8898
WZH8898 force-pushed the fix-test-disk-buffer-init branch 2 times, most recently from e9464ee to 4bc0ec7 Compare May 15, 2026 08:31

@srebhan srebhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WZH8898 for tackling this issue! I do have some comments in the code... Furthermore, I really like the idea of creating a "discard buffer" for test-runs of Telegraf! Can we please

  1. Add a function to buffer.go to just test the buffer settings and do nothing else?
  2. Simply override the buffer_strategy in config and avoid adding all those flags?

With this implemented, the config could (in test-mode) first check the buffer settings using the function of item 1 and then override the buffer_strategy with "discard"...

Comment thread cmd/telegraf/telegraf_config_test.go Outdated
Comment on lines +27 to +35
[agent]
buffer_strategy = "disk"
buffer_directory = ` + strconv.Quote(bufferDirectory) + `

[[inputs.cpu]]

[[outputs.influxdb]]
urls = ["http://localhost:8086"]
database = "telegraf"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this to a file in the testdata directory instead of writing it somewhere in every test?

Comment thread cmd/telegraf/telegraf_config_test.go Outdated
Comment on lines +47 to +52
agent = &Telegraf{
GlobalFlags: GlobalFlags{
config: []string{configFile},
test: true,
},
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the agent here and just set test?

Comment thread config/config_test.go Outdated
bufferDirectory := filepath.Join(root, "buffer")
require.NoError(t, os.WriteFile(bufferDirectory, []byte("not a directory"), 0600))

cfg := []byte(fmt.Sprintf(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Please create a real file in testdata instead of writing it everytime.

Comment thread models/buffer.go Outdated
Comment on lines +180 to +213

type discardBuffer struct {
BufferStats
}

func newDiscardBuffer(stats BufferStats) *discardBuffer {
return &discardBuffer{BufferStats: stats}
}

func (*discardBuffer) Len() int {
return 0
}

func (b *discardBuffer) Add(metrics ...telegraf.Metric) int {
for _, m := range metrics {
b.metricDropped(m)
}
return len(metrics)
}

func (*discardBuffer) BeginTransaction(int) *Transaction {
return &Transaction{}
}

func (*discardBuffer) EndTransaction(*Transaction) {
}

func (b *discardBuffer) Stats() BufferStats {
return b.BufferStats
}

func (*discardBuffer) Close() error {
return nil
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to its own buffer_discard.go file to follow the pattern of the other implementations!

@srebhan srebhan self-assigned this May 19, 2026
@srebhan srebhan added area/agent plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins labels May 19, 2026
@WZH8898
WZH8898 force-pushed the fix-test-disk-buffer-init branch from 4bc0ec7 to 38af8fe Compare May 19, 2026 11:04
@telegraf-tiger

Copy link
Copy Markdown
Contributor

@srebhan srebhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks @WZH8898!

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label May 19, 2026
@srebhan srebhan assigned skartikey and unassigned srebhan May 19, 2026

@skartikey skartikey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WZH8898 Thanks for the contribution!

@skartikey
skartikey merged commit a084d92 into influxdata:master May 19, 2026
5 checks passed
@github-actions github-actions Bot added this to the v1.38.5 milestone May 19, 2026
@srebhan srebhan modified the milestones: v1.38.5, v1.39.0 Jun 1, 2026
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
telegraf 1.39.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v1.39.0 [2026-06-08]

### New Plugins

- [#18790](influxdata/telegraf#18790) `inputs.gnmi_listener` Add plugin

### Features

- [#18909](influxdata/telegraf#18909) `agent` Accept TELEGRAF_CONTROLLER_TOKEN environment variable
- [#18744](influxdata/telegraf#18744) `inputs.azure_monitor` Support secrets for client_secret
- [#18921](influxdata/telegraf#18921) `inputs.directory_monitor` Allow to preserve timestamps when moving file
- [#18338](influxdata/telegraf#18338) `inputs.exec` Convert 'commands' to already parsed argument lists
- [#18740](influxdata/telegraf#18740) `inputs.fritzbox` Add support for fiber lines
- [#18987](influxdata/telegraf#18987) `inputs.http_response` Add secret token support
- [#18739](influxdata/telegraf#18739) `inputs.huebridge` Add brightness and color fields to light metric
- [#18571](influxdata/telegraf#18571) `inputs.internal` Add counters for failing writes and gathers
- [#19038](influxdata/telegraf#19038) `inputs.kafka_consumer` Add consumer_fetch_min and consumer_fetch_max_wait options
- [#18532](influxdata/telegraf#18532) `inputs.mem` Add extended memory statistics
- [#18871](influxdata/telegraf#18871) `inputs.modbus` Add workaround for devices with smaller batch size
- [#18690](influxdata/telegraf#18690) `inputs.nvidia_smi` Add schema v13 support
- [#18643](influxdata/telegraf#18643) `inputs.opcua` Add locales configuration option
- [#18831](influxdata/telegraf#18831) `inputs.opcua` Discover nodes by browse-path glob patterns
- [#18465](influxdata/telegraf#18465) `inputs.opcua_listener` Allow selecting the deadband mode 'None'
- [#18941](influxdata/telegraf#18941) `inputs.opcua_listener` Wire browse-based node discovery
- [#18468](influxdata/telegraf#18468) `inputs.openntpd` Add sensor and status metrics
- [#18944](influxdata/telegraf#18944) `inputs.prometheus` Add per-URL statistics on gather cycles
- [#18915](influxdata/telegraf#18915) `inputs.socket_listener` Add SSM/IGMPv3 support
- [#18868](influxdata/telegraf#18868) `inputs.system` Add hardware information
- [#18834](influxdata/telegraf#18834) `inputs.system` Add operating-system information
- [#18533](influxdata/telegraf#18533) `inputs.system` Add option to specify collected information
- [#18906](influxdata/telegraf#18906) `inputs.temp` Add setting to force thermal-zones gathering on linux
- [#18457](influxdata/telegraf#18457) `inputs.wireguard` Add endpoint field to peer metrics
- [#18819](influxdata/telegraf#18819) `inputs.x509_cert` Add field for public-key length
- [#18829](influxdata/telegraf#18829) `outputs.kafka` Add support for custom record headers
- [#18826](influxdata/telegraf#18826) `outputs.mongodb` Allow specifying metadata fields
- [#18784](influxdata/telegraf#18784) `outputs.opensearch` Implement startup-error-behavior options
- [#18823](influxdata/telegraf#18823) `outputs.opentelemetry` Add proxy support
- [#18980](influxdata/telegraf#18980) `outputs.opentelemetry` Add support for token authentication
- [#19036](influxdata/telegraf#19036) `outputs.sql` Add oracle driver
- [#18904](influxdata/telegraf#18904) `parsers.avro` Implement ParserTimeFuncPlugin interface
- [#18945](influxdata/telegraf#18945) `parsers.binary` Implement ParserTimeFuncPlugin interface
- [#18903](influxdata/telegraf#18903) `parsers.csv` Implement ParserTimeFuncPlugin interface
- [#18946](influxdata/telegraf#18946) `parsers.dropwizard` Implement ParserTimeFuncPlugin interface
- [#18947](influxdata/telegraf#18947) `parsers.form_urlencoded` Implement ParserTimeFuncPlugin interface
- [#18948](influxdata/telegraf#18948) `parsers.graphite` Implement ParserTimeFuncPlugin interface
- [#18950](influxdata/telegraf#18950) `parsers.grok` Implement ParserTimeFuncPlugin interface
- [#18990](influxdata/telegraf#18990) `parsers.json` Implement ParserTimeFuncPlugin interface
- [#18994](influxdata/telegraf#18994) `parsers.json_v2` Implement ParserTimeFuncPlugin interface
- [#18995](influxdata/telegraf#18995) `parsers.logfmt` Implement ParserTimeFuncPlugin interface
- [#18996](influxdata/telegraf#18996) `parsers.nagios` Implement ParserTimeFuncPlugin interface
- [#18998](influxdata/telegraf#18998) `parsers.openmetrics` Implement ParserTimeFuncPlugin interface
- [#19000](influxdata/telegraf#19000) `parsers.parquet` Implement ParserTimeFuncPlugin interface
- [#19042](influxdata/telegraf#19042) `parsers.prometheus` Implement ParserTimeFuncPlugin interface
- [#19043](influxdata/telegraf#19043) `parsers.prometheusremotewrite` Implement ParserTimeFuncPlugin interface
- [#19008](influxdata/telegraf#19008) `parsers.value` Implement ParserTimeFuncPlugin interface
- [#19009](influxdata/telegraf#19009) `parsers.wavefront` Implement ParserTimeFuncPlugin interface
- [#19011](influxdata/telegraf#19011) `parsers.xpath` Implement ParserTimeFuncPlugin interface
- [#18901](influxdata/telegraf#18901) `parsers` Add time-setting interface
- [#18558](influxdata/telegraf#18558) `processors.parser` Add strategy to merge parsed metric with parent individually
- [#18786](influxdata/telegraf#18786) `secretstores.vault` Add token authentication

### Bugfixes

- [#18918](influxdata/telegraf#18918) `agent` Skip output buffer initialization in test mode
- [#19033](influxdata/telegraf#19033) `circleci` Fix destination of nightly build artifact uploads
- [#18910](influxdata/telegraf#18910) `common.tls` Set default minimum TLS version explicitly
- [#17664](influxdata/telegraf#17664) `config` Reject invalid tagpass and tagdrop types
- [#18913](influxdata/telegraf#18913) `input.temp` Ignore EAGAIN on unavailable thermal-zones
- [#18988](influxdata/telegraf#18988) `inputs.docker_log` Don't use follow when tailing docker logs
- [#19001](influxdata/telegraf#19001) `inputs.docker_log` Guard concurrent access to the state map
- [#19004](influxdata/telegraf#19004) `inputs.docker_log` Read only new entries if from_beginning is false
- [#19006](influxdata/telegraf#19006) `inputs.docker_log` Restore following the log-stream and keep the state
- [#18902](influxdata/telegraf#18902) `inputs.netflow` Parse all counter records
- [#18683](influxdata/telegraf#18683) `inputs.opcua_listener` Defer node ID parsing until after server connection
- [#18870](influxdata/telegraf#18870) `inputs.ping` Use deterministic packet IDs to prevent collisions
- [#18911](influxdata/telegraf#18911) `inputs.system` Demote missing utmp debug log to trace
- [#18982](influxdata/telegraf#18982) `inputs.system` Restore n_cpu field name
- [#18923](influxdata/telegraf#18923) `inputs.webhooks.github` Restore secret field in configuration
- [#18984](influxdata/telegraf#18984) `outputs.influxdb_v2` Capture unix socket path before URL mutation
- [#18908](influxdata/telegraf#18908) `secrets` Avoid panic with empty content

### Dependency Updates

- [#18897](influxdata/telegraf#18897) `deps` Bump cloud.google.com/go/monitoring from 1.28.0 to 1.29.0
- [#18928](influxdata/telegraf#18928) `deps` Bump cloud.google.com/go/storage from 1.62.1 to 1.62.2
- [#19030](influxdata/telegraf#19030) `deps` Bump github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor from 0.11.0 to 0.12.0
- [#18889](influxdata/telegraf#18889) `deps` Bump github.com/IBM/sarama from 1.48.0 to 1.48.1
- [#18929](influxdata/telegraf#18929) `deps` Bump github.com/IBM/sarama from 1.48.1 to 1.49.0
- [#19031](influxdata/telegraf#19031) `deps` Bump github.com/IBM/sarama from 1.49.0 to 1.50.1
- [#18881](influxdata/telegraf#18881) `deps` Bump github.com/SAP/go-hdb from 1.16.7 to 1.16.8
- [#19028](influxdata/telegraf#19028) `deps` Bump github.com/SAP/go-hdb from 1.16.8 to 1.16.11
- [#18970](influxdata/telegraf#18970) `deps` Bump github.com/apache/inlong/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang from 1.0.7 to 1.0.8
- [#18880](influxdata/telegraf#18880) `deps` Bump github.com/aws/aws-sdk-go-v2/service/ec2 from 1.300.0 to 1.301.0
- [#19016](https://github.com/influx

See merge request: Harmonybrew/homebrew-core!11058
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent fix pr to fix corresponding bug plugin/output 1. Request for new output plugins 2. Issues/PRs that are related to out plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

telegraf --test fails to load config when buffer_strategy = "disk" and the running user lacks write access to buffer_directory

3 participants