@Override public boolean isAvailable() { return !corePlugin.getElasticsearchUrls().isEmpty(); }
public boolean isElasticsearchAvailable() { return !corePlugin.getElasticsearchUrls().isEmpty() && elasticsearchAvailable.get(); }
public boolean isReportToElasticsearch() { return !getElasticsearchUrls().isEmpty() && reportingIntervalElasticsearch.getValue() > 0; }
@Before public void setUp() throws Exception { final CorePlugin corePlugin = mock(CorePlugin.class); final URL url = new URL("http://localhost:41234"); when(corePlugin.getElasticsearchUrl()).thenReturn(url); when(corePlugin.getElasticsearchUrls()).thenReturn(Collections.singletonList(url)); when(corePlugin.getThreadPoolQueueCapacityLimit()).thenReturn(10000); when(corePlugin.isInitialized()).thenReturn(TRUE); elasticsearchClient = new ElasticsearchClient(corePlugin, new HttpClient(), -1, Collections.emptyList()); }
@Override public void initializePlugin(StagemonitorPlugin.InitArguments initArguments) throws Exception { alertSender = new AlertSender(initArguments.getConfiguration()); CorePlugin corePlugin = initArguments.getPlugin(CorePlugin.class); if (!corePlugin.getElasticsearchUrls().isEmpty()) { incidentRepository = new ElasticsearchIncidentRepository(corePlugin.getElasticsearchClient()); } else { incidentRepository = new ConcurrentMapIncidentRepository(); } logger.info("Using {} for storing incidents.", incidentRepository.getClass().getSimpleName()); thresholdMonitoringReporter = ThresholdMonitoringReporter.forRegistry(initArguments.getMetricRegistry()) .alertingPlugin(this) .alertSender(alertSender) .incidentRepository(incidentRepository) .measurementSession(initArguments.getMeasurementSession()) .build(); thresholdMonitoringReporter.start(checkFrequency.getValue(), TimeUnit.SECONDS); SlaCheckCreatingClassPathScanner.onStart(initArguments.getMeasurementSession()); }
@Before public void setUp() throws Exception { configuration = mock(ConfigurationRegistry.class); CorePlugin corePlugin = mock(CorePlugin.class); TracingPlugin tracingPlugin = mock(TracingPlugin.class); this.servletPlugin = mock(ServletPlugin.class); when(configuration.getConfig(CorePlugin.class)).thenReturn(corePlugin); when(configuration.getConfig(TracingPlugin.class)).thenReturn(tracingPlugin); when(configuration.getConfig(ServletPlugin.class)).thenReturn(servletPlugin); when(tracingPlugin.getDefaultRateLimitSpansPerMinute()).thenReturn(1000000d); when(tracingPlugin.getOnlyReportSpansWithName()).thenReturn(Collections.emptyList()); final URL url = new URL("http://localhost:9200"); when(corePlugin.getElasticsearchUrl()).thenReturn(url); when(corePlugin.getElasticsearchUrls()).thenReturn(Collections.singletonList(url)); ElasticsearchClient elasticsearchClient = mock(ElasticsearchClient.class); when(elasticsearchClient.isElasticsearchAvailable()).thenReturn(true); when(corePlugin.getElasticsearchClient()).thenReturn(elasticsearchClient); when(corePlugin.getMetricRegistry()).thenReturn(new Metric2Registry()); when(servletPlugin.isHonorDoNotTrackHeader()).thenReturn(true); tracer = new SpanWrappingTracer(new MockTracer(), Arrays.asList( new SpanContextInformation.SpanContextSpanEventListener(), new SpanContextInformation.SpanFinalizer() ) ); GlobalTracerTestHelper.override(tracer); when(tracingPlugin.getTracer()).thenReturn(tracer); assertThat(tracer.scopeManager().active()).isNull(); }
doReturn(1000).when(corePlugin).getThreadPoolQueueCapacityLimit(); doReturn(new Metric2Registry()).when(corePlugin).getMetricRegistry(); doReturn(Collections.singletonList("http://mockhost:9200")).when(corePlugin).getElasticsearchUrls(); ElasticsearchClient elasticsearchClient = mock(ElasticsearchClient.class); doReturn(true).when(elasticsearchClient).isElasticsearchAvailable();
AbstractElasticsearchTest.corePlugin = mock(CorePlugin.class); when(corePlugin.getElasticsearchUrl()).thenReturn(elasticsearchUrl); when(corePlugin.getElasticsearchUrls()).thenReturn(Collections.singletonList(elasticsearchUrl)); when(corePlugin.getThreadPoolQueueCapacityLimit()).thenReturn(1000); elasticsearchClient = new ElasticsearchClient(corePlugin, new HttpClient(), -1, Collections.emptyList());
@Test public void testCycleElasticsearchUrlsEmptyString() throws Exception { CorePlugin corePlugin = ConfigurationRegistry.builder() .addOptionProvider(new CorePlugin()) .addConfigSource(new SimpleSource("test") .add("stagemonitor.reporting.elasticsearch.url", "")) .build() .getConfig(CorePlugin.class); assertThat(corePlugin.getElasticsearchUrls()).isEmpty(); }
private boolean isReportToElasticsearch() { final boolean urlAvailable = !corePlugin.getElasticsearchUrls().isEmpty(); final boolean logOnly = requestMonitorPlugin.isOnlyLogElasticsearchRequestTraceReports(); return (urlAvailable || logOnly); }
private void reportExternalRequestsToElasticsearch(final List<ExternalRequest> externalRequests) throws IOException { if (requestMonitorPlugin.isOnlyLogElasticsearchRequestTraceReports()) { final ByteArrayOutputStream os = new ByteArrayOutputStream(); writeExternalRequestsToOutputStream(os, externalRequests); externalRequestsLogger.info(new String(os.toByteArray(), Charset.forName("UTF-8"))); } else if (!corePlugin.getElasticsearchUrls().isEmpty()) { final String index = "stagemonitor-external-requests-" + StringUtils.getLogstashStyleDate(); elasticsearchClient.sendBulkAsync("/" + index + "/requests", new HttpClient.OutputStreamHandler() { @Override public void withHttpURLConnection(OutputStream os) throws IOException { writeExternalRequestsToOutputStream(os, externalRequests); } }); } }
@Override public void initializePlugin(StagemonitorPlugin.InitArguments initArguments) { final CorePlugin corePlugin = initArguments.getPlugin(CorePlugin.class); final ElasticsearchClient elasticsearchClient = corePlugin.getElasticsearchClient(); final GrafanaClient grafanaClient = corePlugin.getGrafanaClient(); final String requestsMappingJson = ElasticsearchClient.modifyIndexTemplate( requestIndexTemplate.getValue(), corePlugin.getMoveToColdNodesAfterDays(), corePlugin.getNumberOfReplicas(), corePlugin.getNumberOfShards()); elasticsearchClient.sendMappingTemplateAsync(requestsMappingJson, "stagemonitor-requests"); final String mappingJson = ElasticsearchClient.modifyIndexTemplate( externalRequestsIndexTemplate.getValue(), corePlugin.getMoveToColdNodesAfterDays(), corePlugin.getNumberOfReplicas(), corePlugin.getNumberOfShards()); elasticsearchClient.sendMappingTemplateAsync(mappingJson, "stagemonitor-external-requests"); if (corePlugin.isReportToGraphite()) { elasticsearchClient.sendGrafana1DashboardAsync("grafana/Grafana1GraphiteRequestDashboard.json"); } if (corePlugin.isReportToElasticsearch()) { elasticsearchClient.sendClassPathRessourceBulkAsync("kibana/RequestDashboard.bulk"); grafanaClient.sendGrafanaDashboardAsync("grafana/ElasticsearchRequestDashboard.json"); grafanaClient.sendGrafanaDashboardAsync("grafana/ElasticsearchExternalRequestsDashboard.json"); } if (!corePlugin.getElasticsearchUrls().isEmpty()) { elasticsearchClient.sendClassPathRessourceBulkAsync("kibana/StagemonitorRequestsIndexPattern.bulk"); elasticsearchClient.sendClassPathRessourceBulkAsync("kibana/RequestAnalysis.bulk"); elasticsearchClient.sendClassPathRessourceBulkAsync("kibana/WebAnalytics.bulk"); elasticsearchClient.sendClassPathRessourceBulkAsync("kibana/ExternalRequests.bulk"); elasticsearchClient.scheduleIndexManagement("stagemonitor-requests-", corePlugin.getMoveToColdNodesAfterDays(), deleteRequestTracesAfterDays.getValue()); elasticsearchClient.scheduleIndexManagement("stagemonitor-external-requests-", corePlugin.getMoveToColdNodesAfterDays(), deleteRequestTracesAfterDays.getValue()); } }