From 43a5b6093bda06d49037a919f85ec15b9e31b3f4 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Mon, 2 Dec 2024 11:12:56 -0500 Subject: [PATCH] NH-95070: address codeQl stuff --- .../joboe/core/ReporterFactory.java | 70 +----------------- .../hdrHistogram/HistogramLogProcessor.java | 9 ++- .../joboe/core/rpc/RpcSettings.java | 14 +--- .../joboe/core/settings/SettingsUtil.java | 11 --- .../core/settings/TestSettingsReader.java | 7 -- .../solarwinds/joboe/core/util/TestUtils.java | 5 -- .../joboe/core/ReporterFactoryTest.java | 15 ---- .../com/solarwinds/joboe/core/TraceTest.java | 73 ------------------- .../joboe/core/rpc/RpcClientTest.java | 17 ++--- .../joboe/core/rpc/grpc/GrpcClientTest.java | 18 ++--- .../settings/PollingSettingsFetcherTest.java | 14 ++-- .../joboe/core/settings/SettingsUtilTest.java | 3 +- pom.xml | 4 +- .../solarwinds/joboe/sampling/LruCache.java | 9 +++ .../solarwinds/joboe/sampling/Settings.java | 8 +- .../joboe/sampling/LruCacheTest.java | 8 ++ .../joboe/sampling/SettingsStub.java | 7 -- 17 files changed, 56 insertions(+), 236 deletions(-) delete mode 100644 core/src/test/java/com/solarwinds/joboe/core/TraceTest.java diff --git a/core/src/main/java/com/solarwinds/joboe/core/ReporterFactory.java b/core/src/main/java/com/solarwinds/joboe/core/ReporterFactory.java index 10ceda65..f7fe7530 100644 --- a/core/src/main/java/com/solarwinds/joboe/core/ReporterFactory.java +++ b/core/src/main/java/com/solarwinds/joboe/core/ReporterFactory.java @@ -16,66 +16,13 @@ public class ReporterFactory { private static final Logger logger = LoggerFactory.getLogger(); - private String tracelyzerHost = Constants.XTR_UDP_HOST; - private int tracelyzerPort = Constants.XTR_UDP_PORT; - private String datagramLocalAddress; - private Integer datagramLocalPort; - - private static final String OPENSHIFT_TRACEVIEW_TLYZER_IP = "OPENSHIFT_TRACEVIEW_TLYZER_IP"; - private static final String OPENSHIFT_TRACEVIEW_TLYZER_PORT = "OPENSHIFT_TRACEVIEW_TLYZER_PORT"; - private static final String OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_IP = "OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_IP"; - private static final String OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_PORT = "OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_PORT"; - - private static final String TRACELYTICS_UDPADDR = "TRACELYTICS_UDPADDR"; - private static final String TRACELYTICS_UDPPORT = "TRACELYTICS_UDPPORT"; - - private static UDPReporter singletonUdpReporter; - private static final Object singletonUdpReporterLock = new Object(); @Getter(lazy = true) private static final ReporterFactory instance = new ReporterFactory(); private ReporterFactory() { - Map env = System.getenv(); - - if (env.containsKey(TRACELYTICS_UDPADDR)) { - tracelyzerHost = env.get(TRACELYTICS_UDPADDR); - logger.info("Setting Reporter to contact Tracelyzer host on [" + tracelyzerHost + "]"); - } - if (env.containsKey(TRACELYTICS_UDPPORT)) { - tracelyzerPort = Integer.parseInt(env.get(TRACELYTICS_UDPPORT)); - logger.info("Setting Reporter to contact Tracelyzer port on [" + tracelyzerPort + "]"); - } - - //open shift check - if (env.containsKey(OPENSHIFT_TRACEVIEW_TLYZER_IP)) { - tracelyzerHost = env.get(OPENSHIFT_TRACEVIEW_TLYZER_IP); - logger.info("Running in OpenShift environment. Setting Reporter to contact Tracelyzer host on [" + tracelyzerHost + "]"); - } - if (env.containsKey(OPENSHIFT_TRACEVIEW_TLYZER_PORT)) { - tracelyzerPort = Integer.parseInt(env.get(OPENSHIFT_TRACEVIEW_TLYZER_PORT)); - logger.info("Running in OpenShift environment. Setting Reporter to contact Tracelyzer port on [" + tracelyzerPort + "]"); - } - if (env.containsKey(OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_IP)) { - datagramLocalAddress = env.get(OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_IP); - logger.info("Running in OpenShift environment. Setting Reporter datagram port to [" + datagramLocalAddress + "]"); - } - if (env.containsKey(OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_PORT)) { - datagramLocalPort = Integer.parseInt(env.get(OPENSHIFT_TRACEVIEW_JAVA_DATAGRAM_PORT)); - logger.info("Running in OpenShift environment. Setting Reporter datagram port to [" + datagramLocalPort + "]"); - } - } - /** - * Builds a {@link UDPReporter}. Take note that this might create a singleton if the system has restrictions on UDP bind address/port - * - * @return - * @throws IOException - */ - public UDPReporter createUdpReporter() throws IOException { - return createUdpReporter(tracelyzerHost, tracelyzerPort); - } /** * Builds a {@link UDPReporter}. Take note that this might create a singleton if the system has restrictions on UDP bind address/port, in such an @@ -91,22 +38,7 @@ UDPReporter createUdpReporter(String host, Integer port) throws IOException { logger.error("Cannot build UDPReporter. Host and/or port params are null!"); return null; } - - logger.debug("Building UPD Reporter with host [" + host + "] and port [" + port + "]"); - - if (datagramLocalAddress != null && datagramLocalPort != null) { - //if using specific address and port, then we should only allow singleton; otherwise multiple UDP reporters will try to bind to the same address/port - synchronized (singletonUdpReporterLock) { - if (singletonUdpReporter == null) { - logger.debug("UPD Reporter specified datagram to bind on [" + datagramLocalAddress + ":" + datagramLocalPort + "]"); - singletonUdpReporter = new UDPReporter(host, port, datagramLocalAddress, datagramLocalPort); - } - } - - return singletonUdpReporter; - } else { - return new UDPReporter(host, port); - } + return new UDPReporter(host, port); } /** diff --git a/core/src/main/java/com/solarwinds/joboe/core/metrics/hdrHistogram/HistogramLogProcessor.java b/core/src/main/java/com/solarwinds/joboe/core/metrics/hdrHistogram/HistogramLogProcessor.java index dd385a10..f0bad26f 100644 --- a/core/src/main/java/com/solarwinds/joboe/core/metrics/hdrHistogram/HistogramLogProcessor.java +++ b/core/src/main/java/com/solarwinds/joboe/core/metrics/hdrHistogram/HistogramLogProcessor.java @@ -216,7 +216,7 @@ public void run() { PrintStream timeIntervalLog = null; PrintStream movingWindowLog = null; PrintStream histogramPercentileLog = System.out; - Double firstStartTime = 0.0; + double firstStartTime = 0.0; boolean timeIntervalLogLegendWritten = false; boolean movingWindowLogLegendWritten = false; @@ -442,9 +442,12 @@ public void run() { config.percentilesOutputTicksPerHalf, config.outputValueUnitRatio, config.logFormatCsv); } } finally { - if (config.outputFileName != null) { + if (timeIntervalLog != null) { timeIntervalLog.close(); - histogramPercentileLog.close(); + } + + if (movingWindowLog != null) { + movingWindowLog.close(); } } } diff --git a/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcSettings.java b/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcSettings.java index 396a6327..3aba96c2 100644 --- a/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcSettings.java +++ b/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcSettings.java @@ -7,6 +7,7 @@ import com.solarwinds.joboe.logging.Logger; import com.solarwinds.joboe.logging.LoggerFactory; +import com.solarwinds.joboe.sampling.Settings; import com.solarwinds.joboe.sampling.SettingsArg; import com.solarwinds.joboe.sampling.TraceDecisionUtil; @@ -21,12 +22,11 @@ public class RpcSettings extends com.solarwinds.joboe.sampling.Settings { private final short flags; // required private final long timestamp; // required, in millsec private final long value; // required - private final String layer; // required private final long ttl; //time to live this settings record private final Map, Object> args = new HashMap, Object>(); //other arguments - public RpcSettings(short type, String stringFlags, long timestamp, long value, long ttl, String layer, Map args) { - this.type = type; + public RpcSettings(String stringFlags, long timestamp, long value, long ttl, Map args) { + this.type = Settings.OBOE_SETTINGS_TYPE_DEFAULT_SAMPLE_RATE; this.flags = convertFlagsFromStringToShort(stringFlags); this.timestamp = timestamp; if (value < 0) { @@ -39,7 +39,6 @@ public RpcSettings(short type, String stringFlags, long timestamp, long value, l this.value = value; } this.ttl = ttl; - this.layer = layer; readArgs(args); } @@ -54,7 +53,6 @@ public RpcSettings(RpcSettings source, long timestamp) { this.timestamp = timestamp; //take the new timestamp this.value = source.value; this.ttl = source.ttl; - this.layer = source.layer; this.args.putAll(source.args); } @@ -117,11 +115,7 @@ public short getFlags() { return flags; } - @Override - public String getLayer() { - return layer; - } - + @Override public long getTtl() { return ttl; diff --git a/core/src/main/java/com/solarwinds/joboe/core/settings/SettingsUtil.java b/core/src/main/java/com/solarwinds/joboe/core/settings/SettingsUtil.java index 3c9c705d..aa65f517 100644 --- a/core/src/main/java/com/solarwinds/joboe/core/settings/SettingsUtil.java +++ b/core/src/main/java/com/solarwinds/joboe/core/settings/SettingsUtil.java @@ -16,15 +16,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class SettingsUtil { - public static Map transformToKVSetting(SettingsResult settingsResult){ - Map updatedSettings = new LinkedHashMap(); - for (Settings settingsForLayer : settingsResult.getSettings()) { - LoggerFactory.getLogger().debug("Got settings from collector: " + settingsForLayer); - updatedSettings.put(settingsForLayer.getLayer(), settingsForLayer); - } - return updatedSettings; - } - public static SettingsResult transformToLocalSettings(Collector.SettingsResult result){ List settings = new ArrayList<>(); if (result.getResult() == Collector.ResultCode.OK) { @@ -44,12 +35,10 @@ public static Settings convertSetting(Collector.OboeSetting grpcOboeSetting) { } return new RpcSettings( - convertType(grpcOboeSetting.getType()), grpcOboeSetting.getFlags().toStringUtf8(), System.currentTimeMillis(), //use local timestamp for now, as it is easier to compare ttl with it grpcOboeSetting.getValue(), grpcOboeSetting.getTtl(), - grpcOboeSetting.getLayer().toStringUtf8(), convertedArguments); } diff --git a/core/src/main/java/com/solarwinds/joboe/core/settings/TestSettingsReader.java b/core/src/main/java/com/solarwinds/joboe/core/settings/TestSettingsReader.java index be9010b8..dcd01bc7 100644 --- a/core/src/main/java/com/solarwinds/joboe/core/settings/TestSettingsReader.java +++ b/core/src/main/java/com/solarwinds/joboe/core/settings/TestSettingsReader.java @@ -186,15 +186,8 @@ public short getType() { return settingsType; } - @Override - public String getLayer() { - // TODO Auto-generated method stub - return null; - } - @Override public long getTtl() { - // TODO Auto-generated method stub return 0; } } diff --git a/core/src/main/java/com/solarwinds/joboe/core/util/TestUtils.java b/core/src/main/java/com/solarwinds/joboe/core/util/TestUtils.java index 40d75199..314ef54d 100644 --- a/core/src/main/java/com/solarwinds/joboe/core/util/TestUtils.java +++ b/core/src/main/java/com/solarwinds/joboe/core/util/TestUtils.java @@ -74,11 +74,6 @@ public short getFlags() { return TracingMode.ALWAYS.toFlags(); } - @Override - public String getLayer() { - return ""; - } - @Override public long getTtl() { return Integer.MAX_VALUE; //don't use long, otherwise it might overflow... diff --git a/core/src/test/java/com/solarwinds/joboe/core/ReporterFactoryTest.java b/core/src/test/java/com/solarwinds/joboe/core/ReporterFactoryTest.java index b6b15145..0464fa06 100644 --- a/core/src/test/java/com/solarwinds/joboe/core/ReporterFactoryTest.java +++ b/core/src/test/java/com/solarwinds/joboe/core/ReporterFactoryTest.java @@ -26,21 +26,6 @@ static void setup() { tested = ReporterFactory.getInstance(); } - @Test - public void testbuildDefaultUdpReporter() throws Exception { - UDPReporter reporter = tested.createUdpReporter(); - - Field addressField = reporter.getClass().getDeclaredField("addr"); - addressField.setAccessible(true); - - Field portField = reporter.getClass().getDeclaredField("port"); - portField.setAccessible(true); - - InetAddress address = (InetAddress) addressField.get(reporter); - assertEquals(InetAddress.getByName(Constants.XTR_UDP_HOST), address); - assertEquals(Constants.XTR_UDP_PORT, portField.get(reporter)); - } - @Test public void testbuildNonDefaultUdpReporter() throws Exception { UDPReporter reporter = tested.createUdpReporter("localhost", 9999); diff --git a/core/src/test/java/com/solarwinds/joboe/core/TraceTest.java b/core/src/test/java/com/solarwinds/joboe/core/TraceTest.java deleted file mode 100644 index 29bb6281..00000000 --- a/core/src/test/java/com/solarwinds/joboe/core/TraceTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.solarwinds.joboe.core; - -import com.solarwinds.joboe.core.Context; -import com.solarwinds.joboe.core.Event; -import com.solarwinds.joboe.core.EventReporter; -import com.solarwinds.joboe.core.ReporterFactory; -import org.junit.jupiter.api.Test; - -public class TraceTest { - /* Make sure we can report a trace: generate several events with multiple layers */ - @Test - public void testTrace() - throws Exception { - EventReporter reporter = ReporterFactory.getInstance().createUdpReporter(); - - Event event = Context.startTrace(); - event.addInfo("Layer", "JavaTest", - "Label", "entry"); - event.report(reporter); - - Thread.sleep(10); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest_2", - "Label", "entry"); - event.report(reporter); - - Thread.sleep(20); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest_2", - "Label", "exit"); - event.report(reporter); - - Thread.sleep(10); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest_3", - "Label", "entry"); - event.report(reporter); - - Thread.sleep(20); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest_4", - "Label", "entry"); - event.report(reporter); - - Thread.sleep(20); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest_4", - "Label", "exit"); - event.report(reporter); - - Thread.sleep(40); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest_3", - "Label", "exit"); - event.report(reporter); - - Thread.sleep(50); - - event = Context.createEvent(); - event.addInfo("Layer", "JavaTest", - "Label", "exit"); - event.report(reporter); - - Context.clearMetadata(); - } - // XXX: Some way to check these were actually processed -} diff --git a/core/src/test/java/com/solarwinds/joboe/core/rpc/RpcClientTest.java b/core/src/test/java/com/solarwinds/joboe/core/rpc/RpcClientTest.java index f8a34249..b6a7e13c 100644 --- a/core/src/test/java/com/solarwinds/joboe/core/rpc/RpcClientTest.java +++ b/core/src/test/java/com/solarwinds/joboe/core/rpc/RpcClientTest.java @@ -83,11 +83,11 @@ protected interface TestCollector { protected abstract TestCollector startCollector(int port) throws IOException; protected abstract TestCollector startRedirectCollector(int port, String redirectArg) throws IOException; - protected abstract TestCollector startRatedCollector(int port, int processingTimePerMessage, ResultCode limitExceededCode) throws IOException; - protected abstract TestCollector startBiasedTestCollector(int port, Map taskToResponseCode) throws IOException; + protected abstract TestCollector startRatedCollector(int port, ResultCode limitExceededCode) throws IOException; + protected abstract TestCollector startBiasedTestCollector(int port) throws IOException; //Test server that throws Runtime exception on every other message protected abstract TestCollector startErroneousTestCollector(int port, double errorPercentage) throws IOException; - protected abstract TestCollector startSoftDisabledTestCollector(int port, String warning) throws IOException; + protected abstract void startSoftDisabledTestCollector(int port, String warning) throws IOException; protected static String getServerPublicKeyLocation() { return TEST_SERVER_CERT_LOCATION; @@ -101,7 +101,7 @@ private static List generateTestSettings() { arguments.put(SettingsArg.BUCKET_CAPACITY.getKey(), SettingsArg.BUCKET_CAPACITY.toByteBuffer(32.0)); arguments.put(SettingsArg.BUCKET_RATE.getKey(), SettingsArg.BUCKET_RATE.toByteBuffer(2.0)); - settings.add(new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_DEFAULT_SAMPLE_RATE, PollingSettingsFetcherTest.DEFAULT_FLAGS_STRING, TimeUtils.getTimestampMicroSeconds(), 1000000, 600, "test-layer", arguments)); + settings.add(new RpcSettings(PollingSettingsFetcherTest.DEFAULT_FLAGS_STRING, TimeUtils.getTimestampMicroSeconds(), 1000000, 600, arguments)); return settings; } @@ -274,7 +274,6 @@ public void testGetSettings() throws Exception { com.solarwinds.joboe.core.rpc.SettingsResult result = client.getSettings("", null).get(); assertEquals(com.solarwinds.joboe.core.rpc.ResultCode.OK, result.getResultCode()); - assertEquals(TEST_SETTINGS.size(), result.getSettings().size()); for (int i = 0 ; i < TEST_SETTINGS.size(); i ++) { @@ -284,8 +283,6 @@ public void testGetSettings() throws Exception { short expectedFlags = expectedSetting.getFlags(); assertEquals(expectedFlags, receivedSetting.getFlags()); - assertEquals(expectedSetting.getLayer(), receivedSetting.getLayer()); - //assertEquals(expectedSetting.getTimestamp(), receivedSetting.getTimestamp()); timestamp for now we will use the machine's current timestamp instead of the incoming one as TTL is tricky (otherwise we would have to keep 2 timestamps...) assertEquals(expectedSetting.getValue(), receivedSetting.getValue()); assertEquals(expectedSetting.getArgValue(SettingsArg.BUCKET_CAPACITY), receivedSetting.getArgValue(SettingsArg.BUCKET_CAPACITY), 0); assertEquals(expectedSetting.getArgValue(SettingsArg.BUCKET_RATE), receivedSetting.getArgValue(SettingsArg.BUCKET_RATE), 0); @@ -591,7 +588,7 @@ public void testTryLater() throws Exception { final int TIME_PER_EVENT = 10; int tryLaterPort = locateAvailablePort(); - TestCollector tryLaterCollector = startRatedCollector(tryLaterPort, TIME_PER_EVENT, ResultCode.TRY_LATER); + TestCollector tryLaterCollector = startRatedCollector(tryLaterPort, ResultCode.TRY_LATER); Client client = null; try { @@ -629,7 +626,7 @@ public void testLimitExceed() throws Exception { final int TIME_PER_EVENT = 10; int tryLaterPort = locateAvailablePort(); - TestCollector tryLaterServer = startRatedCollector(tryLaterPort, TIME_PER_EVENT, ResultCode.LIMIT_EXCEEDED); + TestCollector tryLaterServer = startRatedCollector(tryLaterPort, ResultCode.LIMIT_EXCEEDED); Client client = null; try { @@ -798,7 +795,7 @@ public void testBiasedServer() throws Exception { System.out.println("running testBiasedServer"); int biasedServerPort = locateAvailablePort(); - TestCollector basiedServer = startBiasedTestCollector(biasedServerPort, Collections.singletonMap(TaskType.POST_METRICS, ResultCode.TRY_LATER)); + TestCollector basiedServer = startBiasedTestCollector(biasedServerPort); Client client = new RpcClient(TEST_SERVER_HOST, biasedServerPort, TEST_CLIENT_ID, getProtocolClientFactory(new File(getServerPublicKeyLocation()).toURI().toURL())); assertThrows(TimeoutException.class, () -> client.postMetrics(new ArrayList>(), null).get(5, TimeUnit.SECONDS),"Not expecting to return any result for this call!"); //this is supposed to get held up because of TRY_LAYER) diff --git a/core/src/test/java/com/solarwinds/joboe/core/rpc/grpc/GrpcClientTest.java b/core/src/test/java/com/solarwinds/joboe/core/rpc/grpc/GrpcClientTest.java index cbbfb958..6df4de03 100644 --- a/core/src/test/java/com/solarwinds/joboe/core/rpc/grpc/GrpcClientTest.java +++ b/core/src/test/java/com/solarwinds/joboe/core/rpc/grpc/GrpcClientTest.java @@ -40,7 +40,6 @@ import static org.junit.jupiter.api.Assertions.fail; -//@RunWith(Parameterized.class) public class GrpcClientTest extends RpcClientTest { private static final String TEST_SERVER_PRIVATE_KEY_LOCATION = "src/test/java/com/solarwinds/joboe/core/rpc/grpc/test-collector-private.pem"; @@ -57,11 +56,10 @@ private static List convertToOboeSettings(List taskToResponseCode) throws IOException { + protected TestCollector startBiasedTestCollector(int port) throws IOException { return new GrpcCollector(port, new GrpcBiasedCollectorService(Collections.singletonMap(TaskType.POST_METRICS, Collector.ResultCode.TRY_LATER))); } @@ -120,12 +118,12 @@ protected TestCollector startErroneousTestCollector(int port, double errorPercen } @Override - protected TestCollector startSoftDisabledTestCollector(int port, String warning) throws IOException { - return new GrpcCollector(port, new GrpcCollectorService(Collector.ResultCode.OK, "", warning)); + protected void startSoftDisabledTestCollector(int port, String warning) throws IOException { + new GrpcCollector(port, new GrpcCollectorService(Collector.ResultCode.OK, "", warning)); } - private TestCollector startExhaustedServer(int port) throws IOException { - return new GrpcCollector(port, new GrpcCollectorService() { + private void startExhaustedServer(int port) throws IOException { + new GrpcCollector(port, new GrpcCollectorService() { @Override public void postEvents(Collector.MessageRequest request, StreamObserver responseObserver) { responseObserver.onError(Status.RESOURCE_EXHAUSTED.withDescription("Testing resource exhaustion on server side").asRuntimeException()); diff --git a/core/src/test/java/com/solarwinds/joboe/core/settings/PollingSettingsFetcherTest.java b/core/src/test/java/com/solarwinds/joboe/core/settings/PollingSettingsFetcherTest.java index f72b9615..7e5a1608 100644 --- a/core/src/test/java/com/solarwinds/joboe/core/settings/PollingSettingsFetcherTest.java +++ b/core/src/test/java/com/solarwinds/joboe/core/settings/PollingSettingsFetcherTest.java @@ -59,7 +59,7 @@ public class PollingSettingsFetcherTest { // MOCK_SETTINGS.add(new com.solarwinds.joboe.core.rpc.Settings(Settings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, Agent.currentTimeStamp(), layerSampleRate.getValue(), TTL, layerSampleRate.getKey(), args)); // } - MOCK_SETTINGS.add(new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_DEFAULT_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), SAMPLE_RATE_FOR_DEFAULT_LAYER, TTL, "", ARGS)); + MOCK_SETTINGS.add(new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), SAMPLE_RATE_FOR_DEFAULT_LAYER, TTL, ARGS)); } @@ -133,7 +133,7 @@ public void testInvalidArgs() throws Exception { Settings sourceSettings; //test remote settings that give empty map for args - sourceSettings = new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 100000, TTL, "", Collections.emptyMap()); + sourceSettings = new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 100000, TTL, Collections.emptyMap()); Client client = new MockRpcClient(Collections.singletonList(sourceSettings)); fetcher = getFetcher(client); settings = fetcher.getSettings(); @@ -147,7 +147,7 @@ public void testInvalidArgs() throws Exception { args.put(SettingsArg.BUCKET_CAPACITY.getKey(), ByteBuffer.allocate(0)); args.put(SettingsArg.BUCKET_RATE.getKey(), ByteBuffer.allocate(0)); args.put(SettingsArg.METRIC_FLUSH_INTERVAL.getKey(), ByteBuffer.allocate(0)); - sourceSettings = new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 100000, TTL, "", args); + sourceSettings = new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 100000, TTL, args); fetcher = getFetcher(new MockRpcClient(Collections.singletonList(sourceSettings))); settings = fetcher.getSettings(); assertEquals(100000, (int)settings.getValue()); @@ -171,7 +171,7 @@ public void testInvalidArgs() throws Exception { buffer.putInt(3); buffer.rewind(); args.put(SettingsArg.METRIC_FLUSH_INTERVAL.getKey(), buffer); - sourceSettings = new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 100000, TTL, "", args); + sourceSettings = new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 100000, TTL, args); fetcher = getFetcher(new MockRpcClient(Collections.singletonList(sourceSettings))); settings = fetcher.getSettings(); assertEquals(100000, (int)settings.getValue()); @@ -190,7 +190,7 @@ public void testInvalidSampleRate() throws Exception { Settings sourceSettings; //test remote settings that gives sample rate that is greater than 1000000 - sourceSettings = new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 1111111, TTL, "", ARGS); + sourceSettings = new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 1111111, TTL, ARGS); Client client = new MockRpcClient(Collections.singletonList(sourceSettings)); fetcher = getFetcher(client); assert fetcher != null; @@ -201,7 +201,7 @@ public void testInvalidSampleRate() throws Exception { assertEquals(BUCKET_RATE, settings.getArgValue(SettingsArg.BUCKET_RATE)); //test remote settings that gives sample rate that is negative - sourceSettings = new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), -1, TTL, "", ARGS); + sourceSettings = new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), -1, TTL, ARGS); fetcher = getFetcher(new MockRpcClient(Collections.singletonList(sourceSettings))); settings = fetcher.getSettings(); assertEquals(0, (int)settings.getValue()); //should be adjusted to 0 @@ -227,7 +227,7 @@ public void testExecutionException() throws Exception { @Test public void testSettingsListener() throws InterruptedException { RpcSettings settings; - settings = new RpcSettings(RpcSettings.OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE, DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 1, TTL, "", ARGS); + settings = new RpcSettings(DEFAULT_FLAGS_STRING, System.currentTimeMillis(), 1, TTL, ARGS); Client client = new MockRpcClient(Collections.singletonList(settings)); SettingsFetcher fetcher = new PollingSettingsFetcher(new RpcSettingsReader(client), 1); //refresh every second diff --git a/core/src/test/java/com/solarwinds/joboe/core/settings/SettingsUtilTest.java b/core/src/test/java/com/solarwinds/joboe/core/settings/SettingsUtilTest.java index 79309124..0e61ac4d 100644 --- a/core/src/test/java/com/solarwinds/joboe/core/settings/SettingsUtilTest.java +++ b/core/src/test/java/com/solarwinds/joboe/core/settings/SettingsUtilTest.java @@ -39,9 +39,8 @@ static void setup() throws IOException { void testTransformToKVSetting() { when(settingsMock.getTtl()).thenReturn(60L); SettingsResult settingsResult = new SettingsResult(ResultCode.OK, "arg", "we up", Collections.singletonList(settingsMock)); - Map settingsMap = SettingsUtil.transformToKVSetting(settingsResult); - boolean anyMatch = settingsMap.values().stream().anyMatch(settings -> settings.getTtl() == 60); + boolean anyMatch = settingsResult.getSettings().stream().anyMatch(settings -> settings.getTtl() == 60); assertTrue(anyMatch); } diff --git a/pom.xml b/pom.xml index 2beaf844..0d235d9e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ joboe - 10.0.14-SNAPSHOT + 10.0.15-SNAPSHOT UTF-8 ${git.commit.time} @@ -136,7 +136,7 @@ org.projectlombok lombok - 1.18.26 + 1.18.32 provided diff --git a/sampling/src/main/java/com/solarwinds/joboe/sampling/LruCache.java b/sampling/src/main/java/com/solarwinds/joboe/sampling/LruCache.java index 757070b5..38ff94f3 100644 --- a/sampling/src/main/java/com/solarwinds/joboe/sampling/LruCache.java +++ b/sampling/src/main/java/com/solarwinds/joboe/sampling/LruCache.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -14,4 +15,12 @@ public class LruCache extends LinkedHashMap { protected boolean removeEldestEntry(Map.Entry eldest) { return size() > maximumSize; } + + @Override + public Object clone() { + Object clone = super.clone(); + return new LruCache(maximumSize) {{ + putAll((HashMap) clone); + }}; + } } diff --git a/sampling/src/main/java/com/solarwinds/joboe/sampling/Settings.java b/sampling/src/main/java/com/solarwinds/joboe/sampling/Settings.java index 9ff94e07..2b0bf60e 100644 --- a/sampling/src/main/java/com/solarwinds/joboe/sampling/Settings.java +++ b/sampling/src/main/java/com/solarwinds/joboe/sampling/Settings.java @@ -33,7 +33,6 @@ public abstract class Settings { public abstract long getTimestamp(); public abstract short getType(); public abstract short getFlags(); - public abstract String getLayer(); public abstract long getTtl(); public abstract T getArgValue(SettingsArg arg); @@ -46,8 +45,7 @@ public final boolean isDefault() { public String toString() { return "[Settings: timestamp=" + getTimestamp() + " type=" + getType() + - " layer=" + getLayer() + - " flags=" + getFlags() + + " flags=" + getFlags() + " value=" + getValue() + " ttl=" + getTtl() + " args=" + getArgsString() + @@ -60,9 +58,9 @@ private String getArgsString() { Object value = getArgValue(arg); if (value != null) { if (arg == SettingsArg.TRACE_OPTIONS_SECRET) { - builder.append(arg.getKey() + "=, "); + builder.append(arg.getKey()).append("=, "); } else { - builder.append(arg.getKey() + "=" + value + ", "); + builder.append(arg.getKey()).append("=").append(value).append(", "); } } diff --git a/sampling/src/test/java/com/solarwinds/joboe/sampling/LruCacheTest.java b/sampling/src/test/java/com/solarwinds/joboe/sampling/LruCacheTest.java index 644624f8..cceea84e 100644 --- a/sampling/src/test/java/com/solarwinds/joboe/sampling/LruCacheTest.java +++ b/sampling/src/test/java/com/solarwinds/joboe/sampling/LruCacheTest.java @@ -16,4 +16,12 @@ void ensureMaximumSizeIsRespect() { assertEquals(1, tested.size()); assertEquals("two", tested.get("two")); } + + @Test + void testClone() { + tested.put("one", "one"); + tested.put("two", "two"); + + assertEquals(tested, tested.clone()); + } } \ No newline at end of file diff --git a/sampling/src/test/java/com/solarwinds/joboe/sampling/SettingsStub.java b/sampling/src/test/java/com/solarwinds/joboe/sampling/SettingsStub.java index 713d08a7..4f78b2ca 100644 --- a/sampling/src/test/java/com/solarwinds/joboe/sampling/SettingsStub.java +++ b/sampling/src/test/java/com/solarwinds/joboe/sampling/SettingsStub.java @@ -45,15 +45,8 @@ public short getType() { return settingsType; } - @Override - public String getLayer() { - // TODO Auto-generated method stub - return null; - } - @Override public long getTtl() { - // TODO Auto-generated method stub return 0; }