mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-12 18:26:36 +08:00
feat(core): mount the configuration extension point on the kernel Context
Context 新增 Config() 访问器,注册表随 Fork 共享(配置声明是进程级事实), 并在 types.go 导出配置别名与 ConfigGatedPlugin 可选接口,为插件门禁做准备。
This commit is contained in:
@@ -72,3 +72,21 @@ func TestConfigGetRejectsNilView(t *testing.T) {
|
||||
_, err := core.ConfigGet[float64](nil, "otel.sampling_rate")
|
||||
require.ErrorIs(t, err, extpoints.ErrConfigNotResolved)
|
||||
}
|
||||
|
||||
func TestContextConfigIsSharedAcrossForks(t *testing.T) {
|
||||
ctx := core.NewContext(nil)
|
||||
child := ctx.Fork()
|
||||
|
||||
require.NotNil(t, ctx.Config())
|
||||
assert.Same(t, ctx.Config(), child.Config(), "configuration declarations are process-wide facts")
|
||||
|
||||
require.NoError(t, child.Config().Declare("cache",
|
||||
extpoints.ConfigBinding{Prefix: "otel", Target: &otelConfig{}}))
|
||||
|
||||
declared := false
|
||||
for _, entry := range ctx.Config().Entries() {
|
||||
declared = declared || entry.Key == "otel.sampling_rate"
|
||||
}
|
||||
assert.True(t, declared, "a declaration made in a plugin scope must be visible to the root")
|
||||
assert.False(t, ctx.Config().Resolved())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user