From 669da71271ed828f8f259f317ae863d1f9236f84 Mon Sep 17 00:00:00 2001 From: Cole Laven <82364622+colelaven@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:48:22 -0500 Subject: [PATCH] fix: validate topology processor interval (#2076) * validate interval * fix test --- processor/topologyprocessor/config.go | 4 ++++ processor/topologyprocessor/config_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/processor/topologyprocessor/config.go b/processor/topologyprocessor/config.go index d5763742b..897877cb7 100644 --- a/processor/topologyprocessor/config.go +++ b/processor/topologyprocessor/config.go @@ -52,6 +52,10 @@ func (cfg Config) Validate() error { return nil } + if cfg.Interval < 10*time.Second { + return errors.New("`interval` must be at least 10 seconds") + } + if cfg.Configuration == "" { return errors.New("`configuration` must be specified") } diff --git a/processor/topologyprocessor/config_test.go b/processor/topologyprocessor/config_test.go index a7d43a203..8a9fd9670 100644 --- a/processor/topologyprocessor/config_test.go +++ b/processor/topologyprocessor/config_test.go @@ -16,6 +16,7 @@ package topologyprocessor import ( "testing" + "time" "github.com/stretchr/testify/require" ) @@ -26,6 +27,18 @@ func TestConfigValidate(t *testing.T) { require.NoError(t, err) }) + t.Run("interval too low", func(t *testing.T) { + cfg := Config{ + Enabled: true, + Interval: 8 * time.Second, + AccountID: "myacct", + Configuration: "myConfig", + OrganizationID: "myorg", + } + err := cfg.Validate() + require.Error(t, err) + }) + t.Run("Empty configuration", func(t *testing.T) { cfg := Config{ Enabled: true,