From 261f3db1ce055e5917e41b56c10c34f2576efb67 Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Tue, 12 Mar 2024 10:53:13 +0000 Subject: [PATCH 1/3] fix(build): correct version in docs output --- .github/workflows/on_release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index d27b371..f9bb55b 100644 --- a/.github/workflows/on_release.yml +++ b/.github/workflows/on_release.yml @@ -64,6 +64,9 @@ jobs: distribution: 'temurin' cache: 'maven' + - name: Update java version + run: mvn versions:set -DnewVersion=${VERSION} -B -U + - name: Package project run: mvn clean package -DskipTests -U -B -P cf-it-tests,examples From 3eea40669088473309a43d114a0c9dfc6b96d93f Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Tue, 12 Mar 2024 11:01:14 +0000 Subject: [PATCH 2/3] fix(plugins): ensure that failed plugins do not block start up --- .../deep/agent/plugins/PluginSpiLoader.java | 11 ++++- .../agent/plugins/PluginSpiLoaderTest.java | 47 +++++++++++++++++++ .../deep/agent/plugins/TestBadPlugin.java | 30 ++++++++++++ .../deep/agent/plugins/TestPlugin.java | 24 ++++++++++ ...m.intergral.deep.agent.api.spi.IDeepPlugin | 18 +++++++ 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java create mode 100644 agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java create mode 100644 agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java create mode 100644 agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin diff --git a/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java b/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java index 8ec9492..81ddd26 100644 --- a/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java +++ b/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java @@ -27,12 +27,16 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This acts as the main loader for plugins using the SPI loader system. */ public final class PluginSpiLoader { + private static final Logger LOGGER = LoggerFactory.getLogger(PluginSpiLoader.class); + private PluginSpiLoader() { } @@ -59,7 +63,12 @@ public static List loadPlugins(final ISettings settings, final IRef .filter(plugin -> !ResourceDetector.isDisabled(plugin.getClass(), enabledProviders, disabledProviders)) .filter(plugin -> { if (plugin instanceof IConditional) { - return ((IConditional) plugin).isActive(); + try { + return ((IConditional) plugin).isActive(); + } catch (Exception e) { + LOGGER.error("Failed to load plugin {}", plugin.getClass().getName(), e); + return false; + } } return true; }) diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java b/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java new file mode 100644 index 0000000..32a7d16 --- /dev/null +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2024 Intergral GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.intergral.deep.agent.plugins; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.intergral.deep.agent.api.settings.ISettings; +import com.intergral.deep.agent.api.spi.IDeepPlugin; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +class PluginSpiLoaderTest { + + @Test + void loadPlugins() { + final ISettings settings = Mockito.mock(ISettings.class); + final List iDeepPlugins = PluginSpiLoader.loadPlugins(settings, null, null); + assertNotNull(iDeepPlugins); + + assertTrue(iDeepPlugins.size() > 1); + + final Set classNames = iDeepPlugins.stream().map(Object::getClass).map(Class::getName).collect(Collectors.toSet()); + + assertTrue(classNames.contains(TestPlugin.class.getName())); + assertFalse(classNames.contains(TestBadPlugin.class.getName())); + } +} \ No newline at end of file diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java b/agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java new file mode 100644 index 0000000..ab399e4 --- /dev/null +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 Intergral GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.intergral.deep.agent.plugins; + +import com.intergral.deep.agent.api.spi.IConditional; +import com.intergral.deep.agent.api.spi.IDeepPlugin; + +public class TestBadPlugin implements IDeepPlugin, IConditional { + + + @Override + public boolean isActive() { + throw new RuntimeException("test exception"); + } +} diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java b/agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java new file mode 100644 index 0000000..06ef432 --- /dev/null +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 Intergral GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.intergral.deep.agent.plugins; + +import com.intergral.deep.agent.api.spi.IDeepPlugin; + +public class TestPlugin implements IDeepPlugin { + +} diff --git a/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin b/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin new file mode 100644 index 0000000..bbf8563 --- /dev/null +++ b/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin @@ -0,0 +1,18 @@ +# +# Copyright (C) 2024 Intergral GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +com.intergral.deep.agent.plugins.TestPlugin +com.intergral.deep.agent.plugins.TestBadPlugin From a3a8c04efa35d175147dc8b082ae245730d290dc Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Tue, 12 Mar 2024 11:07:43 +0000 Subject: [PATCH 3/3] fix(plugins): ensure that failed plugins do not block start up - rename test plugins - update CHANGELOG.md --- CHANGELOG.md | 1 + .../agent/plugins/{TestBadPlugin.java => MockBadPlugin.java} | 5 ++++- .../deep/agent/plugins/{TestPlugin.java => MockPlugin.java} | 5 ++++- .../intergral/deep/agent/plugins/PluginSpiLoaderTest.java | 4 ++-- .../services/com.intergral.deep.agent.api.spi.IDeepPlugin | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) rename agent/src/test/java/com/intergral/deep/agent/plugins/{TestBadPlugin.java => MockBadPlugin.java} (86%) rename agent/src/test/java/com/intergral/deep/agent/plugins/{TestPlugin.java => MockPlugin.java} (86%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eb6b7e..4f77a91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 1.2.1 - (12/03/2024) - **[BUGFIX]**: plugin: fix ColdFusion detection on Windows [#116](https://github.com/intergral/deep/pull/116) [@LMarkie](https://github.com/LMarkie) +- **[BUGFIX]**: plugin: ensure that failed plugins do not block start up [#118](https://github.com/intergral/deep/pull/118) [@Umaaz](https://github.com/Umaaz) # 1.2.0 - (06/02/2024) - **[CHANGE]**: change log config to allow better control of logging [#103](https://github.com/intergral/deep/pull/103) [@Umaaz](https://github.com/Umaaz) diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java b/agent/src/test/java/com/intergral/deep/agent/plugins/MockBadPlugin.java similarity index 86% rename from agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java rename to agent/src/test/java/com/intergral/deep/agent/plugins/MockBadPlugin.java index ab399e4..fa89d56 100644 --- a/agent/src/test/java/com/intergral/deep/agent/plugins/TestBadPlugin.java +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/MockBadPlugin.java @@ -20,7 +20,10 @@ import com.intergral.deep.agent.api.spi.IConditional; import com.intergral.deep.agent.api.spi.IDeepPlugin; -public class TestBadPlugin implements IDeepPlugin, IConditional { +/** + * This is used to test the SPI loder and just throws an exception on activate. + */ +public class MockBadPlugin implements IDeepPlugin, IConditional { @Override diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java b/agent/src/test/java/com/intergral/deep/agent/plugins/MockPlugin.java similarity index 86% rename from agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java rename to agent/src/test/java/com/intergral/deep/agent/plugins/MockPlugin.java index 06ef432..464232e 100644 --- a/agent/src/test/java/com/intergral/deep/agent/plugins/TestPlugin.java +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/MockPlugin.java @@ -19,6 +19,9 @@ import com.intergral.deep.agent.api.spi.IDeepPlugin; -public class TestPlugin implements IDeepPlugin { +/** + * This is used to test the SPI loder and doesn't need to actually do anything. + */ +public class MockPlugin implements IDeepPlugin { } diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java b/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java index 32a7d16..e995ac1 100644 --- a/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java @@ -41,7 +41,7 @@ void loadPlugins() { final Set classNames = iDeepPlugins.stream().map(Object::getClass).map(Class::getName).collect(Collectors.toSet()); - assertTrue(classNames.contains(TestPlugin.class.getName())); - assertFalse(classNames.contains(TestBadPlugin.class.getName())); + assertTrue(classNames.contains(MockPlugin.class.getName())); + assertFalse(classNames.contains(MockBadPlugin.class.getName())); } } \ No newline at end of file diff --git a/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin b/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin index bbf8563..0c2223a 100644 --- a/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin +++ b/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin @@ -14,5 +14,5 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # -com.intergral.deep.agent.plugins.TestPlugin -com.intergral.deep.agent.plugins.TestBadPlugin +com.intergral.deep.agent.plugins.MockPlugin +com.intergral.deep.agent.plugins.MockBadPlugin