-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pipelines: | ||
join_throttle: | ||
settings: | ||
event_timeout: 1s | ||
input: | ||
type: file | ||
persistence_mode: async | ||
watching_dir: SOME_DIR | ||
offsets_file: SOME_FILE | ||
offsets_op: reset | ||
actions: | ||
- type: join | ||
field: message | ||
start: '/^start/' | ||
continue: '/^continue/' | ||
- type: modify | ||
ts: '2009-11-10T23:00:00Z' | ||
- type: throttle | ||
bucket_interval: 1m | ||
buckets_count: 60 | ||
default_limit: 100 | ||
throttle_field: service | ||
time_field: ts | ||
output: | ||
type: file | ||
target_file: SOME_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package join_throttle | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ozontech/file.d/cfg" | ||
"github.com/ozontech/file.d/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type Config struct { | ||
inputDir string | ||
outputDir string | ||
Count int | ||
} | ||
|
||
func (c *Config) Configure(t *testing.T, conf *cfg.Config, pipelineName string) { | ||
c.inputDir = t.TempDir() | ||
c.outputDir = t.TempDir() | ||
offsetsDir := t.TempDir() | ||
|
||
input := conf.Pipelines[pipelineName].Raw.Get("input") | ||
input.Set("watching_dir", c.inputDir) | ||
input.Set("filename_pattern", "input.log") | ||
input.Set("offsets_file", filepath.Join(offsetsDir, "offsets.yaml")) | ||
|
||
output := conf.Pipelines[pipelineName].Raw.Get("output") | ||
output.Set("target_file", path.Join(c.outputDir, "output.log")) | ||
} | ||
|
||
func (c *Config) Send(t *testing.T) { | ||
file, err := os.Create(path.Join(c.inputDir, "input.log")) | ||
require.NoError(t, err) | ||
defer file.Close() | ||
|
||
for i := 0; i < c.Count; i++ { | ||
_, err = file.WriteString(`{"message":"start "}` + "\n") | ||
_ = file.Sync() | ||
require.NoError(t, err) | ||
} | ||
} | ||
|
||
func (c *Config) Validate(t *testing.T) { | ||
logFilePattern := path.Join(c.outputDir, "*") | ||
|
||
expectedEvents := 100 // because we are set default_limit: 100 in the throttle plugin | ||
|
||
test.WaitProcessEvents(t, expectedEvents, 3*time.Second, 50*time.Second, logFilePattern) | ||
matches := test.GetMatches(t, logFilePattern) | ||
assert.True(t, len(matches) > 0, "no files with processed events") | ||
|
||
got := test.CountLines(t, logFilePattern) | ||
|
||
throttleAccuracy := got >= expectedEvents && got <= expectedEvents*2 // we don't know how many events we will get | ||
assert.True(t, throttleAccuracy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters