Skip to content

Commit

Permalink
Cleanup scan config options. Mark it experimental.
Browse files Browse the repository at this point in the history
Follow up PR from #4374.
  • Loading branch information
ruflin committed Jun 28, 2017
1 parent fa7fc6d commit a8f1de4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
14 changes: 9 additions & 5 deletions filebeat/docs/reference/configuration/filebeat-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 37 additions & 1 deletion filebeat/prospector/log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
HarvesterLimit: 0,
Symlinks: false,
TailFiles: false,
ScanSort: "none",
ScanSort: "",
ScanOrder: "asc",

// Harvester
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion filebeat/prospector/log/prospector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8f1de4

Please sign in to comment.