Skip to content

Commit 5c1c514

Browse files
committed
address some review comments
1 parent 03e726c commit 5c1c514

File tree

5 files changed

+31
-35
lines changed

5 files changed

+31
-35
lines changed

config/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ type AgentConfig struct {
272272
// this setting to true will skip the second run of processors.
273273
SkipProcessorsAfterAggregators bool `toml:"skip_processors_after_aggregators"`
274274

275-
BufferStrategy string `toml:"buffer_strategy"`
276-
BufferFileDirectory string `toml:"buffer_file_directory"`
275+
BufferStrategy string `toml:"buffer_strategy"`
276+
BufferDirectory string `toml:"buffer_directory"`
277277
}
278278

279279
// InputNames returns a list of strings of the configured inputs.
@@ -1493,7 +1493,7 @@ func (c *Config) buildOutput(name string, tbl *ast.Table) (*models.OutputConfig,
14931493
c.getFieldString(tbl, "name_prefix", &oc.NamePrefix)
14941494
c.getFieldString(tbl, "startup_error_behavior", &oc.StartupErrorBehavior)
14951495
c.getFieldString(tbl, "buffer_strategy", &oc.BufferStrategy)
1496-
c.getFieldString(tbl, "buffer_file_directory", &oc.BufferFileDirectory)
1496+
c.getFieldString(tbl, "buffer_directory", &oc.BufferDirectory)
14971497

14981498
if c.hasErrs() {
14991499
return nil, c.firstErr()

models/buffer.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ var (
1010
AgentMetricsDropped = selfstat.Register("agent", "metrics_dropped", map[string]string{})
1111
)
1212

13-
const (
14-
StrategyMemory = "memory"
15-
StrategyDisk = "disk"
16-
StrategyOverflow = "overflow"
17-
)
18-
1913
type Buffer interface {
2014

2115
// Len returns the number of metrics currently in the buffer.
@@ -37,9 +31,9 @@ type Buffer interface {
3731
Reject([]telegraf.Metric)
3832
}
3933

40-
// BufferMetrics holds common metrics used for buffer implementations.
34+
// BufferStats holds common metrics used for buffer implementations.
4135
// Implementations of Buffer should embed this struct in them.
42-
type BufferMetrics struct {
36+
type BufferStats struct {
4337
MetricsAdded selfstat.Stat
4438
MetricsWritten selfstat.Stat
4539
MetricsDropped selfstat.Stat
@@ -51,26 +45,28 @@ type BufferMetrics struct {
5145
func NewBuffer(name string, alias string, capacity int, strategy string, path string) Buffer {
5246
bm := NewBufferMetrics(name, alias, capacity)
5347

54-
if strategy == StrategyDisk {
48+
switch strategy {
49+
case "", "memory":
50+
return NewMemoryBuffer(capacity, bm)
51+
case "disk":
5552
return NewDiskBuffer(name, capacity, path, bm)
56-
} else if strategy == StrategyOverflow {
53+
case "overflow":
5754
// todo implementme
5855
// todo log currently unimplemented
5956
return NewMemoryBuffer(capacity, bm)
60-
} else if strategy == StrategyMemory || strategy == "" {
61-
return NewMemoryBuffer(capacity, bm)
6257
}
58+
6359
// todo log invalid buffer strategy configuration provided, falling back to memory
6460
return NewMemoryBuffer(capacity, bm)
6561
}
6662

67-
func NewBufferMetrics(name string, alias string, capacity int) BufferMetrics {
63+
func NewBufferMetrics(name string, alias string, capacity int) BufferStats {
6864
tags := map[string]string{"output": name}
6965
if alias != "" {
7066
tags["alias"] = alias
7167
}
7268

73-
bm := BufferMetrics{
69+
bm := BufferStats{
7470
MetricsAdded: selfstat.Register(
7571
"write",
7672
"metrics_added",
@@ -102,17 +98,17 @@ func NewBufferMetrics(name string, alias string, capacity int) BufferMetrics {
10298
return bm
10399
}
104100

105-
func (b *BufferMetrics) metricAdded() {
101+
func (b *BufferStats) metricAdded() {
106102
b.MetricsAdded.Incr(1)
107103
}
108104

109-
func (b *BufferMetrics) metricWritten(metric telegraf.Metric) {
105+
func (b *BufferStats) metricWritten(metric telegraf.Metric) {
110106
AgentMetricsWritten.Incr(1)
111107
b.MetricsWritten.Incr(1)
112108
metric.Accept()
113109
}
114110

115-
func (b *BufferMetrics) metricDropped(metric telegraf.Metric) {
111+
func (b *BufferStats) metricDropped(metric telegraf.Metric) {
116112
AgentMetricsDropped.Incr(1)
117113
b.MetricsDropped.Incr(1)
118114
metric.Reject()

models/buffer_disk.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import (
1010
)
1111

1212
type DiskBuffer struct {
13-
BufferMetrics
13+
BufferStats
1414

1515
walFile *wal.Log
1616
}
1717

18-
func NewDiskBuffer(name string, capacity int, path string, metrics BufferMetrics) *DiskBuffer {
18+
func NewDiskBuffer(name string, capacity int, path string, stats BufferStats) *DiskBuffer {
1919
// todo capacity
2020
walFile, err := wal.Open(path+"/"+name, nil)
2121
if err != nil {
2222
return nil // todo error handling
2323
}
2424
return &DiskBuffer{
25-
BufferMetrics: metrics,
26-
walFile: walFile,
25+
BufferStats: stats,
26+
walFile: walFile,
2727
}
2828
}
2929

models/buffer_mem.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// MemoryBuffer stores metrics in a circular buffer.
1010
type MemoryBuffer struct {
1111
sync.Mutex
12-
BufferMetrics
12+
BufferStats
1313

1414
buf []telegraf.Metric
1515
first int // index of the first/oldest metric
@@ -21,14 +21,14 @@ type MemoryBuffer struct {
2121
batchSize int // number of metrics currently in the batch
2222
}
2323

24-
func NewMemoryBuffer(capacity int, metrics BufferMetrics) *MemoryBuffer {
24+
func NewMemoryBuffer(capacity int, stats BufferStats) *MemoryBuffer {
2525
return &MemoryBuffer{
26-
BufferMetrics: metrics,
27-
buf: make([]telegraf.Metric, capacity),
28-
first: 0,
29-
last: 0,
30-
size: 0,
31-
cap: capacity,
26+
BufferStats: stats,
27+
buf: make([]telegraf.Metric, capacity),
28+
first: 0,
29+
last: 0,
30+
size: 0,
31+
cap: capacity,
3232
}
3333
}
3434

models/running_output.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type OutputConfig struct {
3838
NamePrefix string
3939
NameSuffix string
4040

41-
BufferStrategy string
42-
BufferFileDirectory string
41+
BufferStrategy string
42+
BufferDirectory string
4343
}
4444

4545
// RunningOutput contains the output configuration
@@ -100,7 +100,7 @@ func NewRunningOutput(
100100
}
101101

102102
ro := &RunningOutput{
103-
buffer: NewBuffer(config.Name, config.Alias, bufferLimit, config.BufferStrategy, config.BufferFileDirectory),
103+
buffer: NewBuffer(config.Name, config.Alias, bufferLimit, config.BufferStrategy, config.BufferDirectory),
104104
BatchReady: make(chan time.Time, 1),
105105
Output: output,
106106
Config: config,

0 commit comments

Comments
 (0)