diff --git a/otelcol/config.go b/otelcol/config.go index 9345405b4fd..7c27bd40201 100644 --- a/otelcol/config.go +++ b/otelcol/config.go @@ -12,8 +12,9 @@ import ( ) var ( - errMissingExporters = errors.New("no exporter configuration specified in config") - errMissingReceivers = errors.New("no receiver configuration specified in config") + errMissingExporters = errors.New("no exporter configuration specified in config") + errMissingReceivers = errors.New("no receiver configuration specified in config") + errEmptyConfigurationFile = errors.New("empty configuration file") ) // Config defines the configuration for the various elements of collector or agent. @@ -42,6 +43,11 @@ type Config struct { // invalid cases that we currently don't check for but which we may want to add in // the future (e.g. disallowing receiving and exporting on the same endpoint). func (cfg *Config) Validate() error { + // There must be at least one property set in the configuration file. + if len(cfg.Receivers) == 0 && len(cfg.Exporters) == 0 && len(cfg.Processors) == 0 && len(cfg.Connectors) == 0 && len(cfg.Extensions) == 0 { + return errEmptyConfigurationFile + } + // Currently, there is no default receiver enabled. // The configuration must specify at least one receiver to be valid. if len(cfg.Receivers) == 0 { diff --git a/otelcol/config_test.go b/otelcol/config_test.go index e482e6c8ae8..c1677c07220 100644 --- a/otelcol/config_test.go +++ b/otelcol/config_test.go @@ -54,6 +54,19 @@ func TestConfigValidate(t *testing.T) { }, expected: nil, }, + { + name: "empty configuration file", + cfgFn: func() *Config { + cfg := generateConfig() + cfg.Receivers = nil + cfg.Connectors = nil + cfg.Processors = nil + cfg.Exporters = nil + cfg.Extensions = nil + return cfg + }, + expected: errEmptyConfigurationFile, + }, { name: "missing-exporters", cfgFn: func() *Config {