When Elasticsearch starts up, plugins are loaded based on their inter-dependencies. The specific order used is sometimes useful to see. Currently though the actual order cannot be seen. Instead the modules and plugins are logged in name sorted order after all loading has occurred.

We should be more clear about what order the plugins are actually loaded in, though we do need to be careful as to not add too much noise. I suggest moving the "loaded xxx module" message to the actual loading method in PluginsService (it will require passing through whether the code being loaded is a module or plugin).


server/src/main/java/org/elasticsearch/plugins/PluginsService.java
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory;
public class PluginsService implements ReportingService<PluginsAndModules> {
    public StablePluginsRegistry getStablePluginRegistry() {
        return stablePluginsRegistry;
    }
    /**
     * A loaded plugin is one for which Elasticsearch has successfully constructed an instance of the plugin's class
     * @param descriptor Metadata about the plugin, usually loaded from plugin properties
     * @param instance The constructed instance of the plugin's main class
     * @param loader   The classloader for the plugin
     * @param layer   The module layer for the plugin
     */
    record LoadedPlugin(PluginDescriptor descriptor, Plugin instance, ClassLoader loader, ModuleLayer layer) {
        LoadedPlugin {
            Objects.requireNonNull(descriptor);
            Objects.requireNonNull(instance);
            Objects.requireNonNull(loader);
            Objects.requireNonNull(layer);
        }
        /**
         * Creates a loaded <i>classpath plugin</i>. A <i>classpath plugin</i> is a plugin loaded
         * by the system classloader and defined to the unnamed module of the boot layer.
         */
        LoadedPlugin(PluginDescriptor descriptor, Plugin instance) {
            this(descriptor, instance, PluginsService.class.getClassLoader(), ModuleLayer.boot());