Browse Source

Move metrics package to org.springframework.core

See gh-24878
pull/25487/head
Juergen Hoeller 6 years ago
parent
commit
adce6593af
  1. 6
      spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
  2. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
  3. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  4. 4
      spring-context/src/main/java/org/springframework/context/ApplicationStartupAware.java
  5. 8
      spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java
  6. 2
      spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java
  7. 4
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java
  8. 4
      spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java
  9. 4
      spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
  10. 4
      spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java
  11. 4
      spring-core/src/main/java/org/springframework/core/metrics/ApplicationStartup.java
  12. 5
      spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java
  13. 21
      spring-core/src/main/java/org/springframework/core/metrics/StartupStep.java
  14. 10
      spring-core/src/main/java/org/springframework/core/metrics/jfr/FlightRecorderApplicationStartup.java
  15. 8
      spring-core/src/main/java/org/springframework/core/metrics/jfr/FlightRecorderStartupEvent.java
  16. 12
      spring-core/src/main/java/org/springframework/core/metrics/jfr/FlightRecorderStartupStep.java
  17. 2
      spring-core/src/main/java/org/springframework/core/metrics/jfr/package-info.java
  18. 2
      spring-core/src/main/java/org/springframework/core/metrics/package-info.java

6
spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java

@ -26,8 +26,8 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -26,8 +26,8 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.lang.Nullable;
import org.springframework.util.StringValueResolver;
@ -281,13 +281,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single @@ -281,13 +281,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* Set the {@code ApplicationStartup} for this bean factory.
* <p>This allows the application context to record metrics during application startup.
* @param applicationStartup the new application startup
* @since 5.3.0
* @since 5.3
*/
void setApplicationStartup(ApplicationStartup applicationStartup);
/**
* Return the {@code ApplicationStartup} for this bean factory.
* @since 5.3.0
* @since 5.3
*/
ApplicationStartup getApplicationStartup();

4
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

@ -69,14 +69,14 @@ import org.springframework.beans.factory.config.DestructionAwareBeanPostProcesso @@ -69,14 +69,14 @@ import org.springframework.beans.factory.config.DestructionAwareBeanPostProcesso
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.config.Scope;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.core.AttributeAccessor;
import org.springframework.core.DecoratingClassLoader;
import org.springframework.core.NamedThreadLocal;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.log.LogMessage;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

2
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -71,13 +71,13 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -71,13 +71,13 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.config.NamedBeanHolder;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.core.OrderComparator;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.core.log.LogMessage;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

4
spring-context/src/main/java/org/springframework/context/ApplicationStartupAware.java

