Move metrics package to org.springframework.core

See gh-24878
This commit is contained in:
Juergen Hoeller 2020-07-28 11:28:10 +02:00
parent 9f211de113
commit adce6593af
18 changed files with 60 additions and 46 deletions

View File

@ -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
* 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();

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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
/**
* 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
* <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();

View File

@ -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;

View File

@ -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;
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;

View File

@ -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;

View File

@ -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;
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;

View File

@ -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;
/**

View File

@ -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;
* or their processing time.
*
* @author Brian Clozel
* @since 5.3.0
* @since 5.3
*/
public interface ApplicationStartup {

View File

@ -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;
/**
* 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 {
return new DefaultStartupStep();
}
static class DefaultStartupStep implements StartupStep {
boolean recorded = false;
@ -80,6 +82,7 @@ class DefaultApplicationStartup implements ApplicationStartup {
this.recorded = true;
}
static class DefaultTags implements StartupStep.Tags {
@Override

View File

@ -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;
/**
* 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 {
/**
* 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 {
*/
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 {
*/
String getValue();
}
}

View File

@ -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 {
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;
}

View File

@ -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;
/**
* {@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")

View File

@ -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;
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 {
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 {
return this.event;
}
static class FlightRecorderTags implements Tags {
private Tag[] tags = new Tag[0];
@ -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 {
public String getValue() {
return this.value;
}
}
}

View File

@ -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;

View File

@ -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;