Skip to content

Commit a09236d

Browse files
authored
Merge pull request #183 from kube-logging/feat/file-exporter
feat: file exporter
2 parents 55fe5c8 + a81bb23 commit a09236d

File tree

13 files changed

+941
-31
lines changed

13 files changed

+941
-31
lines changed

api/telemetry/v1alpha1/output_types.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
package v1alpha1
1616

1717
import (
18+
"time"
19+
20+
"go.opentelemetry.io/collector/component"
1821
corev1 "k8s.io/api/core/v1"
1922
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2023

@@ -66,6 +69,7 @@ type OutputSpec struct {
6669
OTLPGRPC *OTLPGRPC `json:"otlp,omitempty"`
6770
Fluentforward *Fluentforward `json:"fluentforward,omitempty"`
6871
OTLPHTTP *OTLPHTTP `json:"otlphttp,omitempty"`
72+
File *File `json:"file,omitempty"`
6973
Authentication *OutputAuth `json:"authentication,omitempty"`
7074
Batch *Batch `json:"batch,omitempty"`
7175
}
@@ -110,6 +114,99 @@ type OTLPHTTP struct {
110114
Encoding *string `json:"encoding,omitempty"`
111115
}
112116

117+
type formatType string
118+
119+
const (
120+
FormatTypeJSON formatType = "json"
121+
FormatTypeProto formatType = "proto"
122+
)
123+
124+
type compression string
125+
126+
const (
127+
CompressionZstd compression = "zstd"
128+
)
129+
130+
// File defines configuration for the file exporter.
131+
type File struct {
132+
// Path of the file to write to. Path is relative to current directory.
133+
Path string `json:"path,omitempty"`
134+
135+
// Mode defines whether the exporter should append to the file.
136+
// Options:
137+
// - false[default]: truncates the file
138+
// - true: appends to the file.
139+
Append bool `json:"append,omitempty"`
140+
141+
// Rotation defines an option about rotation of telemetry files. Ignored
142+
// when GroupByAttribute is used.
143+
Rotation *Rotation `json:"rotation,omitempty"`
144+
145+
// +kubebuilder:validation:Enum:=proto;json
146+
147+
// FormatType define the data format of encoded telemetry data
148+
// Options:
149+
// - json[default]: OTLP json bytes.
150+
// - proto: OTLP binary protobuf bytes.
151+
152+
FormatType formatType `json:"format,omitempty"`
153+
154+
// Encoding defines the encoding of the telemetry data.
155+
// If specified, it overrides `FormatType` and applies an encoding extension.
156+
Encoding *component.ID `json:"encoding,omitempty"`
157+
158+
// +kubebuilder:validation:Enum:=zstd
159+
160+
// Compression Codec used to export telemetry data
161+
// Supported compression algorithms:`zstd`
162+
Compression compression `json:"compression,omitempty"`
163+
164+
// FlushInterval is the duration between flushes.
165+
// See time.ParseDuration for valid values.
166+
FlushInterval time.Duration `json:"flush_interval,omitempty"`
167+
168+
// GroupBy enables writing to separate files based on a resource attribute.
169+
GroupBy *GroupBy `json:"group_by,omitempty"`
170+
}
171+
172+
// Rotation an option to rolling log files
173+
type Rotation struct {
174+
// MaxMegabytes is the maximum size in megabytes of the file before it gets
175+
// rotated. It defaults to 100 megabytes.
176+
MaxMegabytes int `json:"max_megabytes,omitempty"`
177+
178+
// MaxDays is the maximum number of days to retain old log files based on the
179+
// timestamp encoded in their filename. Note that a day is defined as 24
180+
// hours and may not exactly correspond to calendar days due to daylight
181+
// savings, leap seconds, etc. The default is not to remove old log files
182+
// based on age.
183+
MaxDays int `json:"max_days,omitempty"`
184+
185+
// MaxBackups is the maximum number of old log files to retain. The default
186+
// is to 100 files.
187+
MaxBackups int `json:"max_backups,omitempty"`
188+
189+
// LocalTime determines if the time used for formatting the timestamps in
190+
// backup files is the computer's local time. The default is to use UTC
191+
// time.
192+
LocalTime *bool `json:"localtime,omitempty"`
193+
}
194+
195+
type GroupBy struct {
196+
// Enables group_by. When group_by is enabled, rotation setting is ignored. Default is false.
197+
Enabled bool `json:"enabled,omitempty"`
198+
199+
// ResourceAttribute specifies the name of the resource attribute that
200+
// contains the path segment of the file to write to. The final path will be
201+
// the Path config value, with the * replaced with the value of this resource
202+
// attribute. Default is "fileexporter.path_segment".
203+
ResourceAttribute string `json:"resource_attribute,omitempty"`
204+
205+
// MaxOpenFiles specifies the maximum number of open file descriptors for the output files.
206+
// The default is 100.
207+
MaxOpenFiles int `json:"max_open_files,omitempty"`
208+
}
209+
113210
type Endpoint struct {
114211
// TCPAddr is the address of the server to connect to.
115212
TCPAddr *string `json:"tcp_addr"`

api/telemetry/v1alpha1/zz_generated.deepcopy.go

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/telemetry-controller/crds/telemetry.kube-logging.dev_outputs.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,92 @@ spec:
144144
format: duration
145145
type: string
146146
type: object
147+
file:
148+
description: File defines configuration for the file exporter.
149+
properties:
150+
append:
151+
description: |-
152+
Mode defines whether the exporter should append to the file.
153+
Options:
154+
- false[default]: truncates the file
155+
- true: appends to the file.
156+
type: boolean
157+
compression:
158+
description: |-
159+
Compression Codec used to export telemetry data
160+
Supported compression algorithms:`zstd`
161+
enum:
162+
- zstd
163+
type: string
164+
encoding:
165+
description: |-
166+
Encoding defines the encoding of the telemetry data.
167+
If specified, it overrides `FormatType` and applies an encoding extension.
168+
type: string
169+
flush_interval:
170+
description: |-
171+
FlushInterval is the duration between flushes.
172+
See time.ParseDuration for valid values.
173+
format: int64
174+
type: integer
175+
format:
176+
type: string
177+
group_by:
178+
description: GroupBy enables writing to separate files based on
179+
a resource attribute.
180+
properties:
181+
enabled:
182+
description: Enables group_by. When group_by is enabled, rotation
183+
setting is ignored. Default is false.
184+
type: boolean
185+
max_open_files:
186+
description: |-
187+
MaxOpenFiles specifies the maximum number of open file descriptors for the output files.
188+
The default is 100.
189+
type: integer
190+
resource_attribute:
191+
description: |-
192+
ResourceAttribute specifies the name of the resource attribute that
193+
contains the path segment of the file to write to. The final path will be
194+
the Path config value, with the * replaced with the value of this resource
195+
attribute. Default is "fileexporter.path_segment".
196+
type: string
197+
type: object
198+
path:
199+
description: Path of the file to write to. Path is relative to
200+
current directory.
201+
type: string
202+
rotation:
203+
description: |-
204+
Rotation defines an option about rotation of telemetry files. Ignored
205+
when GroupByAttribute is used.
206+
properties:
207+
localtime:
208+
description: |-
209+
LocalTime determines if the time used for formatting the timestamps in
210+
backup files is the computer's local time. The default is to use UTC
211+
time.
212+
type: boolean
213+
max_backups:
214+
description: |-
215+
MaxBackups is the maximum number of old log files to retain. The default
216+
is to 100 files.
217+
type: integer
218+
max_days:
219+
description: |-
220+
MaxDays is the maximum number of days to retain old log files based on the
221+
timestamp encoded in their filename. Note that a day is defined as 24
222+
hours and may not exactly correspond to calendar days due to daylight
223+
savings, leap seconds, etc. The default is not to remove old log files
224+
based on age.
225+
type: integer
226+
max_megabytes:
227+
description: |-
228+
MaxMegabytes is the maximum size in megabytes of the file before it gets
229+
rotated. It defaults to 100 megabytes.
230+
type: integer
231+
type: object
232+
type: object
147233
fluentforward:
148234
description: Configuration for the fluentforward exporter.
149235
properties:

0 commit comments

Comments
 (0)