Search in sources :

Example 6 with NodeConfig

use of org.apache.solr.core.NodeConfig in project lucene-solr by apache.

the class SolrSlf4jReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    LogWatcherConfig watcherCfg = new LogWatcherConfig(true, null, null, 100);
    LogWatcher watcher = LogWatcher.newRegisteredLogWatcher(watcherCfg, null);
    watcher.setThreshold("INFO");
    Path home = Paths.get(TEST_HOME());
    // define these properties, they are used in solrconfig.xml
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8");
    NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
    CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
    h.coreName = DEFAULT_TEST_CORENAME;
    SolrMetricManager metricManager = cc.getMetricManager();
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
    assertTrue(reporters.toString(), reporters.size() >= 2);
    SolrMetricReporter reporter = reporters.get("test1");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrSlf4jReporter);
    reporter = reporters.get("test2");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrSlf4jReporter);
    watcher.reset();
    Thread.sleep(5000);
    SolrDocumentList history = watcher.getHistory(-1, null);
    // dot-separated names are treated like class names and collapsed
    // in regular log output, but here we get the full name
    assertTrue(history.stream().filter(d -> "solr.node".equals(d.getFirstValue("logger"))).count() > 0);
    assertTrue(history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() > 0);
}
Also used : LogWatcherConfig(org.apache.solr.logging.LogWatcherConfig) Path(java.nio.file.Path) LogWatcherConfig(org.apache.solr.logging.LogWatcherConfig) SolrDocumentList(org.apache.solr.common.SolrDocumentList) TestHarness(org.apache.solr.util.TestHarness) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) CoreContainer(org.apache.solr.core.CoreContainer) SolrTestCaseJ4(org.apache.solr.SolrTestCaseJ4) SolrXmlConfig(org.apache.solr.core.SolrXmlConfig) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) Paths(java.nio.file.Paths) Map(java.util.Map) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) LogWatcher(org.apache.solr.logging.LogWatcher) NodeConfig(org.apache.solr.core.NodeConfig) Path(java.nio.file.Path) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) SolrDocumentList(org.apache.solr.common.SolrDocumentList) LogWatcher(org.apache.solr.logging.LogWatcher) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) TestHarness(org.apache.solr.util.TestHarness) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) NodeConfig(org.apache.solr.core.NodeConfig) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 7 with NodeConfig

use of org.apache.solr.core.NodeConfig in project lucene-solr by apache.

the class MetricsConfigTest method testCustomReservoir.

@Test
public void testCustomReservoir() throws Exception {
    System.setProperty("timer.reservoir", UniformReservoir.class.getName());
    System.setProperty("histogram.size", "2048");
    System.setProperty("histogram.window", "600");
    System.setProperty("histogram.reservoir", SlidingTimeWindowReservoir.class.getName());
    NodeConfig cfg = loadNodeConfig();
    SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig());
    assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
    assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
    assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
    assertTrue(mgr.getHistogramSupplier() instanceof MetricSuppliers.DefaultHistogramSupplier);
    Reservoir rsv = ((MetricSuppliers.DefaultTimerSupplier) mgr.getTimerSupplier()).getReservoir();
    assertTrue(rsv instanceof UniformReservoir);
    rsv = ((MetricSuppliers.DefaultHistogramSupplier) mgr.getHistogramSupplier()).getReservoir();
    assertTrue(rsv instanceof SlidingTimeWindowReservoir);
}
Also used : SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) Reservoir(com.codahale.metrics.Reservoir) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) NodeConfig(org.apache.solr.core.NodeConfig) Test(org.junit.Test)

Example 8 with NodeConfig

use of org.apache.solr.core.NodeConfig in project lucene-solr by apache.

the class JvmMetricsTest method testHiddenSysProps.

@Test
public void testHiddenSysProps() throws Exception {
    Path home = Paths.get(TEST_HOME());
    SolrResourceLoader loader = new SolrResourceLoader(home);
    // default config
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr.xml").toFile(), "UTF-8");
    NodeConfig config = SolrXmlConfig.fromString(loader, solrXml);
    NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS.forEach(s -> {
        assertTrue(s, config.getMetricsConfig().getHiddenSysProps().contains(s));
    });
    // custom config
    solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-hiddensysprops.xml").toFile(), "UTF-8");
    NodeConfig config2 = SolrXmlConfig.fromString(loader, solrXml);
    Arrays.asList("foo", "bar", "baz").forEach(s -> {
        assertTrue(s, config2.getMetricsConfig().getHiddenSysProps().contains(s));
    });
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) NodeConfig(org.apache.solr.core.NodeConfig) Test(org.junit.Test)

