From fe7ab2f2cebd2e0a6d4f82f055717c0ec0841a3b Mon Sep 17 00:00:00 2001 From: jeffail Date: Wed, 17 Jan 2018 16:10:15 +0000 Subject: [PATCH] Avoid brokers when unnecessary --- lib/input/fan_in.go | 6 ++++++ lib/output/fan_out.go | 6 ++++++ lib/output/round_robin.go | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/lib/input/fan_in.go b/lib/input/fan_in.go index 2a50b593e9..e8a79ae725 100644 --- a/lib/input/fan_in.go +++ b/lib/input/fan_in.go @@ -238,6 +238,12 @@ func NewFanIn( return nil, err } + if len(inputConfs) == 0 { + return nil, ErrFanInNoInputs + } else if len(inputConfs) == 1 { + return New(inputConfs[0], log, stats, pipelines...) + } + inputs := make([]types.Producer, len(inputConfs)) for i, iConf := range inputConfs { diff --git a/lib/output/fan_out.go b/lib/output/fan_out.go index 496e9dcd17..177fcf1127 100644 --- a/lib/output/fan_out.go +++ b/lib/output/fan_out.go @@ -85,6 +85,12 @@ func NewFanOut(conf Config, log log.Modular, stats metrics.Type) (Type, error) { return nil, err } + if len(outputConfs) == 0 { + return nil, ErrFanOutNoOutputs + } else if len(outputConfs) == 1 { + return New(outputConfs[0], log, stats) + } + outputs := make([]types.Consumer, len(outputConfs)) for i, oConf := range outputConfs { diff --git a/lib/output/round_robin.go b/lib/output/round_robin.go index ba57e14882..e1f560174e 100644 --- a/lib/output/round_robin.go +++ b/lib/output/round_robin.go @@ -80,6 +80,12 @@ func NewRoundRobin(conf Config, log log.Modular, stats metrics.Type) (Type, erro return nil, err } + if len(outputConfs) == 0 { + return nil, ErrFanOutNoOutputs + } else if len(outputConfs) == 1 { + return New(outputConfs[0], log, stats) + } + outputs := make([]types.Consumer, len(outputConfs)) for i, oConf := range outputConfs {