Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port doublestar support from Opentelementry #283

Merged
merged 9 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.13.20] - Unrealeased

### Added
- Added doublestar support

## [0.13.19] - 2021-04-15

Expand Down
81 changes: 63 additions & 18 deletions cmd/stanza/go.sum

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/operators/file_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ The `file_input` operator reads logs from files. It will place the lines read in

Note that by default, no logs will be read unless the monitored file is actively being written to because `start_at` defaults to `end`.

`include` and `exclude` fields use `github.com/bmatcuk/doublestar` for expression language.
For reference documentation see [here](https://github.com/bmatcuk/doublestar#patterns).

#### `multiline` configuration

If set, the `multiline` configuration block instructs the `file_input` operator to split log entries on a pattern other than newlines.
Expand Down
36 changes: 17 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
module github.com/observiq/stanza

go 1.14
go 1.14

require (
github.com/antonmedv/expr v1.8.2
github.com/cenkalti/backoff/v4 v4.0.2
github.com/antonmedv/expr v1.8.9
github.com/bmatcuk/doublestar/v2 v2.0.4
github.com/cenkalti/backoff/v4 v4.1.0
github.com/json-iterator/go v1.1.10
github.com/kr/text v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/observiq/ctimefmt v1.0.0
github.com/observiq/nanojack v0.0.0-20201106172433-343928847ebc
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.6.1
go.etcd.io/bbolt v1.3.4
go.uber.org/zap v1.15.0
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 // indirect
golang.org/x/text v0.3.3
golang.org/x/tools v0.0.0-20200904185747-39188db58858 // indirect
gonum.org/v1/gonum v0.6.2
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.3.0
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
go.etcd.io/bbolt v1.3.5
go.uber.org/zap v1.16.0
golang.org/x/exp v0.0.0-20210417010653-0739314eea07 // indirect
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
golang.org/x/text v0.3.6
gonum.org/v1/gonum v0.9.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0
honnef.co/go/tools v0.1.3 // indirect
)
112 changes: 76 additions & 36 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions operator/builtin/input/file/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package file
import (
"bufio"
"fmt"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/bmatcuk/doublestar/v2"
"github.com/observiq/stanza/entry"
"github.com/observiq/stanza/operator"
"github.com/observiq/stanza/operator/helper"
Expand Down Expand Up @@ -76,15 +76,15 @@ func (c InputConfig) Build(context operator.BuildContext) ([]operator.Operator,

// Ensure includes can be parsed as globs
for _, include := range c.Include {
_, err := filepath.Match(include, "matchstring")
_, err := doublestar.PathMatch(include, "matchstring")
if err != nil {
return nil, fmt.Errorf("parse include glob: %s", err)
}
}

// Ensure excludes can be parsed as globs
for _, exclude := range c.Exclude {
_, err := filepath.Match(exclude, "matchstring")
_, err := doublestar.PathMatch(exclude, "matchstring")
if err != nil {
return nil, fmt.Errorf("parse exclude glob: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion operator/builtin/input/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

"github.com/bmatcuk/doublestar/v2"
"github.com/observiq/stanza/entry"
"github.com/observiq/stanza/operator/helper"
"go.uber.org/zap"
Expand Down Expand Up @@ -170,7 +171,7 @@ func getMatches(includes, excludes []string) []string {
INCLUDE:
for _, match := range matches {
for _, exclude := range excludes {
if itMatches, _ := filepath.Match(exclude, match); itMatches {
if itMatches, _ := doublestar.PathMatch(exclude, match); itMatches {
continue INCLUDE
}
}
Expand Down
4 changes: 2 additions & 2 deletions operator/builtin/input/k8sevent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.14

require (
github.com/observiq/stanza v0.13.10
github.com/stretchr/testify v1.6.1
go.uber.org/zap v1.15.0
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.16.0
k8s.io/api v0.19.0
k8s.io/apimachinery v0.19.0
k8s.io/client-go v0.19.0
Expand Down
Loading