Example 9 with NodeConfig

use of org.apache.solr.core.NodeConfig in project lucene-solr by apache.

the class MetricsConfigTest method testDefaults.

@Test
public void testDefaults() throws Exception {
    NodeConfig cfg = loadNodeConfig();
    SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig());
    assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
    assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
    assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
    assertTrue(mgr.getHistogramSupplier() instanceof MetricSuppliers.DefaultHistogramSupplier);
    Clock clk = ((MetricSuppliers.DefaultTimerSupplier) mgr.getTimerSupplier()).clk;
    assertTrue(clk instanceof Clock.UserTimeClock);
    Reservoir rsv = ((MetricSuppliers.DefaultTimerSupplier) mgr.getTimerSupplier()).getReservoir();
    assertTrue(rsv instanceof ExponentiallyDecayingReservoir);
}
Also used : ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) Reservoir(com.codahale.metrics.Reservoir) ExponentiallyDecayingReservoir(com.codahale.metrics.ExponentiallyDecayingReservoir) UniformReservoir(com.codahale.metrics.UniformReservoir) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Clock(com.codahale.metrics.Clock) NodeConfig(org.apache.solr.core.NodeConfig) Test(org.junit.Test)

Example 10 with NodeConfig

use of org.apache.solr.core.NodeConfig in project lucene-solr by apache.

the class SolrMetricsIntegrationTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    Path home = Paths.get(TEST_HOME());
    // define these properties, they are used in solrconfig.xml
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-metricreporter.xml").toFile(), "UTF-8");
    NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
    cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
    h.coreName = DEFAULT_TEST_CORENAME;
    jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0;
    metricManager = cc.getMetricManager();
    tag = h.getCore().getCoreMetricManager().getTag();
    // initially there are more reporters, because two of them are added via a matching collection name
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.core." + DEFAULT_TEST_CORENAME);
    assertEquals(INITIAL_REPORTERS.length + jmxReporter, reporters.size());
    for (String r : INITIAL_REPORTERS) {
        assertTagged(reporters, r);
    }
    // test rename operation
    cc.rename(DEFAULT_TEST_CORENAME, CORE_NAME);
    h.coreName = CORE_NAME;
    cfg = cc.getConfig();
    PluginInfo[] plugins = cfg.getMetricsConfig().getMetricReporters();
    assertNotNull(plugins);
    assertEquals(10 + jmxReporter, plugins.length);
    reporters = metricManager.getReporters("solr.node");
    assertEquals(4 + jmxReporter, reporters.size());
    assertTrue("Reporter '" + REPORTER_NAMES[0] + "' missing in solr.node", reporters.containsKey(REPORTER_NAMES[0]));
    assertTrue("Reporter '" + UNIVERSAL + "' missing in solr.node", reporters.containsKey(UNIVERSAL));
    assertTrue("Reporter '" + MULTIGROUP + "' missing in solr.node", reporters.containsKey(MULTIGROUP));
    assertTrue("Reporter '" + MULTIREGISTRY + "' missing in solr.node", reporters.containsKey(MULTIREGISTRY));
    SolrMetricReporter reporter = reporters.get(REPORTER_NAMES[0]);
    assertTrue("Reporter " + reporter + " is not an instance of " + MockMetricReporter.class.getName(), reporter instanceof MockMetricReporter);
    reporter = reporters.get(UNIVERSAL);
    assertTrue("Reporter " + reporter + " is not an instance of " + MockMetricReporter.class.getName(), reporter instanceof MockMetricReporter);
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) PluginInfo(org.apache.solr.core.PluginInfo) MockMetricReporter(org.apache.solr.metrics.reporters.MockMetricReporter) NodeConfig(org.apache.solr.core.NodeConfig) Before(org.junit.Before)

Aggregations

NodeConfig (org.apache.solr.core.NodeConfig)13 Test (org.junit.Test)8 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Path (java.nio.file.Path)6 CoreContainer (org.apache.solr.core.CoreContainer)5 PluginInfo (org.apache.solr.core.PluginInfo)3 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)3 SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)3 TestHarness (org.apache.solr.util.TestHarness)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Reservoir (com.codahale.metrics.Reservoir)2 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)2 UniformReservoir (com.codahale.metrics.UniformReservoir)2 Clock (com.codahale.metrics.Clock)1 GMetric (info.ganglia.gmetric4j.gmetric.GMetric)1 GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1