Search in sources :

Example 1 with ApplicationStartedEvent

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());
        }
    }
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)

Example 2 with ApplicationStartedEvent

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();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) TimeGauge(io.micrometer.core.instrument.TimeGauge) Test(org.junit.jupiter.api.Test)

Example 3 with ApplicationStartedEvent

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();
    });
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationStartedEvent

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);
    });
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) TimeGauge(io.micrometer.core.instrument.TimeGauge) Test(org.junit.jupiter.api.Test)

Example 5 with ApplicationStartedEvent

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);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent)

Aggregations

ApplicationStartedEvent (org.springframework.boot.context.event.ApplicationStartedEvent)5 SpringApplication (org.springframework.boot.SpringApplication)4 Test (org.junit.jupiter.api.Test)3 TimeGauge (io.micrometer.core.instrument.TimeGauge)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)2 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)1 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1