public Incident sendTestAlert(Subscription subscription, CheckResult.Status status) { Check check = new Check(); check.setName("Test Check"); check.setApplication("testApp"); check.setTarget(name("test").build()); check.getWarn().add(new Threshold("mean", Threshold.Operator.GREATER_EQUAL, 1)); Incident testIncident = new Incident(check, new MeasurementSession("testApp", "testHost", "testInstance"), Arrays.asList(new CheckResult("test", 10, status))); tryAlert(testIncident, subscription, alerterByType.get(subscription.getAlerterType())); return testIncident; }
@Before public void setUp() throws Exception { registry = new Metric2Registry(); final ConfigurationRegistry configuration = Mockito.mock(ConfigurationRegistry.class); final CorePlugin corePlugin = mock(CorePlugin.class); when(corePlugin.isReportToJMX()).thenReturn(true); when(configuration.getConfig(CorePlugin.class)).thenReturn(corePlugin); new CorePlugin(mock(ElasticsearchClient.class)).registerReporters(registry, configuration, new MeasurementSession("JmxReportingTest", "test", "test")); }
@Test public void testDisabledPlugin() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(true); when(corePlugin.getDisabledPlugins()).thenReturn(Collections.singletonList("TestExceptionPlugin")); Stagemonitor.reset(new MeasurementSession("StagemonitorTest", "testHost", "testInstance")); assertThat(healthCheckRegistry.runHealthCheck("TestPlugin").isHealthy()).isTrue(); assertThat(healthCheckRegistry.runHealthCheck("TestExceptionPlugin").isHealthy()).isFalse(); assertThat(healthCheckRegistry.runHealthCheck("TestExceptionPlugin").getMessage()).isEqualTo("disabled via configuration"); }
@Test public void testMDCStagemonitorDeactivated() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(false); when(corePlugin.getMeasurementSession()) .thenReturn(new MeasurementSession("MDCSpanEventListenerTest", "testHost", null)); mdcSpanInterceptor.onStart(spanWrapper); assertNull(MDC.getCopyOfContextMap()); }
@Test public void testNotInitialized() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(true); final MeasurementSession measurementSession = new MeasurementSession(null, "testHost", "testInstance"); Stagemonitor.reset(measurementSession); assertFalse(Stagemonitor.isStarted()); }
@BeforeClass public static void attachProfiler() throws Exception { GlobalTracerTestHelper.resetGlobalTracer(); Stagemonitor.reset(new MeasurementSession("ConnectionMonitoringTransformerTest", "test", "test")); }
@Before public void setUp() throws Exception { alertingPlugin = mock(AlertingPlugin.class); ConcurrentMapIncidentRepository incidentRepository = new ConcurrentMapIncidentRepository(); incident = new Incident(ThresholdMonitoringReporterTest.createCheckCheckingMean(1, 5), new MeasurementSession("testApp", "testHost2", "testInstance"), Arrays.asList(new CheckResult("test", 10, CheckResult.Status.CRITICAL), new CheckResult("test", 10, CheckResult.Status.ERROR))); incidentRepository.createIncident(incident); when(alertingPlugin.getIncidentRepository()).thenReturn(incidentRepository); incidentServlet = new IncidentServlet(alertingPlugin); }
public static Incident createIncidentWithVersion(String checkId, int version) { Incident incident = new Incident(ThresholdMonitoringReporterTest.createCheckCheckingMean(1, 5), new MeasurementSession("testApp", "testHost2", "testInstance"), Arrays.asList(new CheckResult("test", 10, CheckResult.Status.CRITICAL), new CheckResult("test", 10, CheckResult.Status.ERROR))); incident.setVersion(version); incident.setCheckId(checkId); return incident; }
@Test public void testCreateAndGetIncindent() throws Exception { final Check check = ThresholdMonitoringReporterTest.createCheckCheckingMean(1, 5); check.setId("test 1"); final Incident incident = new Incident(check, new MeasurementSession("testApp", "testHost2", "testInstance"), Arrays.asList(new CheckResult("test", 10, CheckResult.Status.CRITICAL), new CheckResult("test", 10, CheckResult.Status.ERROR))); elasticsearchIncidentRepository.createIncident(incident); refresh(); assertThat(elasticsearchIncidentRepository.getIncidentByCheckId("test 1")).isEqualTo(incident); } }
@Before public void before() throws Exception { Stagemonitor.reset(new MeasurementSession("JaxRsRequestNameDeterminerTransformerTest", "testHost", "testInstance")); registry.removeMatching(Metric2Filter.ALL); when(configuration.getConfig(TracingPlugin.class)).thenReturn(tracingPlugin);
@Test public void testIsRoot() throws Exception { final StagemonitorPlugin.InitArguments initArguments = mock(StagemonitorPlugin.InitArguments.class); when(initArguments.getMeasurementSession()).thenReturn( new MeasurementSession("JaegerTracerFactoryTest", "test", "test")); final JaegerTracerFactory jaegerTracerFactory = new JaegerTracerFactory(); final Tracer tracer = jaegerTracerFactory.getTracer(initArguments); try (final Scope rootSpan = tracer.buildSpan("foo").startActive(true)) { try (final Scope childSpan = tracer.buildSpan("bar").startActive(true)) { assertThat(jaegerTracerFactory.isRoot(rootSpan.span())).isTrue(); assertThat(jaegerTracerFactory.isRoot(childSpan.span())).isFalse(); } } } }
/** * Should only be used outside of this class by the internal unit tests */ @Deprecated public static void reset(MeasurementSession measurementSession) { started = false; disabled = false; if (configuration == null) { reloadPluginsAndConfiguration(); } if (measurementSession == null) { CorePlugin corePlugin = getPlugin(CorePlugin.class); measurementSession = new MeasurementSession(corePlugin.getApplicationName(), corePlugin.getHostName(), corePlugin.getInstanceName()); } onShutdownActions.add(AgentAttacher.performRuntimeAttachment()); startMonitoring(measurementSession); healthCheckRegistry.register("Startup", new HealthCheck() { @Override protected Result check() throws Exception { if (started) { return Result.healthy(); } else { return Result.unhealthy("stagemonitor is not started"); } } }); logStatus(); new ConfigurationLogger().logConfiguration(configuration); }
@Test public void testMdc() throws Exception { Stagemonitor.reset(new MeasurementSession("MDCSpanEventListenerTest", "testHost", "testInstance")); when(corePlugin.getMeasurementSession()) .thenReturn(new MeasurementSession("MDCSpanEventListenerTest", "testHost", "testInstance")); mdcSpanInterceptor.onStart(spanWrapper); assertNotNull(MDC.get("spanId")); assertNotNull(MDC.get("traceId")); assertNull(MDC.get("parentId")); mdcSpanInterceptor.onFinish(spanWrapper, null, 0); assertThat(MDC.getCopyOfContextMap()).isEmpty(); }
TagRecordingSpanEventListener.asList(tags), samplePriorityDeterminingSpanInterceptor, reportingSpanEventListener); when(corePlugin.getMeasurementSession()).thenReturn(new MeasurementSession(getClass().getSimpleName(), "test", "test")); when(tracingPlugin.getTracer()).then((invocation) -> { if (corePlugin.isStagemonitorActive()) {
@Test public void testStartMonitoring() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(true); Stagemonitor.setConfiguration(configuration); Stagemonitor.reset(); final MeasurementSession measurementSession = new MeasurementSession("StagemonitorTest", "testHost", "testInstance"); Stagemonitor.reset(measurementSession); assertTrue(Stagemonitor.isStarted()); assertTrue(Stagemonitor.getMeasurementSession().isInitialized()); assertSame(measurementSession, Stagemonitor.getMeasurementSession()); assertThat(healthCheckRegistry.runHealthCheck("TestPlugin").isHealthy()).isTrue(); assertThat(healthCheckRegistry.runHealthCheck("TestExceptionPlugin").isHealthy()).isFalse(); }
@Test public void testStartMonitoringNotActive() throws Exception { when(corePlugin.isStagemonitorActive()).thenReturn(false); final MeasurementSession measurementSession = new MeasurementSession("StagemonitorTest", "testHost", "testInstance"); Stagemonitor.reset(measurementSession); assertTrue(Stagemonitor.isDisabled()); assertFalse(Stagemonitor.isStarted()); assertTrue(Stagemonitor.getMeasurementSession().isInitialized()); assertThat(healthCheckRegistry.getNames()).doesNotContain("TestPlugin", "TestExceptionPlugin"); }
when(alertingPlugin.getChecks()).thenReturn(Collections.singletonMap(check.getId(), check)); incidentRepository.createIncident( new Incident(check, new MeasurementSession("testApp", "testHost2", "testInstance"), Arrays.asList(new CheckResult("test", 10, CheckResult.Status.CRITICAL))));
@Test public void testMdcStagemonitorNotStarted() throws Exception { final MeasurementSession measurementSession = new MeasurementSession("MDCSpanEventListenerTest", "testHost", null); Stagemonitor.reset(measurementSession); when(corePlugin.getMeasurementSession()).thenReturn(measurementSession); mdcSpanInterceptor.onStart(spanWrapper); assertEquals("testHost", MDC.get("host")); assertEquals("MDCSpanEventListenerTest", MDC.get("application")); assertNull(MDC.get("instance")); assertNull(MDC.get("spanId")); assertNull(MDC.get("traceId")); assertNull(MDC.get("parentId")); mdcSpanInterceptor.onFinish(spanWrapper, null, 0); }
@Before public void before() throws Exception { GlobalTracerTestHelper.resetGlobalTracer(); testClass = new TestSubClass(); metricRegistry = Stagemonitor.getMetric2Registry(); testClassLevelAnnotationClass = new TestClassLevelAnnotationClass(); metricRegistry.removeMatching(Metric2Filter.ALL); Stagemonitor.reset(new MeasurementSession("TracedTransformerTest", "test", "test")); spanCapturingReporter = new SpanCapturingReporter(); tags = new HashMap<>(); Stagemonitor.getPlugin(TracingPlugin.class).addSpanEventListenerFactory(new TagRecordingSpanEventListener(tags)); Stagemonitor.getPlugin(TracingPlugin.class).addReporter(spanCapturingReporter); assertThat(GlobalTracer.get().scopeManager().active()).isNull(); }
@Test public void testToJson() throws Exception { MeasurementSession measurementSession = new MeasurementSession("app", "host", "instance"); final MeasurementSession jsonSession = JsonUtils.getMapper().readValue(JsonUtils.toJson(measurementSession), MeasurementSession.class); assertEquals(measurementSession.getApplicationName(), jsonSession.getApplicationName()); assertEquals(measurementSession.getHostName(), jsonSession.getHostName()); assertEquals(measurementSession.getInstanceName(), jsonSession.getInstanceName()); assertEquals(measurementSession.getInstanceName(), jsonSession.getInstanceName()); assertEquals(measurementSession.getId(), jsonSession.getId()); assertEquals(measurementSession.getStart(), jsonSession.getStart()); } }