From 8de032bc839eb5be238e5a47d8e00c33b39a222f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 6 Jul 2021 13:23:47 -0400 Subject: [PATCH] Osquerybeat: Fix the configuration poll interval setting (#26739) (#26740) * Fix the configuration poll interval setting * Unit tests (cherry picked from commit 1e4971f88238697cfb34b71663924756a6bbd2e3) Co-authored-by: Aleksandr Maus --- x-pack/osquerybeat/internal/osqd/osqueryd.go | 2 +- .../internal/osqd/osqueryd_test.go | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 x-pack/osquerybeat/internal/osqd/osqueryd_test.go diff --git a/x-pack/osquerybeat/internal/osqd/osqueryd.go b/x-pack/osquerybeat/internal/osqd/osqueryd.go index f2e5f184bda..15006d84203 100644 --- a/x-pack/osquerybeat/internal/osqd/osqueryd.go +++ b/x-pack/osquerybeat/internal/osqd/osqueryd.go @@ -65,7 +65,7 @@ func WithBinaryPath(binPath string) Option { func WithConfigRefresh(refreshInterval int) Option { return func(q *OSQueryD) { - q.extensionsTimeout = refreshInterval + q.configRefreshInterval = refreshInterval } } diff --git a/x-pack/osquerybeat/internal/osqd/osqueryd_test.go b/x-pack/osquerybeat/internal/osqd/osqueryd_test.go new file mode 100644 index 00000000000..513e921cd2e --- /dev/null +++ b/x-pack/osquerybeat/internal/osqd/osqueryd_test.go @@ -0,0 +1,48 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package osqd + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestNew(t *testing.T) { + + socketPath := "/var/run/foobar" + + extensionsTimeout := 5 + configurationRefreshIntervalSecs := 12 + configPluginName := "config_plugin_test" + loggerPluginName := "logger_plugin_test" + + osq := New( + socketPath, + WithExtensionsTimeout(extensionsTimeout), + WithConfigRefresh(configurationRefreshIntervalSecs), + WithConfigPlugin(configPluginName), + WithLoggerPlugin(loggerPluginName), + ) + + diff := cmp.Diff(extensionsTimeout, osq.extensionsTimeout) + if diff != "" { + t.Error(diff) + } + + diff = cmp.Diff(configurationRefreshIntervalSecs, osq.configRefreshInterval) + if diff != "" { + t.Error(diff) + } + diff = cmp.Diff(configPluginName, osq.configPlugin) + if diff != "" { + t.Error(diff) + } + + diff = cmp.Diff(loggerPluginName, osq.loggerPlugin) + if diff != "" { + t.Error(diff) + } +}