Add configs to DebugReport

This commit is contained in:
Vankka 2023-10-29 23:18:35 +02:00
parent 4bab23bc35
commit c9a811c758
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
8 changed files with 68 additions and 18 deletions

View File

@ -45,7 +45,7 @@ public abstract class ConnectionConfigManager<C extends ConnectionConfig>
}
@Override
protected String fileName() {
public String fileName() {
return ConnectionConfig.FILE_NAME;
}
}

View File

@ -45,7 +45,7 @@ public abstract class MainConfigManager<C extends MainConfig>
}
@Override
protected String fileName() {
public String fileName() {
return MainConfig.FILE_NAME;
}
}

View File

@ -25,6 +25,10 @@ public abstract class MessagesConfigManager<C extends MessagesConfig> {
public abstract C createConfiguration();
public Map<Locale, MessagesConfigSingleManager<C>> getAllManagers() {
return Collections.unmodifiableMap(configs);
}
public MessagesConfigSingleManager<C> getManager(Locale locale) {
synchronized (configs) {
return configs.get(locale);

View File

@ -24,7 +24,7 @@ public class MessagesConfigSingleManager<C extends MessagesConfig>
}
@Override
protected String fileName() {
public String fileName() {
if (multi) {
return aggregateManager.directory().resolve(locale.getISO3Language() + ".yaml").toString();
}

View File

@ -19,6 +19,8 @@
package com.discordsrv.common.config.configurate.manager.abstraction;
import com.discordsrv.common.exception.ConfigException;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.loader.AbstractConfigurationLoader;
public interface ConfigManager<T> {
@ -27,5 +29,6 @@ public interface ConfigManager<T> {
void load() throws ConfigException;
void reload() throws ConfigException;
void save(AbstractConfigurationLoader<CommentedConfigurationNode> loader) throws ConfigException;
void save() throws ConfigException;
}

View File

@ -94,7 +94,7 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
public LT loader() {
if (loader == null) {
loader = createLoader(filePath(), nodeOptions(true));
loader = createLoader(filePath(), nodeOptions(true)).build();
}
return loader;
}
@ -104,7 +104,7 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
return configuration;
}
protected abstract String fileName();
public abstract String fileName();
protected Field headerField() throws ReflectiveOperationException {
return null;
@ -392,9 +392,8 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
@SuppressWarnings("unchecked")
@Override
public void save() throws ConfigException {
public void save(AbstractConfigurationLoader<CommentedConfigurationNode> loader) throws ConfigException {
try {
LT loader = loader();
CommentedConfigurationNode node = loader.createNode();
save(configuration, (Class<T>) configuration.getClass(), node);
loader.save(node);
@ -403,6 +402,12 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
}
}
@Override
public void save() throws ConfigException {
LT loader = loader();
save(loader);
}
protected void save(T config, Class<T> clazz, CommentedConfigurationNode node) throws SerializationException {
objectMapper().get(clazz).save(config, node);
}

View File

@ -35,11 +35,10 @@ public interface ConfigLoaderProvider<LT extends AbstractConfigurationLoader<Com
AbstractConfigurationLoader.Builder<?, LT> createBuilder();
@ApiStatus.NonExtendable
default LT createLoader(Path configFile, ConfigurationOptions options) {
default AbstractConfigurationLoader.Builder<?, LT> createLoader(Path configFile, ConfigurationOptions options) {
return createBuilder()
.path(configFile)
.defaultOptions(options)
.headerMode(headerMode())
.build();
.headerMode(headerMode());
}
}

View File

@ -19,9 +19,13 @@
package com.discordsrv.common.debug;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.configurate.manager.MessagesConfigSingleManager;
import com.discordsrv.common.config.configurate.manager.abstraction.ConfigurateConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.debug.file.DebugFile;
import com.discordsrv.common.debug.file.KeyValueDebugFile;
import com.discordsrv.common.debug.file.TextDebugFile;
import com.discordsrv.common.exception.ConfigException;
import com.discordsrv.common.paste.Paste;
import com.discordsrv.common.paste.PasteService;
import com.discordsrv.common.plugin.Plugin;
@ -30,8 +34,12 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import net.dv8tion.jda.api.JDA;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.loader.AbstractConfigurationLoader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileStore;
import java.nio.file.Files;
@ -44,7 +52,7 @@ import java.util.zip.ZipOutputStream;
public class DebugReport {
private static final int BIG_FILE_SPLIT_SIZE = 20000;
private static final int BIG_FILE_SPLIT_SIZE = 50000;
private final List<DebugFile> files = new ArrayList<>();
private final DiscordSRV discordSRV;
@ -56,10 +64,16 @@ public class DebugReport {
public void generate() {
discordSRV.eventBus().publish(new DebugGenerateEvent(this));
addFile(environment());
addFile(plugins());
addFile(environment()); // 100
addFile(plugins()); // 90
for (Path debugLog : discordSRV.logger().getDebugLogs()) {
addFile(readFile(1, debugLog));
addFile(readFile(80, debugLog));
}
addFile(config(79, discordSRV.configManager()));
addFile(rawConfig(79, discordSRV.configManager()));
for (MessagesConfigSingleManager<? extends MessagesConfig> manager : discordSRV.messagesConfigManager().getAllManagers().values()) {
addFile(config(78, manager));
addFile(rawConfig(78, manager));
}
}
@ -160,7 +174,7 @@ public class DebugReport {
} catch (IOException ignored) {}
values.put("docker", docker);
return new KeyValueDebugFile(10, "environment.json", values);
return new KeyValueDebugFile(100, "environment.json", values);
}
private DebugFile plugins() {
@ -169,14 +183,35 @@ public class DebugReport {
.sorted(Comparator.comparing(plugin -> plugin.name().toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
int order = 90;
String fileName = "plugins.json";
try {
String json = discordSRV.json().writeValueAsString(plugins);
return new TextDebugFile(5, "plugins.json", json);
return new TextDebugFile(order, fileName, json);
} catch (JsonProcessingException e) {
return null;
return exception(order, fileName, e);
}
}
private DebugFile config(int order, ConfigurateConfigManager<?, ?> manager) {
String fileName = "parsed_" + manager.fileName();
try (StringWriter writer = new StringWriter()) {
AbstractConfigurationLoader<CommentedConfigurationNode> loader = manager
.createLoader(manager.filePath(), manager.nodeOptions(true))
.sink(() -> new BufferedWriter(writer))
.build();
manager.save(loader);
return new TextDebugFile(order, fileName, writer.toString());
} catch (IOException | ConfigException e) {
return exception(order, fileName, e);
}
}
private DebugFile rawConfig(int order, ConfigurateConfigManager<?, ?> manager) {
return readFile(order, manager.filePath());
}
private DebugFile readFile(int order, Path file) {
String fileName = file.getFileName().toString();
if (!Files.exists(file)) {
@ -187,7 +222,11 @@ public class DebugReport {
List<String> lines = Files.readAllLines(file, StandardCharsets.UTF_8);
return new TextDebugFile(order, fileName, String.join("\n", lines));
} catch (IOException e) {
return new TextDebugFile(order, fileName, ExceptionUtils.getStackTrace(e));
return exception(order, fileName, e);
}
}
private DebugFile exception(int order, String fileName, Throwable throwable) {
return new TextDebugFile(order, fileName, ExceptionUtils.getStackTrace(throwable));
}
}