diff --git a/filebeat/docs/reference/configuration/filebeat-options.asciidoc b/filebeat/docs/reference/configuration/filebeat-options.asciidoc index 9e6c7ecb4eba..6c5320ffd148 100644 --- a/filebeat/docs/reference/configuration/filebeat-options.asciidoc +++ b/filebeat/docs/reference/configuration/filebeat-options.asciidoc @@ -306,19 +306,23 @@ The default setting is 10s. [[scan-sort]] ===== scan.sort -Specifies if files should be harvested in order and how to determine the order. Possible values are modtime, filename and none. To sort by file modification time use modtime otherwise use filename. +[]experimental -If you specify a value other than none for this setting you can determine whether to use ascending or descending order using `scan.order`. + If you specify a value other than the empty string for this setting you can determine whether to use ascending or descending order using `scan.order`. Possible values are `modtime` and `filename`. To sort by file modification time, use `modtime`, otherwise use `filename`. Leave this option empty to disable it. -The default setting is none. +If you specify a value for this setting, you can use `scan.order` to configure whether files are scanned in ascending or descending order. + +The default setting is disabled. [[scan-order]] ===== scan.order -Specifies ascending or descending order if `scan.sort` is set to a value other than none. Possible values are asc or desc. +[]experimental + +Specifies whether to use ascending or descending order when `scan.sort` is set to a value other than none. Possible values are `asc` or `desc`. -The default setting is asc. +The default setting is `asc`. ===== harvester_buffer_size diff --git a/filebeat/prospector/log/config.go b/filebeat/prospector/log/config.go index 0a51e724a690..6761df690396 100644 --- a/filebeat/prospector/log/config.go +++ b/filebeat/prospector/log/config.go @@ -29,7 +29,7 @@ var ( HarvesterLimit: 0, Symlinks: false, TailFiles: false, - ScanSort: "none", + ScanSort: "", ScanOrder: "asc", // Harvester @@ -92,6 +92,28 @@ type LogConfig struct { CloseTimeout time.Duration `config:"close_timeout" validate:"min=0"` } +// Contains available scan options +const ( + ScanOrderAsc = "asc" + ScanOrderDesc = "desc" + ScanSortNone = "" + ScanSortModtime = "modtime" + ScanSortFilename = "filename" +) + +// ValidScanOrder of valid scan orders +var ValidScanOrder = map[string]struct{}{ + ScanOrderAsc: {}, + ScanOrderDesc: {}, +} + +// ValidScanOrder of valid scan orders +var ValidScanSort = map[string]struct{}{ + ScanSortNone: {}, + ScanSortModtime: {}, + ScanSortFilename: {}, +} + func (c *config) Validate() error { // DEPRECATED 6.0.0: warning is already outputted on propsector level @@ -128,6 +150,20 @@ func (c *config) Validate() error { return fmt.Errorf("When using the JSON decoder and line filtering together, you need to specify a message_key value") } + if c.ScanSort != "" { + logp.Experimental("scan_sort is used.") + + // Check input type + if _, ok := ValidScanSort[c.ScanSort]; !ok { + return fmt.Errorf("Invalid scan sort: %v", c.ScanSort) + } + + // Check input type + if _, ok := ValidScanOrder[c.ScanOrder]; !ok { + return fmt.Errorf("Invalid scan order: %v", c.ScanOrder) + } + } + return nil } diff --git a/filebeat/prospector/log/prospector.go b/filebeat/prospector/log/prospector.go index 9d7a84825eec..f8ba4d32117a 100644 --- a/filebeat/prospector/log/prospector.go +++ b/filebeat/prospector/log/prospector.go @@ -353,7 +353,7 @@ func (p *Prospector) scan() { var err error - if p.config.ScanSort != "none" { + if p.config.ScanSort != "" { sortInfos, err = getSortedFiles(p.config.ScanOrder, p.config.ScanSort, getSortInfos(paths)) if err != nil { logp.Err("Failed to sort files during scan due to error %s", err)