From 6088191f9ef32c396f9a01f401306ce3a85cefcd Mon Sep 17 00:00:00 2001 From: Jerry Leung Date: Tue, 28 Nov 2023 16:42:23 -0800 Subject: [PATCH] Use Error instead of Fatal --- .../extension.go | 4 ++-- .../extension_test.go | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/extension/solarwindsapmsettingsextension/extension.go b/extension/solarwindsapmsettingsextension/extension.go index 3b5741efd370..4054ec4bc924 100644 --- a/extension/solarwindsapmsettingsextension/extension.go +++ b/extension/solarwindsapmsettingsextension/extension.go @@ -44,7 +44,7 @@ func newSolarwindsApmSettingsExtension(extensionCfg *Config, logger *zap.Logger) func Refresh(extension *solarwindsapmSettingsExtension) { extension.logger.Info("Time to refresh from " + extension.config.Endpoint) if hostname, err := os.Hostname(); err != nil { - extension.logger.Fatal("Unable to call os.Hostname() " + err.Error()) + extension.logger.Error("Unable to call os.Hostname() " + err.Error()) } else { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -57,7 +57,7 @@ func Refresh(extension *solarwindsapmSettingsExtension) { ClientVersion: "2", } if response, err := extension.client.GetSettings(ctx, request); err != nil { - extension.logger.Fatal("Unable to getSettings from " + extension.config.Endpoint + " " + err.Error()) + extension.logger.Error("Unable to getSettings from " + extension.config.Endpoint + " " + err.Error()) } else { switch result := response.GetResult(); result { case collectorpb.ResultCode_OK: diff --git a/extension/solarwindsapmsettingsextension/extension_test.go b/extension/solarwindsapmsettingsextension/extension_test.go index 9c865fd6f9e4..923b9f929177 100644 --- a/extension/solarwindsapmsettingsextension/extension_test.go +++ b/extension/solarwindsapmsettingsextension/extension_test.go @@ -18,6 +18,26 @@ func TestCreateExtension(t *testing.T) { ex.Shutdown(context.TODO()) } +func TestCreateExtensionWrongEndpoint(t *testing.T) { + conf := &Config{ + Endpoint: "apm.collector.cloud.solarwindsswoswoswo.com:443", + Key: "vlEW1JtimSH2LlBsNrPdeEjBxNl5z8Bp7gX55bNTk3_GIxHWedgj42GDFBWpRe2ne7TffHk:jerry_test", + Interval: "1s", + } + ex := createAnExtension(conf, t) + ex.Shutdown(context.TODO()) +} + +func TestCreateExtensionWrongKey(t *testing.T) { + conf := &Config{ + Endpoint: "apm.collector.cloud.solarwinds.com:443", + Key: "IsItAKey:jerry_test", + Interval: "1s", + } + ex := createAnExtension(conf, t) + ex.Shutdown(context.TODO()) +} + // create extension func createAnExtension(c *Config, t *testing.T) extension.Extension { logger, err := zap.NewProduction()