From 1f8521aabdaed078efc7b1b7634ecc11877b720f Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Fri, 19 Jul 2024 14:08:57 -0600 Subject: [PATCH 1/2] chore: Update influxdata/tail to master --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 89a30806a43b6..0fda1c847ff3d 100644 --- a/go.mod +++ b/go.mod @@ -117,7 +117,7 @@ require ( github.com/influxdata/influxdb-observability/influx2otel v0.5.12 github.com/influxdata/influxdb-observability/otel2influx v0.5.12 github.com/influxdata/line-protocol/v2 v2.2.1 - github.com/influxdata/tail v1.0.1-0.20221130111531-19b97bffd978 + github.com/influxdata/tail v1.0.1-0.20240719165826-3c9d721090d2 github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65 github.com/influxdata/wlog v0.0.0-20160411224016-7c63b0a71ef8 github.com/intel/iaevents v1.1.0 diff --git a/go.sum b/go.sum index da793dd232fb2..8f704c8b501c6 100644 --- a/go.sum +++ b/go.sum @@ -1617,8 +1617,8 @@ github.com/influxdata/line-protocol/v2 v2.0.0-20210312151457-c52fdecb625a/go.mod github.com/influxdata/line-protocol/v2 v2.1.0/go.mod h1:QKw43hdUBg3GTk2iC3iyCxksNj7PX9aUSeYOYE/ceHY= github.com/influxdata/line-protocol/v2 v2.2.1 h1:EAPkqJ9Km4uAxtMRgUubJyqAr6zgWM0dznKMLRauQRE= github.com/influxdata/line-protocol/v2 v2.2.1/go.mod h1:DmB3Cnh+3oxmG6LOBIxce4oaL4CPj3OmMPgvauXh+tM= -github.com/influxdata/tail v1.0.1-0.20221130111531-19b97bffd978 h1:SaKzm7QUHJcHOFni43zxs+RAKTE6455UoZCloL6dBso= -github.com/influxdata/tail v1.0.1-0.20221130111531-19b97bffd978/go.mod h1:VeiWgI3qaGdJWust2fP27a6J+koITo/1c/UhxeOxgaM= +github.com/influxdata/tail v1.0.1-0.20240719165826-3c9d721090d2 h1:W68O0w2sRiBXoD9kkaBj2dMJJO5FdQJ5cL0zGA3NWMU= +github.com/influxdata/tail v1.0.1-0.20240719165826-3c9d721090d2/go.mod h1:VeiWgI3qaGdJWust2fP27a6J+koITo/1c/UhxeOxgaM= github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65 h1:vvyMtD5LTJc1W9sQKjDkAWdcg0478CszSdzlHtiAXCY= github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65/go.mod h1:zApaNFpP/bTpQItGZNNUMISDMDAnTXu9UqJ4yT3ocz8= github.com/influxdata/wlog v0.0.0-20160411224016-7c63b0a71ef8 h1:W2IgzRCb0L9VzMujq/QuTaZUKcH8096jWwP519mHN6Q= From 4900613affa9f35823348b62592397ada7ffe678 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Fri, 19 Jul 2024 14:19:37 -0600 Subject: [PATCH 2/2] feat(agent): Enable watching for new files This allows for watching for new files in a configuraiton directory. When a new file is found, Telegraf will reload with that file added to the list of files to watch. Note this will reload when any file, a telegraf config or not, is added to the directory. TODO: test on Windows fixes: #12389 fixes: #12264 --- cmd/telegraf/telegraf.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 640787c992da9..216a6bcf76248 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -157,6 +157,13 @@ func (t *Telegraf) reloadLoop() error { go t.watchLocalConfig(ctx, signals, fConfig) } } + for _, fConfigDirectory := range t.configDir { + if _, err := os.Stat(fConfigDirectory); err != nil { + log.Printf("W! Cannot watch config directory %s: %s", fConfigDirectory, err) + } else { + go t.watchLocalConfig(ctx, signals, fConfigDirectory) + } + } } if t.configURLWatchInterval > 0 { remoteConfigs := make([]string, 0) @@ -212,7 +219,7 @@ func (t *Telegraf) watchLocalConfig(ctx context.Context, signals chan os.Signal, } changes, err := watcher.ChangeEvents(&mytomb, 0) if err != nil { - log.Printf("E! Error watching config %q: %s\n", fConfig, err) + log.Printf("E! Error watching config file/directory %q: %s\n", fConfig, err) return } log.Printf("I! Config watcher started for %s\n", fConfig) @@ -221,17 +228,19 @@ func (t *Telegraf) watchLocalConfig(ctx context.Context, signals chan os.Signal, mytomb.Done() return case <-changes.Modified: - log.Printf("I! Config file %q modified\n", fConfig) + log.Printf("I! Config file/directory %q modified\n", fConfig) case <-changes.Deleted: // deleted can mean moved. wait a bit a check existence <-time.After(time.Second) if _, err := os.Stat(fConfig); err == nil { - log.Printf("I! Config file %q overwritten\n", fConfig) + log.Printf("I! Config file/directory %q overwritten\n", fConfig) } else { - log.Printf("W! Config file %q deleted\n", fConfig) + log.Printf("W! Config file/directory %q deleted\n", fConfig) } case <-changes.Truncated: - log.Printf("I! Config file %q truncated\n", fConfig) + log.Printf("I! Config file/directory %q truncated\n", fConfig) + case <-changes.Created: + log.Printf("I! Config directory %q has new file(s)\n", fConfig) case <-mytomb.Dying(): log.Printf("I! Config watcher %q ended\n", fConfig) return