diff options
author | Arne Juul <arnej@vespa.ai> | 2024-02-06 13:11:22 +0000 |
---|---|---|
committer | Arne Juul <arnej@vespa.ai> | 2024-02-06 13:11:22 +0000 |
commit | ea12c9b990b81df22dc47fc6d796a2aaab03ef97 (patch) | |
tree | eab2b9415a9f66d46cf34bfd970c078857a7f7de /logserver | |
parent | fcca2419ded121767da85b563efb7a634533bae1 (diff) |
drop logging of metrics
Diffstat (limited to 'logserver')
5 files changed, 1 insertions, 401 deletions
diff --git a/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java b/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java index 31dc86f3b18..ca96afa8932 100644 --- a/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java +++ b/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java @@ -3,7 +3,6 @@ package com.yahoo.logserver; import java.util.logging.Level; import com.yahoo.logserver.handlers.archive.ArchiverPlugin; -import com.yahoo.logserver.handlers.logmetrics.LogMetricsPlugin; import java.util.logging.Logger; @@ -20,7 +19,6 @@ public class BuiltinPluginLoader extends AbstractPluginLoader { log.log(Level.FINE, "starting to load builtin plugins"); loadFromClass(ArchiverPlugin.class); - loadFromClass(LogMetricsPlugin.class); log.log(Level.FINE, "done loading builtin plugins"); } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java deleted file mode 100644 index c32eaa4d573..00000000000 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/* - * $Id$ - */ -package com.yahoo.logserver.handlers.logmetrics; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.ArrayList; -import java.util.logging.Logger; -import java.util.logging.Level; - -import com.yahoo.log.LogLevel; -import com.yahoo.log.event.Event; -import com.yahoo.logserver.filter.LevelFilter; -import com.yahoo.log.LogMessage; -import com.yahoo.logserver.handlers.AbstractLogHandler; - -/** - * The LogMetricsHandler stores a count of the number of log messages - * per level per host and sends an event count for this five minutes. - * - * @author hmusum - */ -public class LogMetricsHandler extends AbstractLogHandler { - private static final long EVENTINTERVAL = 5 * 60; // in seconds - - private static final Logger log = Logger.getLogger(LogMetricsHandler.class.getName()); - - // A list of log metrics per host and per log level - private final List<LevelCount> logMetrics = new ArrayList<LevelCount>(); - - // The log levels that are handled by this plugin - @SuppressWarnings("deprecation") - private static final Level[] levels = {LogLevel.INFO, - LogLevel.WARNING, - LogLevel.SEVERE, - LogLevel.ERROR, - LogLevel.FATAL}; - - - /** - * Constructor sets a default log filter ignoring the config, - * debug and spam levels. - */ - public LogMetricsHandler() { - LevelFilter filter = new LevelFilter(); - - for (Level level : Arrays.asList(levels)) { - filter.addLevel(level); - } - - setLogFilter(filter); - - // Start thread that sends events. - EventGenerator eventThread = new EventGenerator(); - new Thread(eventThread).start(); - } - - public boolean doHandle(LogMessage message) { - String host = message.getHost(); - Level logLevel = message.getLevel(); - - boolean found = false; - if (logMetrics.size() > 0) { - LevelCount count; - // Loop through the list logMetrics and check if there - // exists an element with the same host and level. - for (int i = 0; i < logMetrics.size(); i++) { - count = logMetrics.get(i); - if (count.getHost().equals(host) && - count.getLevel().getName().equals(logLevel.getName())) { - count.addCount(1); - found = true; - break; - } - } - } - - // There is no element in logMetrics with the same host and - // level as in the message, so create a new object and add it - // to the list. - if (! found) { - for (Level level : Arrays.asList(levels)) { - LevelCount levelCount; - if (level.getName().equals(logLevel.getName())) { - levelCount = new LevelCount(host, - level, - 1); - } else { - levelCount = new LevelCount(host, - level, - 0); - - } - logMetrics.add(levelCount); - } - } - return true; - } - - /** - * Create event count for each log level and report it. For now we - * add up the numbers for all host on each level and report that. - */ - private void sendEvents() { - Map<String, Long> levelCount = getMetricsPerLevel(); - for (Map.Entry<String, Long> entry : levelCount.entrySet()) { - String key = entry.getKey(); - Long count = entry.getValue(); - Event.count("log_message." + key.toLowerCase(), count.longValue()); - } - } - - public void flush() {} - - public void close() {} - - public String toString() { - return LogMetricsHandler.class.getName(); - } - - /** - * Returns the total number of log messages processed by this - * plugin. - * - * @return A count of log messages - */ - public long getMetricsCount() { - long count = 0; - for (LevelCount levelCount : logMetrics) { - count = count + levelCount.getCount(); - } - return count; - } - - /** - * Returns a Map of log level counts (level is key and count is - * value). - * - * @return A Map of log level counts - */ - public Map<String, Long> getMetricsPerLevel() { - Map<String, Long> levelCounts = new TreeMap<String, Long>(); - // Loop through all levels summing the count for all hosts. - for (Level level : Arrays.asList(levels)) { - String levelName = level.getName(); - long count = 0; - for (LevelCount levelCount : logMetrics) { - if (levelName.equals(levelCount.getLevel().getName())) { - count += levelCount.getCount(); - } - } - levelCounts.put(levelName, count); - } - return levelCounts; - } - - /** - * The LevelCount class represents the number (count) of log - * messages with the same log level for a host. - */ - private class LevelCount { - private final String host; - private final Level level; - private long count; - - LevelCount(String host, Level level, long count) { - this.host = host; - this.level = level; - this.count = count; - } - - LevelCount(String host, Level level) { - this(host, level, 0); - } - - Level getLevel() { - return level; - } - - String getHost() { - return host; - } - - long getCount() { - return count; - } - - void setCount(long count) { - this.count = count; - } - - void addCount(long add) { - count += add; - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Host=" + host + ", level = " + level.getName() + - ",count=" + count); - return sb.toString(); - } - } - - /** - * Implements a thread that sends events every EVENTINTERVAL - * seconds. - */ - private class EventGenerator implements Runnable { - public void run() { - // Send events every EVENTINTERVAL seconds - while (true) { - try { - Thread.sleep(EVENTINTERVAL * 1000); - } catch (InterruptedException e) { - log.log(Level.WARNING, e.getMessage()); - } - sendEvents(); - } - } - } -} diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java b/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java deleted file mode 100644 index 576af02c5fc..00000000000 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/* - * $Id$ - */ -package com.yahoo.logserver.handlers.logmetrics; - -import java.util.logging.Logger; - -import com.yahoo.logserver.Server; -import com.yahoo.plugin.Config; -import com.yahoo.plugin.Plugin; - - -public class LogMetricsPlugin implements Plugin { - private static final Logger log = Logger.getLogger(LogMetricsPlugin.class.getName()); - private LogMetricsHandler logMetricsHandler; - private final Server server = Server.getInstance(); - - public String getPluginName() { - return "logmetrics"; - } - - /** - * Initialize the logmetrics plugin - * - * @param config Plugin config object, keys used: - * <code>thread</code> - name of handler thread this plugin runs in - */ - public void initPlugin(Config config) { - if (logMetricsHandler != null) { - log.finer("LogMetricsPlugin doubly initialized"); - throw new IllegalStateException( - "plugin already initialized: " + getPluginName()); - } - String threadName = config.get("thread", getPluginName()); - logMetricsHandler = new LogMetricsHandler(); - server.registerLogHandler(logMetricsHandler, threadName); - } - - /** - * Shut down the logmetrics plugin. - */ - public void shutdownPlugin() { - if (logMetricsHandler == null) { - log.finer("LogMetricsPlugin shutdown before initialize"); - throw new IllegalStateException("plugin not initialized: " + - getPluginName()); - } - server.unregisterLogHandler(logMetricsHandler); - logMetricsHandler = null; - } -} diff --git a/logserver/src/test/java/com/yahoo/logserver/ServerTestCase.java b/logserver/src/test/java/com/yahoo/logserver/ServerTestCase.java index 6aaef3916d7..6a50fa61b8a 100644 --- a/logserver/src/test/java/com/yahoo/logserver/ServerTestCase.java +++ b/logserver/src/test/java/com/yahoo/logserver/ServerTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.logserver; import com.yahoo.log.LogSetup; import com.yahoo.logserver.handlers.LogHandler; -import com.yahoo.logserver.handlers.logmetrics.LogMetricsPlugin; import com.yahoo.logserver.test.LogDispatcherTestCase; import org.junit.Test; @@ -44,10 +43,7 @@ public class ServerTestCase { @Test public void testPluginLoaderClassLoading() { AbstractPluginLoader loader = new BuiltinPluginLoader(); - System.setProperty("logserver.logmetrics.enable", "false"); - loader.loadFromClass(LogMetricsPlugin.class); - System.setProperty("logserver.logmetrics.enable", "true"); - loader.loadFromClass(LogMetricsPlugin.class); // Hm, no way to verify it was loaded + loader.loadPlugins(); } } diff --git a/logserver/src/test/java/com/yahoo/logserver/handlers/logmetrics/test/LogMetricsTestCase.java b/logserver/src/test/java/com/yahoo/logserver/handlers/logmetrics/test/LogMetricsTestCase.java deleted file mode 100644 index d65d2a51476..00000000000 --- a/logserver/src/test/java/com/yahoo/logserver/handlers/logmetrics/test/LogMetricsTestCase.java +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.logserver.handlers.logmetrics.test; - -import java.util.Map; - -import com.yahoo.log.InvalidLogFormatException; -import com.yahoo.log.LogMessage; -import com.yahoo.logserver.handlers.logmetrics.LogMetricsHandler; -import com.yahoo.logserver.handlers.logmetrics.LogMetricsPlugin; -import com.yahoo.plugin.SystemPropertyConfig; - -import org.junit.*; - -import static org.junit.Assert.*; - -/** - * @author hmusum - */ -public class LogMetricsTestCase { - - // Some of the tests depend upon the number of messages for a - // host, log level etc. to succeed, so you may have update the - // tests if you change something in mStrings. config, debug and - // spam are filtered out and not handled. - private static final String[] mStrings = { - "1095159244.095\thostA\t1/2\tservice\tcomponent\tconfig\tpayload1", - "1095206399.000\thostA\t1/2\tservice\tcomponent\tinfo\tpayload2", - "1095206400.000\thostA\t1/2\tservice\tcomponent\tinfo\tpayload3", - "1095206401.000\thostA\t1/2\tservice\tcomponent\tinfo\tpayload4", - "1095206402.000\thostA\t1/2\tservice\tcomponent\twarning\tpayload5", - "1095206403.000\thostA\t1/2\tservice\tcomponent\terror\tpayload6", - "1095206404.000\thostB\t1/2\tservice\tcomponent\tinfo\tpayload7", - "1095206405.000\thostB\t1/2\tservice\tcomponent\tfatal\tpayload8", - "1095206406.000\thostB\t1/2\tservice\tcomponent\tdebug\tpayload9", - }; - - private static final LogMessage[] msg = new LogMessage[mStrings.length]; - - static { - try { - for (int i = 0; i < mStrings.length; i++) { - msg[i] = LogMessage.parseNativeFormat(mStrings[i]); - } - } catch (InvalidLogFormatException e) { - throw new RuntimeException(e); - } - } - - /** - * Log some messages to the handler and verify that they are - * counted by the handler and that the count for each level is - * correct. - */ - @Test - public void testLevelCountTotal() throws java.io.IOException, InvalidLogFormatException { - LogMetricsHandler a = new LogMetricsHandler(); - - for (LogMessage aMsg : msg) { - a.handle(aMsg); - } - - long count = a.getMetricsCount(); - a.close(); - // Not all messages are processes (debug and spam) - assertEquals(count, 7); - } - - - /** - * Log some messages to the handler and verify that they are - * counted by the handler and that the count for each level is - * correct (the count for each host is summed into one count for - * each level). - */ - @Test - public void testLevelCountAggregated() { - LogMetricsHandler a = new LogMetricsHandler(); - - for (LogMessage aMsg : msg) { - a.handle(aMsg); - } - - Map<String, Long> levelCount = a.getMetricsPerLevel(); - assertEquals(levelCount.entrySet().size(), 5); - for (Map.Entry<String, Long> entry : levelCount.entrySet()) { - String key = entry.getKey(); - switch (key) { - case "config" -> assertEquals(entry.getValue(), Long.valueOf(1)); - case "info" -> assertEquals(entry.getValue(), Long.valueOf(4)); - case "warning" -> assertEquals(entry.getValue(), Long.valueOf(1)); - case "severe" -> assertEquals(entry.getValue(), Long.valueOf(0)); - case "error" -> assertEquals(entry.getValue(), Long.valueOf(1)); - case "fatal" -> assertEquals(entry.getValue(), Long.valueOf(1)); - case "debug" -> assertEquals(entry.getValue(), Long.valueOf(0)); // always 0 - } - } - a.close(); - } - - @Test - public void testLogMetricsPlugin() { - LogMetricsPlugin lp = new LogMetricsPlugin(); - try { - lp.shutdownPlugin(); - fail("Shutdown before init didn't throw."); - } catch (Exception e) { - } - lp.initPlugin(new SystemPropertyConfig("test")); - try { - lp.initPlugin(new SystemPropertyConfig("test")); - fail("Multiple init didn't throw."); - } catch (Exception e) { - } - lp.shutdownPlugin(); - } - -} |