bui 4 年之前
父节点
当前提交
61ac2ef8ff

+ 10 - 14
pkg/acquisition/acquisition.go

@@ -63,15 +63,15 @@ cat mode will return once source has been exhausted.
 
 // The interface each datasource must implement
 type DataSource interface {
-	GetMetrics() []prometheus.Collector                        // Returns pointers to metrics that are managed by the module
-	Configure([]byte, configuration.DataSourceCommonCfg) error // Configure the datasource
-	ConfigureByDSN(string, *log.Entry) error                   // Configure the datasource
-	GetMode() string                                           // Get the mode (TAIL, CAT or SERVER)
-	SupportedModes() []string                                  // Returns the mode supported by the datasource
-	SupportedDSN() []string                                    // Returns the list of supported URI schemes (file:// s3:// ...)
-	OneShotAcquisition(chan types.Event, *tomb.Tomb) error     // Start one shot acquisition(eg, cat a file)
-	LiveAcquisition(chan types.Event, *tomb.Tomb) error        // Start live acquisition (eg, tail a file)
-	CanRun() error                                             // Whether the datasource can run or not (eg, journalctl on BSD is a non-sense)
+	GetMetrics() []prometheus.Collector                    // Returns pointers to metrics that are managed by the module
+	Configure([]byte, *log.Entry) error                    // Configure the datasource
+	ConfigureByDSN(string, *log.Entry) error               // Configure the datasource
+	GetMode() string                                       // Get the mode (TAIL, CAT or SERVER)
+	SupportedModes() []string                              // Returns the mode supported by the datasource
+	SupportedDSN() []string                                // Returns the list of supported URI schemes (file:// s3:// ...)
+	OneShotAcquisition(chan types.Event, *tomb.Tomb) error // Start one shot acquisition(eg, cat a file)
+	LiveAcquisition(chan types.Event, *tomb.Tomb) error    // Start live acquisition (eg, tail a file)
+	CanRun() error                                         // Whether the datasource can run or not (eg, journalctl on BSD is a non-sense)
 	Dump() interface{}
 }
 
@@ -122,12 +122,8 @@ func DataSourceConfigure(yamlConfig []byte, commonConfig configuration.DataSourc
 		if !found {
 			return nil, fmt.Errorf("%s mode is not supported by %s", commonConfig.Mode, commonConfig.Source)
 		}
-		if commonConfig.Mode == "" {
-			commonConfig.Mode = configuration.TAIL_MODE
-		}
-		commonConfig.Logger = subLogger
 		/* configure the actual datasource */
-		if err := dataSrc.Configure(yamlConfig, commonConfig); err != nil {
+		if err := dataSrc.Configure(yamlConfig, subLogger); err != nil {
 			return nil, errors.Wrapf(err, "failed to configure datasource %s", commonConfig.Source)
 
 		}

+ 12 - 3
pkg/acquisition/acquisition_test.go

@@ -20,12 +20,17 @@ import (
 type MockSource struct {
 	configuration.DataSourceCommonCfg `yaml:",inline"`
 	Toto                              string `yaml:"toto"`
+	logger                            *log.Entry
 }
 
-func (f *MockSource) Configure(cfg []byte, commonConfig configuration.DataSourceCommonCfg) error {
+func (f *MockSource) Configure(cfg []byte, logger *log.Entry) error {
+	f.logger = logger
 	if err := yaml.UnmarshalStrict(cfg, &f); err != nil {
 		return errors.Wrap(err, "while unmarshaling to reader specific config")
 	}
+	if f.Mode == "" {
+		f.Mode = configuration.CAT_MODE
+	}
 	if f.Toto == "" {
 		return fmt.Errorf("expect non-empty toto")
 	}
@@ -308,8 +313,10 @@ type MockCat struct {
 }
 
 func (f *MockCat) Configure(cfg []byte, logger *log.Entry) error {
-	f.SetDefaults()
 	f.logger = logger
+	if f.Mode == "" {
+		f.Mode = configuration.CAT_MODE
+	}
 	return nil
 }
 func (f *MockCat) GetMode() string          { return "cat" }
@@ -339,8 +346,10 @@ type MockTail struct {
 }
 
 func (f *MockTail) Configure(cfg []byte, logger *log.Entry) error {
-	f.SetDefaults()
 	f.logger = logger
+	if f.Mode == "" {
+		f.Mode = configuration.TAIL_MODE
+	}
 	return nil
 }
 func (f *MockTail) GetMode() string          { return "tail" }

+ 5 - 0
pkg/acquisition/configuration/configuration.go

@@ -13,6 +13,11 @@ type DataSourceCommonCfg struct {
 	Logger     *log.Entry        `yaml:"-"`
 }
 
+// func (d *DataSourceCommonCfg) SetDefaults(cfg []byte) error {
+// 	//if mode == "" -> tail
+// 	//if source == "" && filename || filenames ->
+// }
+
 var TAIL_MODE = "tail"
 var CAT_MODE = "cat"
 var SERVER_MODE = "server" // No difference with tail, just a bit more verbose

+ 0 - 1
pkg/acquisition/modules/file/file.go

@@ -60,7 +60,6 @@ func (f *FileSource) Configure(Config []byte, logger *log.Entry) error {
 		return fmt.Errorf("no filename or filenames configuration provided")
 	}
 	f.config = fileConfig
-	f.config.SetDefaults()
 	f.watcher, err = fsnotify.NewWatcher()
 	if err != nil {
 		return errors.Wrapf(err, "Could not create fsnotify watcher")