mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
fix(config): fix config reloading errors that caused by using wrong relative paths to load config file
This commit is contained in:
@@ -132,7 +132,7 @@ class ContextWorkspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (removedBlocks.isNotEmpty()) {
|
if (removedBlocks.isNotEmpty()) {
|
||||||
recordExpire(sourceKey, removedBlocks)
|
recordExpire(sourceKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,12 +144,19 @@ class ContextWorkspace {
|
|||||||
TraceRecorder.record(TraceEvent(tracePath, payload))
|
TraceRecorder.record(TraceEvent(tracePath, payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recordExpire(sourceKey: ContextBlock.SourceKey, removedBlocks: List<ContextBlock>) {
|
private fun recordExpire(sourceKey: ContextBlock.SourceKey) {
|
||||||
val payload = JSONObject()
|
val payload = JSONObject()
|
||||||
payload["action"] = "expire"
|
payload["action"] = "expire"
|
||||||
payload["blockName"] = sourceKey.blockName
|
payload["changedSourceKey"] = JSONObject.of(
|
||||||
payload["source"] = sourceKey.source
|
"blockName", sourceKey.blockName,
|
||||||
payload["removed"] = removedBlocks.map(::blockSnapshot)
|
"source", sourceKey.source
|
||||||
|
)
|
||||||
|
payload["blocks"] = stateSet
|
||||||
|
.sortedWith(
|
||||||
|
compareBy<ContextBlock> { it.sourceKey.blockName }
|
||||||
|
.thenBy { it.sourceKey.source }
|
||||||
|
)
|
||||||
|
.map(::blockSnapshot)
|
||||||
TraceRecorder.record(TraceEvent(tracePath, payload))
|
TraceRecorder.record(TraceEvent(tracePath, payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ object ConfigCenter : AutoCloseable {
|
|||||||
fun initAll() {
|
fun initAll() {
|
||||||
val errorConfig = mutableMapOf<Path, String>()
|
val errorConfig = mutableMapOf<Path, String>()
|
||||||
registrations.forEach { (path, registration) ->
|
registrations.forEach { (path, registration) ->
|
||||||
val pair = loadConfig(path, registration)
|
val configFile = paths.configDir.resolve(path).normalize()
|
||||||
|
val pair = loadConfig(configFile, registration)
|
||||||
if (pair != null) {
|
if (pair != null) {
|
||||||
(registration as ConfigRegistration<Config>).init(pair.first, pair.second)
|
(registration as ConfigRegistration<Config>).init(pair.first, pair.second)
|
||||||
return@forEach
|
return@forEach
|
||||||
@@ -175,6 +176,7 @@ object ConfigCenter : AutoCloseable {
|
|||||||
return field.isSynthetic || Modifier.isStatic(field.modifiers)
|
return field.isSynthetic || Modifier.isStatic(field.modifiers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
private fun handleUpsert(thisDir: Path, context: Path?) {
|
private fun handleUpsert(thisDir: Path, context: Path?) {
|
||||||
if (context == null || !Files.isRegularFile(context) || !isJsonFile(context)) {
|
if (context == null || !Files.isRegularFile(context) || !isJsonFile(context)) {
|
||||||
return
|
return
|
||||||
@@ -182,6 +184,7 @@ object ConfigCenter : AutoCloseable {
|
|||||||
reloadIfRegistered(context)
|
reloadIfRegistered(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
private fun handleDelete(thisDir: Path, context: Path?) {
|
private fun handleDelete(thisDir: Path, context: Path?) {
|
||||||
if (context == null || !isJsonFile(context)) {
|
if (context == null || !isJsonFile(context)) {
|
||||||
return
|
return
|
||||||
@@ -260,7 +263,7 @@ object ConfigCenter : AutoCloseable {
|
|||||||
checkAgentStartup(!path.isAbsolute) {
|
checkAgentStartup(!path.isAbsolute) {
|
||||||
AgentStartupException("Config path must be relative: $path", COMPONENT_NAME)
|
AgentStartupException("Config path must be relative: $path", COMPONENT_NAME)
|
||||||
}
|
}
|
||||||
return paths.configDir.resolve(path).normalize()
|
return path.normalize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,13 @@ object LogAdviceProvider : Configurable, ConfigRegistration<AdviceLoggingConfig>
|
|||||||
logLevel = config.logLevel
|
logLevel = config.logLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onReload(
|
||||||
|
config: AdviceLoggingConfig,
|
||||||
|
json: JSONObject?
|
||||||
|
) {
|
||||||
|
this.logLevel = config.logLevel
|
||||||
|
}
|
||||||
|
|
||||||
override fun defaultConfig(): AdviceLoggingConfig = AdviceLoggingConfig(AdviceLoggingConfig.LogLevel.NONE)
|
override fun defaultConfig(): AdviceLoggingConfig = AdviceLoggingConfig(AdviceLoggingConfig.LogLevel.NONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ class ConfigCenterTest {
|
|||||||
writeJson(workingDir.resolve(INVALID_PATH), "invalid-init", 1);
|
writeJson(workingDir.resolve(INVALID_PATH), "invalid-init", 1);
|
||||||
writeJson(workingDir.resolve(IDEMPOTENT_PATH), "idempotent-init", 1);
|
writeJson(workingDir.resolve(IDEMPOTENT_PATH), "idempotent-init", 1);
|
||||||
writeJson(configDir.resolve(INITIAL_PATH), "initial-config-dir", 1);
|
writeJson(configDir.resolve(INITIAL_PATH), "initial-config-dir", 1);
|
||||||
|
writeJson(configDir.resolve(NESTED_PATH), "nested-config-dir", 1);
|
||||||
|
writeJson(configDir.resolve(DELETE_PATH), "delete-config-dir", 1);
|
||||||
|
writeJson(configDir.resolve(INVALID_PATH), "invalid-config-dir", 1);
|
||||||
|
writeJson(configDir.resolve(IDEMPOTENT_PATH), "idempotent-config-dir", 1);
|
||||||
|
|
||||||
ConfigCenter.INSTANCE.register(() -> {
|
ConfigCenter.INSTANCE.register(() -> {
|
||||||
Map<Path, ConfigRegistration<? extends Config>> declared = new LinkedHashMap<>();
|
Map<Path, ConfigRegistration<? extends Config>> declared = new LinkedHashMap<>();
|
||||||
@@ -159,7 +163,7 @@ class ConfigCenterTest {
|
|||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void testStartOnlyInitializesOneRegisteredConfigAndDoesNotTriggerReload() {
|
void testStartOnlyInitializesOneRegisteredConfigAndDoesNotTriggerReload() {
|
||||||
Assertions.assertEquals(1, totalInitCount());
|
Assertions.assertEquals(5, totalInitCount());
|
||||||
Assertions.assertEquals(0, totalReloadCount());
|
Assertions.assertEquals(0, totalReloadCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user