-
Notifications
You must be signed in to change notification settings - Fork 43
Add possibility to force flush logs after certain period of time #216
Changes from 13 commits
644475a
e2399ad
b9ece36
d16d0ee
5d3f482
6b3c0b5
f64b057
5682458
c9bb6cd
a1bf062
1503414
c6557fd
bced39d
6c72b19
b2faa2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ func NewInputConfig(operatorID string) *InputConfig { | |
IncludeFilePath: false, | ||
IncludeFileNameResolved: false, | ||
IncludeFilePathResolved: false, | ||
ForceFlush: helper.NewForceFlushConfig(), | ||
StartAt: "end", | ||
FingerprintSize: defaultFingerprintSize, | ||
MaxLogSize: defaultMaxLogSize, | ||
|
@@ -58,17 +59,18 @@ type InputConfig struct { | |
Include []string `mapstructure:"include,omitempty" json:"include,omitempty" yaml:"include,omitempty"` | ||
Exclude []string `mapstructure:"exclude,omitempty" json:"exclude,omitempty" yaml:"exclude,omitempty"` | ||
|
||
PollInterval helper.Duration `mapstructure:"poll_interval,omitempty" json:"poll_interval,omitempty" yaml:"poll_interval,omitempty"` | ||
Multiline helper.MultilineConfig `mapstructure:"multiline,omitempty" json:"multiline,omitempty" yaml:"multiline,omitempty"` | ||
IncludeFileName bool `mapstructure:"include_file_name,omitempty" json:"include_file_name,omitempty" yaml:"include_file_name,omitempty"` | ||
IncludeFilePath bool `mapstructure:"include_file_path,omitempty" json:"include_file_path,omitempty" yaml:"include_file_path,omitempty"` | ||
IncludeFileNameResolved bool `mapstructure:"include_file_name_resolved,omitempty" json:"include_file_name_resolved,omitempty" yaml:"include_file_name_resolved,omitempty"` | ||
IncludeFilePathResolved bool `mapstructure:"include_file_path_resolved,omitempty" json:"include_file_path_resolved,omitempty" yaml:"include_file_path_resolved,omitempty"` | ||
StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"` | ||
FingerprintSize helper.ByteSize `mapstructure:"fingerprint_size,omitempty" json:"fingerprint_size,omitempty" yaml:"fingerprint_size,omitempty"` | ||
MaxLogSize helper.ByteSize `mapstructure:"max_log_size,omitempty" json:"max_log_size,omitempty" yaml:"max_log_size,omitempty"` | ||
MaxConcurrentFiles int `mapstructure:"max_concurrent_files,omitempty" json:"max_concurrent_files,omitempty" yaml:"max_concurrent_files,omitempty"` | ||
Encoding helper.EncodingConfig `mapstructure:",squash,omitempty" json:",inline,omitempty" yaml:",inline,omitempty"` | ||
PollInterval helper.Duration `mapstructure:"poll_interval,omitempty" json:"poll_interval,omitempty" yaml:"poll_interval,omitempty"` | ||
Multiline helper.MultilineConfig `mapstructure:"multiline,omitempty" json:"multiline,omitempty" yaml:"multiline,omitempty"` | ||
IncludeFileName bool `mapstructure:"include_file_name,omitempty" json:"include_file_name,omitempty" yaml:"include_file_name,omitempty"` | ||
IncludeFilePath bool `mapstructure:"include_file_path,omitempty" json:"include_file_path,omitempty" yaml:"include_file_path,omitempty"` | ||
IncludeFileNameResolved bool `mapstructure:"include_file_name_resolved,omitempty" json:"include_file_name_resolved,omitempty" yaml:"include_file_name_resolved,omitempty"` | ||
IncludeFilePathResolved bool `mapstructure:"include_file_path_resolved,omitempty" json:"include_file_path_resolved,omitempty" yaml:"include_file_path_resolved,omitempty"` | ||
StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"` | ||
FingerprintSize helper.ByteSize `mapstructure:"fingerprint_size,omitempty" json:"fingerprint_size,omitempty" yaml:"fingerprint_size,omitempty"` | ||
MaxLogSize helper.ByteSize `mapstructure:"max_log_size,omitempty" json:"max_log_size,omitempty" yaml:"max_log_size,omitempty"` | ||
MaxConcurrentFiles int `mapstructure:"max_concurrent_files,omitempty" json:"max_concurrent_files,omitempty" yaml:"max_concurrent_files,omitempty"` | ||
Encoding helper.EncodingConfig `mapstructure:",squash,omitempty" json:",inline,omitempty" yaml:",inline,omitempty"` | ||
ForceFlush helper.ForceFlushConfig `mapstructure:",squash,omitempty" json:",inline,omitempty" yaml:",inline,omitempty"` | ||
} | ||
|
||
// Build will build a file input operator from the supplied configuration | ||
|
@@ -117,7 +119,8 @@ func (c InputConfig) Build(context operator.BuildContext) ([]operator.Operator, | |
return nil, err | ||
} | ||
|
||
splitFunc, err := c.Multiline.Build(context, encoding.Encoding, false) | ||
// Ensure that multiline is buildable | ||
_, err = c.Multiline.Build(encoding.Encoding, false, nil) | ||
djaglowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -156,13 +159,14 @@ func (c InputConfig) Build(context operator.BuildContext) ([]operator.Operator, | |
InputOperator: inputOperator, | ||
Include: c.Include, | ||
Exclude: c.Exclude, | ||
SplitFunc: splitFunc, | ||
Multiline: c.Multiline, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this is just a naming issue, but I'll have a difficult time accepting that the splitfunc is being delegated to a I suspect that we can accomplish the same functionality as you are implementing, but by composing things in a better way. Would it make sense to create a new struct which would pair the concept of a split func with the concept of a flush? Maybe something like: type Splitter struct {
splitFunc // can be simple like '\n' or multiline config
flusher // forces a flush based on timing
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking at this further, I'm not convinced we even need to do what I've suggested here. Please see my related comment on |
||
PollInterval: c.PollInterval.Raw(), | ||
FilePathField: filePathField, | ||
FileNameField: fileNameField, | ||
FilePathResolvedField: filePathResolvedField, | ||
FileNameResolvedField: fileNameResolvedField, | ||
startAtBeginning: startAtBeginning, | ||
ForceFlush: c.ForceFlush, | ||
queuedMatches: make([]string, 0), | ||
encoding: encoding, | ||
firstCheck: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, I think we should use
helper.Duration
instead oftime.Duration
. We can then link tohttps://github.com/open-telemetry/opentelemetry-log-collection/blob/main/docs/types/duration.md
, which explains formatting sufficiently.This is basically the same thing, but with a default unit of seconds, since nanoseconds is basically never reasonable in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated documentation