v0.28.0 option schema in struct tags, schema replacing plugin factory metadata, tui prep
This commit is contained in:
1 parent
a1648ce17b
commit
e8e5f05e47
43 files changed
+1345
-1211
No files matched your search
@@ -69,12 +69,14 @@ func (s *slowSink) GetStats() sink.SinkStats { return sink.SinkStats{} }
|
||||
|
||||
var testSinks = map[string]*slowSink{}
|
||||
|
||||
// The fakes take catalogue types that no plugin package registers in this
|
||||
// test binary
|
||||
func init() {
|
||||
plugin.RegisterSource("test_finite", func(id string, cfg map[string]any, _ *log.Logger, _ *session.Proxy) (source.Source, error) {
|
||||
plugin.RegisterSource("random", func(id string, cfg map[string]any, _ *log.Logger, _ *session.Proxy) (source.Source, error) {
|
||||
n, _ := strconv.Atoi(fmt.Sprint(cfg["n"]))
|
||||
return &finiteSource{n: n}, nil
|
||||
})
|
||||
plugin.RegisterSink("test_slow", func(id string, _ map[string]any, _ *log.Logger, _ *session.Proxy) (sink.Sink, error) {
|
||||
plugin.RegisterSink("null", func(id string, _ map[string]any, _ *log.Logger, _ *session.Proxy) (sink.Sink, error) {
|
||||
return testSinks[id], nil
|
||||
})
|
||||
}
|
||||
@@ -84,8 +86,8 @@ func newTestPipeline(t *testing.T, n int, s *slowSink) *Pipeline {
|
||||
testSinks[t.Name()] = s
|
||||
p, err := NewPipeline(&config.PipelineConfig{
|
||||
Name: t.Name(),
|
||||
PluginSources: []config.PluginSourceConfig{{ID: "src", Type: "test_finite", Config: map[string]any{"n": n}}},
|
||||
PluginSinks: []config.PluginSinkConfig{{ID: t.Name(), Type: "test_slow"}},
|
||||
PluginSources: []config.PluginSourceConfig{{ID: "src", Type: "random", Config: map[string]any{"n": n}}},
|
||||
PluginSinks: []config.PluginSinkConfig{{ID: t.Name(), Type: "null"}},
|
||||
}, log.NewLogger())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/lixenwraith/logwisp/internal/config"
|
||||
"github.com/lixenwraith/logwisp/internal/plugin"
|
||||
"github.com/lixenwraith/logwisp/internal/session"
|
||||
"github.com/lixenwraith/logwisp/internal/sink"
|
||||
@@ -59,7 +60,7 @@ func NewRegistry(pipelineName string, logger *log.Logger) *Registry {
|
||||
func (r *Registry) CreateSource(
|
||||
id string,
|
||||
pluginType string,
|
||||
config map[string]any,
|
||||
options map[string]any,
|
||||
logger *log.Logger,
|
||||
proxy *session.Proxy,
|
||||
) (source.Source, error) {
|
||||
@@ -72,8 +73,8 @@ func (r *Registry) CreateSource(
|
||||
}
|
||||
|
||||
// Check single instance constraint
|
||||
if meta, ok := plugin.GetSourceMetadata(pluginType); ok {
|
||||
if meta.MaxInstances == 1 && r.sourceTypeCounts[pluginType] >= 1 {
|
||||
if row, ok := config.LookupPlugin("source", pluginType); ok {
|
||||
if row.Single && r.sourceTypeCounts[pluginType] >= 1 {
|
||||
return nil, fmt.Errorf("source type %s only allows single instance", pluginType)
|
||||
}
|
||||
}
|
||||
@@ -85,7 +86,7 @@ func (r *Registry) CreateSource(
|
||||
}
|
||||
|
||||
// Create instance
|
||||
src, err := constructor(id, config, logger, proxy)
|
||||
src, err := constructor(id, options, logger, proxy)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create source %s: %w", id, err)
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func (r *Registry) CreateSource(
|
||||
func (r *Registry) CreateSink(
|
||||
id string,
|
||||
pluginType string,
|
||||
config map[string]any,
|
||||
options map[string]any,
|
||||
logger *log.Logger,
|
||||
proxy *session.Proxy,
|
||||
) (sink.Sink, error) {
|
||||
@@ -119,8 +120,8 @@ func (r *Registry) CreateSink(
|
||||
}
|
||||
|
||||
// Check single instance constraint
|
||||
if meta, ok := plugin.GetSinkMetadata(pluginType); ok {
|
||||
if meta.MaxInstances == 1 && r.sinkTypeCounts[pluginType] >= 1 {
|
||||
if row, ok := config.LookupPlugin("sink", pluginType); ok {
|
||||
if row.Single && r.sinkTypeCounts[pluginType] >= 1 {
|
||||
return nil, fmt.Errorf("sink type %s only allows single instance", pluginType)
|
||||
}
|
||||
}
|
||||
@@ -132,7 +133,7 @@ func (r *Registry) CreateSink(
|
||||
}
|
||||
|
||||
// Create instance
|
||||
snk, err := constructor(id, config, logger, proxy)
|
||||
snk, err := constructor(id, options, logger, proxy)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create sink %s: %w", id, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user