use of org.springframework.boot.context.event.ApplicationStartedEvent in project pinpoint by naver.
the class EnvironmentLoggingListener method onApplicationEvent.
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
ApplicationEnvironmentPreparedEvent prepared = (ApplicationEnvironmentPreparedEvent) event;
ConfigurableEnvironment environment = prepared.getEnvironment();
logPropertySource(event, environment);
} else if (event instanceof ApplicationStartedEvent) {
ApplicationStartedEvent started = (ApplicationStartedEvent) event;
ConfigurableEnvironment environment = started.getApplicationContext().getEnvironment();
logPropertySource(event, environment);
} else if (event instanceof ApplicationFailedEvent) {
ApplicationFailedEvent failed = (ApplicationFailedEvent) event;
ConfigurableEnvironment environment = failed.getApplicationContext().getEnvironment();
logPropertySource(event, environment);
} else {
if (logger.isDebugEnabled()) {
logger.debug("ApplicationEvent:{}", event.getClass().getSimpleName());
}
}
}
use of org.springframework.boot.context.event.ApplicationStartedEvent in project spring-boot by spring-projects.
the class StartupTimeMetricsListenerTests method metricRecordedWithoutMainAppClassTag.
@Test
void metricRecordedWithoutMainAppClassTag() {
SpringApplication application = mock(SpringApplication.class);
this.listener.onApplicationEvent(new ApplicationStartedEvent(application, null, null, Duration.ofSeconds(2)));
TimeGauge applicationStartedGague = this.registry.find("application.started.time").timeGauge();
assertThat(applicationStartedGague).isNotNull();
assertThat(applicationStartedGague.getId().getTags()).isEmpty();
}
use of org.springframework.boot.context.event.ApplicationStartedEvent in project spring-boot by spring-projects.
the class StartupTimeMetricsListenerAutoConfigurationTests method startupTimeMetricsCanBeDisabled.
@Test
void startupTimeMetricsCanBeDisabled() {
this.contextRunner.withPropertyValues("management.metrics.enable.application.started.time:false", "management.metrics.enable.application.ready.time:false").run((context) -> {
context.publishEvent(new ApplicationStartedEvent(new SpringApplication(), null, context.getSourceApplicationContext(), Duration.ofMillis(2500)));
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), null, context.getSourceApplicationContext(), Duration.ofMillis(3000)));
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
assertThat(registry.find("application.started.time").timeGauge()).isNull();
assertThat(registry.find("application.ready.time").timeGauge()).isNull();
});
}
use of org.springframework.boot.context.event.ApplicationStartedEvent in project spring-boot by spring-projects.
the class StartupTimeMetricsListenerAutoConfigurationTests method startupTimeMetricsAreRecorded.
@Test
void startupTimeMetricsAreRecorded() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(StartupTimeMetricsListener.class);
SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
context.publishEvent(new ApplicationStartedEvent(new SpringApplication(), null, context.getSourceApplicationContext(), Duration.ofMillis(1500)));
TimeGauge startedTimeGage = registry.find("application.started.time").timeGauge();
assertThat(startedTimeGage).isNotNull();
assertThat(startedTimeGage.value(TimeUnit.MILLISECONDS)).isEqualTo(1500L);
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), null, context.getSourceApplicationContext(), Duration.ofMillis(2000)));
TimeGauge readyTimeGage = registry.find("application.ready.time").timeGauge();
assertThat(readyTimeGage).isNotNull();
assertThat(readyTimeGage.value(TimeUnit.MILLISECONDS)).isEqualTo(2000L);
});
}
use of org.springframework.boot.context.event.ApplicationStartedEvent in project spring-boot by spring-projects.
the class StartupTimeMetricsListenerTests method applicationStartedEvent.
private ApplicationStartedEvent applicationStartedEvent(Long startupTimeMs) {
SpringApplication application = mock(SpringApplication.class);
given(application.getMainApplicationClass()).willAnswer((invocation) -> TestMainApplication.class);
return new ApplicationStartedEvent(application, null, null, (startupTimeMs != null) ? Duration.ofMillis(startupTimeMs) : null);
}
Aggregations