Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions .chloggen/add-buffered-flag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: fileexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add parameter (`unbuffered`) to turn optionally off the file buffering.

# One or more tracking issues related to the change
issues: [18251]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
10 changes: 9 additions & 1 deletion exporter/fileexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Telemetry data is compressed according to the `compression` setting.

Currently, `fileexporter` support the `zstd` compression algorithm, and we will support more compression algorithms in the future.

## File Format
## File Format

Telemetry data is encoded according to the `format` setting and then written to the file.

Expand All @@ -66,13 +66,21 @@ When `format` is json and `compression` is none , telemetry data is written to f
Otherwise, when using `proto` format or any kind of encoding, each encoded object is preceded by 4 bytes (an unsigned 32 bit integer) which represent the number of bytes contained in the encoded object.When we need read the messages back in, we read the size, then read the bytes into a separate buffer, then parse from that buffer.


## Buffering

By default, writes to the output file (when rotation is not used) are buffered. This can be turned off by setting the `unbuffered` parameter to `true`. The default value is `false`. This will be ignored when file rotation is used.

## Example:

```yaml
exporters:
file/no_rotation:
path: ./foo

file/no_rotation_unbuffered:
path: ./foo
unbuffered: true

file/rotation_with_default_settings:
path: ./foo
rotation:
Expand Down
5 changes: 5 additions & 0 deletions exporter/fileexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type Config struct {
// Compression Codec used to export telemetry data
// Supported compression algorithms:`zstd`
Compression string `mapstructure:"compression"`

// Unbuffered indicates whether to use buffering
// or not when writing to files. Default is false.
// Ignored when file rotation is used.
Unbuffered bool `mapstructure:"unbuffered"`
}

// Rotation an option to rolling log files
Expand Down
21 changes: 21 additions & 0 deletions exporter/fileexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ func TestLoadConfig(t *testing.T) {
expected component.Config
errorMessage string
}{
{
id: component.NewIDWithName(typeStr, "no_rotation"),
expected: &Config{
Path: "./foo",
Rotation: nil,
FormatType: formatTypeJSON,
Compression: "",
Unbuffered: false,
},
},
{
id: component.NewIDWithName(typeStr, "no_rotation_unbuffered"),
expected: &Config{
Path: "./foo",
Rotation: nil,
FormatType: formatTypeJSON,
Compression: "",
Unbuffered: true,
},
},
{
id: component.NewIDWithName(typeStr, "2"),
expected: &Config{
Expand All @@ -46,6 +66,7 @@ func TestLoadConfig(t *testing.T) {
LocalTime: true,
},
FormatType: formatTypeJSON,
Unbuffered: false,
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions exporter/fileexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func buildFileWriter(cfg *Config) (io.WriteCloser, error) {
if err != nil {
return nil, err
}
if cfg.Unbuffered {
return f, nil
}
return newBufferedWriteCloser(f), nil
}
return &lumberjack.Logger{
Expand Down
3 changes: 3 additions & 0 deletions exporter/fileexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ file/3:

file/no_rotation:
path: ./foo
file/no_rotation_unbuffered:
path: ./foo
unbuffered: true
file/rotation_with_default_settings:
path: ./foo
rotation:
Expand Down