@@ -58,9 +58,8 @@ type Output struct {
58
58
Config Config
59
59
BatchConf client.BatchPointsConfig
60
60
61
- logger logrus.FieldLogger
62
- semaphoreCh chan struct {}
63
- fieldKinds map [string ]FieldKind
61
+ logger logrus.FieldLogger
62
+ fieldKinds map [string ]FieldKind
64
63
}
65
64
66
65
// New returns new influxdb output
@@ -87,11 +86,10 @@ func newOutput(params output.Params) (*Output, error) {
87
86
logger : params .Logger .WithFields (logrus.Fields {
88
87
"output" : "InfluxDBv1" ,
89
88
}),
90
- Client : cl ,
91
- Config : conf ,
92
- BatchConf : batchConf ,
93
- semaphoreCh : make (chan struct {}, conf .ConcurrentWrites .Int64 ),
94
- fieldKinds : fldKinds ,
89
+ Client : cl ,
90
+ Config : conf ,
91
+ BatchConf : batchConf ,
92
+ fieldKinds : fldKinds ,
95
93
}, err
96
94
}
97
95
@@ -178,12 +176,15 @@ func (o *Output) Start() error {
178
176
// usually means we're either a non-admin user to an existing DB or connecting over UDP.
179
177
_ , err := o .Client .Query (client .NewQuery ("CREATE DATABASE " + o .BatchConf .Database , "" , "" ))
180
178
if err != nil {
181
- o .logger .WithError (err ).Debug ("InfluxDB: Couldn't create database; most likely harmless" )
179
+ o .logger .WithError (err ).Debug ("Couldn't create database; most likely harmless" )
182
180
}
183
181
184
- pf , err := output .NewPeriodicFlusher (time .Duration (o .Config .PushInterval .Duration ), o .flushMetrics )
182
+ pf , err := output .NewAsyncPeriodicFlusher (
183
+ time .Duration (o .Config .PushInterval .Duration ),
184
+ int (o .Config .ConcurrentWrites .Int64 ),
185
+ o .flushMetrics )
185
186
if err != nil {
186
- return err //nolint:wrapcheck
187
+ return err
187
188
}
188
189
o .logger .Debug ("Started!" )
189
190
o .periodicFlusher = pf
@@ -201,11 +202,11 @@ func (o *Output) Stop() error {
201
202
202
203
func (o * Output ) flushMetrics () {
203
204
samples := o .GetBufferedSamples ()
205
+ if len (samples ) < 1 {
206
+ o .logger .Debug ("Any buffered samples, skipping the flush operation" )
207
+ return
208
+ }
204
209
205
- o .semaphoreCh <- struct {}{}
206
- defer func () {
207
- <- o .semaphoreCh
208
- }()
209
210
o .logger .Debug ("Committing..." )
210
211
o .logger .WithField ("samples" , len (samples )).Debug ("Writing..." )
211
212
@@ -219,7 +220,13 @@ func (o *Output) flushMetrics() {
219
220
startTime := time .Now ()
220
221
if err := o .Client .Write (batch ); err != nil {
221
222
o .logger .WithError (err ).Error ("Couldn't write stats" )
223
+ return
222
224
}
223
225
t := time .Since (startTime )
224
226
o .logger .WithField ("t" , t ).Debug ("Batch written!" )
227
+
228
+ if t > time .Duration (o .Config .PushInterval .Duration ) {
229
+ o .logger .WithField ("t" , t ).
230
+ Warn ("The flush operation took higher than the expected set push interval. If you see this message multiple times then the setup or configuration need to be adjusted to achieve a sustainable rate." ) //nolint:lll
231
+ }
225
232
}
0 commit comments