@ -17,14 +17,14 @@ @@ -17,14 +17,14 @@
package org.springframework.context;
import org.springframework.beans.factory.Aware;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.core.metrics.ApplicationStartup;
/**
* Interface to be implemented by any object that wishes to be notified
* of the {@link ApplicationStartup} that it runs with.
*
* @author Brian Clozel
* @since 5.3.0
* @since 5.3
* @see ApplicationContextAware
*/
public interface ApplicationStartupAware extends Aware {

8
spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java

@ -21,10 +21,10 @@ import java.io.Closeable; @@ -21,10 +21,10 @@ import java.io.Closeable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ProtocolResolver;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.lang.Nullable;
/**
@ -90,7 +90,7 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life @@ -90,7 +90,7 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
/**
* Name of the {@link ApplicationStartup} bean in the factory.
* @since 5.3.0
* @since 5.3
*/
String APPLICATION_STARTUP_BEAN_NAME = "applicationStartup";
@ -139,13 +139,13 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life @@ -139,13 +139,13 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
* <p>This allows the application context to record metrics
* during startup.
* @param applicationStartup the new context event factory
* @since 5.3.0
* @since 5.3
*/
void setApplicationStartup(ApplicationStartup applicationStartup);
/**
* Return the {@link ApplicationStartup} for this application context.
* @since 5.3.0
* @since 5.3
*/
ApplicationStartup getApplicationStartup();

2
spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java

@ -22,9 +22,9 @@ import java.util.function.Supplier; @@ -22,9 +22,9 @@ import java.util.function.Supplier;
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

4
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -48,8 +48,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -48,8 +48,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.context.ApplicationStartupAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
@ -60,6 +58,8 @@ import org.springframework.core.env.Environment; @@ -60,6 +58,8 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;

4
spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java

@ -22,11 +22,11 @@ import org.apache.commons.logging.Log; @@ -22,11 +22,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.ResolvableType;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.ErrorHandler;

4
spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -39,8 +39,6 @@ import org.springframework.beans.factory.ObjectProvider; @@ -39,8 +39,6 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.beans.support.ResourceEditorRegistrar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@ -80,6 +78,8 @@ import org.springframework.core.io.Resource; @@ -80,6 +78,8 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

4
spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java

@ -36,11 +36,11 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProce @@ -36,11 +36,11 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProce
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
/**

4
spring-beans/src/main/java/org/springframework/beans/metrics/ApplicationStartup.java → spring-core/src/main/java/org/springframework/core/metrics/ApplicationStartup.java

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.beans.metrics;
package org.springframework.core.metrics;
/**
* Instruments the application startup phase using {@link StartupStep steps}.
@ -23,7 +23,7 @@ package org.springframework.beans.metrics; @@ -23,7 +23,7 @@ package org.springframework.beans.metrics;
* or their processing time.
*
* @author Brian Clozel
* @since 5.3.0
* @since 5.3
*/
public interface ApplicationStartup {

5
spring-beans/src/main/java/org/springframework/beans/metrics/DefaultApplicationStartup.java → spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.beans.metrics;
package org.springframework.core.metrics;
import java.util.Collections;
import java.util.Iterator;
@ -22,6 +22,7 @@ import java.util.function.Supplier; @@ -22,6 +22,7 @@ import java.util.function.Supplier;
/**
* Default "no op" {@code ApplicationStartup} implementation.
*
* <p>This variant is designed for minimal overhead and does not record events.
*
* @author Brian Clozel
@ -33,6 +34,7 @@ class DefaultApplicationStartup implements ApplicationStartup { @@ -33,6 +34,7 @@ class DefaultApplicationStartup implements ApplicationStartup {
return new DefaultStartupStep();
}
static class DefaultStartupStep implements StartupStep {
boolean recorded = false;
@ -80,6 +82,7 @@ class DefaultApplicationStartup implements ApplicationStartup { @@ -80,6 +82,7 @@ class DefaultApplicationStartup implements ApplicationStartup {
this.recorded = true;
}
static class DefaultTags implements StartupStep.Tags {
@Override

21
spring-beans/src/main/java/org/springframework/beans/metrics/StartupStep.java → spring-core/src/main/java/org/springframework/core/metrics/StartupStep.java

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.beans.metrics;
package org.springframework.core.metrics;
import java.util.function.Supplier;
@ -22,17 +22,19 @@ import org.springframework.lang.Nullable; @@ -22,17 +22,19 @@ import org.springframework.lang.Nullable;
/**
* Step recording metrics about a particular phase or action happening during the {@link ApplicationStartup}.
*
* <p>The lifecycle of a {@code StartupStep} goes as follows:
* <ol>
* <li>the step is created and starts by calling {@link ApplicationStartup#start(String) the application startup}
* and is assigned a unique {@link StartupStep#getId() id}.
* <li>we can then attach information with {@link Tags} during processing
* <li>we then need to mark the {@link #end()} of the step
* <li>the step is created and starts by calling {@link ApplicationStartup#start(String) the application startup}
* and is assigned a unique {@link StartupStep#getId() id}.
* <li>we can then attach information with {@link Tags} during processing
* <li>we then need to mark the {@link #end()} of the step
* </ol>
*
* <p>Implementations can track the "execution time" or other metrics for steps.
*
* @author Brian Clozel
* @since 5.3.0
* @since 5.3
*/
public interface StartupStep {
@ -51,7 +53,8 @@ public interface StartupStep { @@ -51,7 +53,8 @@ public interface StartupStep {
/**
* Return, if available, the id of the parent step.
* <p>The parent step is the step that was started the most recently when the current step was created.
* <p>The parent step is the step that was started the most recently
* when the current step was created.
*/
@Nullable
Long getParentId();
@ -81,13 +84,14 @@ public interface StartupStep { @@ -81,13 +84,14 @@ public interface StartupStep {
*/
void end();
/**
* Mutable collection of {@link Tag}.
*/
interface Tags extends Iterable<Tag> {
}
/**
* Simple key/value association for storing step metadata.
*/
@ -103,4 +107,5 @@ public interface StartupStep { @@ -103,4 +107,5 @@ public interface StartupStep {
*/
String getValue();
}
}

10
spring-beans/src/main/java/org/springframework/beans/metrics/jfr/FlightRecorderApplicationStartup.java → spring-core/src/main/java/org/springframework/core/metrics/jfr/FlightRecorderApplicationStartup.java

@ -14,13 +14,13 @@ @@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.beans.metrics.jfr;
package org.springframework.core.metrics.jfr;
import java.util.ArrayDeque;
import java.util.Deque;
import org.springframework.beans.metrics.ApplicationStartup;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.core.metrics.StartupStep;
/**
* {@link ApplicationStartup} implementation for the Java Flight Recorder.
@ -38,16 +38,18 @@ public class FlightRecorderApplicationStartup implements ApplicationStartup { @@ -38,16 +38,18 @@ public class FlightRecorderApplicationStartup implements ApplicationStartup {
private final Deque<Long> currentSteps;
public FlightRecorderApplicationStartup() {
this.currentSequenceId = 0;
this.currentSteps = new ArrayDeque<>();
this.currentSteps.offerFirst(0L);
}
@Override
public StartupStep start(String name) {
FlightRecorderStartupStep step = new FlightRecorderStartupStep(++this.currentSequenceId, name,
this.currentSteps.peekFirst(), committedStep -> this.currentSteps.removeFirst());
this.currentSteps.getFirst(), committedStep -> this.currentSteps.removeFirst());
this.currentSteps.offerFirst(this.currentSequenceId);
return step;
}

8
spring-beans/src/main/java/org/springframework/beans/metrics/jfr/FlightRecorderStartupEvent.java → spring-core/src/main/java/org/springframework/core/metrics/jfr/FlightRecorderStartupEvent.java

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.beans.metrics.jfr;
package org.springframework.core.metrics.jfr;
import jdk.jfr.Category;
import jdk.jfr.Description;
@ -24,10 +24,12 @@ import jdk.jfr.Label; @@ -24,10 +24,12 @@ import jdk.jfr.Label;
/**
* {@link Event} extension for recording {@link FlightRecorderStartupStep}
* in Java Flight Recorder.
* <p>{@link org.springframework.beans.metrics.StartupStep.Tags} are serialized as a single {@code String},
* since Flight Recorder events do not support complex types.
*
* <p>{@link org.springframework.core.metrics.StartupStep.Tags} are serialized
* as a single {@code String}, since Flight Recorder events do not support complex types.
*
* @author Brian Clozel
* @since 5.3
*/
@Category("Spring Application")
@Label("Startup Step")

12
spring-beans/src/main/java/org/springframework/beans/metrics/jfr/FlightRecorderStartupStep.java → spring-core/src/main/java/org/springframework/core/metrics/jfr/FlightRecorderStartupStep.java

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.beans.metrics.jfr;
package org.springframework.core.metrics.jfr;
import java.util.Iterator;
import java.util.function.Consumer;
@ -22,7 +22,7 @@ import java.util.function.Supplier; @@ -22,7 +22,7 @@ import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.metrics.StartupStep;
import org.springframework.core.metrics.StartupStep;
/**
* {@link StartupStep} implementation for the Java Flight Recorder.
@ -39,13 +39,16 @@ class FlightRecorderStartupStep implements StartupStep { @@ -39,13 +39,16 @@ class FlightRecorderStartupStep implements StartupStep {
private final Consumer<FlightRecorderStartupStep> recordingCallback;
public FlightRecorderStartupStep(long id, String name, long parentId,
Consumer<FlightRecorderStartupStep> recordingCallback) {
this.event = new FlightRecorderStartupEvent(id, name, parentId);
this.event.begin();
this.recordingCallback = recordingCallback;
}
@Override
public String getName() {
return this.event.name;
@ -96,6 +99,7 @@ class FlightRecorderStartupStep implements StartupStep { @@ -96,6 +99,7 @@ class FlightRecorderStartupStep implements StartupStep {
return this.event;
}
static class FlightRecorderTags implements Tags {
private Tag[] tags = new Tag[0];
@ -135,11 +139,10 @@ class FlightRecorderStartupStep implements StartupStep { @@ -135,11 +139,10 @@ class FlightRecorderStartupStep implements StartupStep {
public void remove() {
throw new UnsupportedOperationException("tags are append only");
}
}
}
static class FlightRecorderTag implements Tag {
private final String key;
@ -160,7 +163,6 @@ class FlightRecorderStartupStep implements StartupStep { @@ -160,7 +163,6 @@ class FlightRecorderStartupStep implements StartupStep {
public String getValue() {
return this.value;
}
}
}

2
spring-beans/src/main/java/org/springframework/beans/metrics/jfr/package-info.java → spring-core/src/main/java/org/springframework/core/metrics/jfr/package-info.java

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
*/
@NonNullApi
@NonNullFields
package org.springframework.beans.metrics.jfr;
package org.springframework.core.metrics.jfr;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

2
spring-beans/src/main/java/org/springframework/beans/metrics/package-info.java → spring-core/src/main/java/org/springframework/core/metrics/package-info.java

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
*/
@NonNullApi
@NonNullFields
package org.springframework.beans.metrics;
package org.springframework.core.metrics;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
Loading…
Cancel
Save