@@ -142,12 +142,11 @@ func (r *Agent) Run(ctx context.Context, recipe recipe.Recipe) (run Run) {
142142 }
143143
144144 for _ , sr := range recipe .Sinks {
145- sink , err := r .setupSink (ctx , sr , stream , recipe )
145+ err := r .setupSink (ctx , sr , stream , recipe )
146146 if err != nil {
147147 run .Error = errors .Wrap (err , "failed to setup sink" )
148148 return
149149 }
150- defer sink .Close ()
151150 }
152151
153152 // to gather total number of records extracted
@@ -235,14 +234,15 @@ func (r *Agent) setupProcessor(ctx context.Context, pr recipe.PluginRecipe, str
235234 return
236235}
237236
238- func (r * Agent ) setupSink (ctx context.Context , sr recipe.PluginRecipe , stream * stream , recipe recipe.Recipe ) (sink plugins.Syncer , err error ) {
237+ func (r * Agent ) setupSink (ctx context.Context , sr recipe.PluginRecipe , stream * stream , recipe recipe.Recipe ) (err error ) {
238+ var sink plugins.Syncer
239+
239240 if sink , err = r .sinkFactory .Get (sr .Name ); err != nil {
240- return nil , errors .Wrapf (err , "could not find sink \" %s\" " , sr .Name )
241+ return errors .Wrapf (err , "could not find sink \" %s\" " , sr .Name )
241242 }
242243 if err = sink .Init (ctx , sr .Config ); err != nil {
243- return nil , errors .Wrapf (err , "could not initiate sink \" %s\" " , sr .Name )
244+ return errors .Wrapf (err , "could not initiate sink \" %s\" " , sr .Name )
244245 }
245-
246246 retryNotification := func (e error , d time.Duration ) {
247247 r .logger .Info (
248248 fmt .Sprintf ("retrying sink in %d" , d ),
@@ -255,21 +255,28 @@ func (r *Agent) setupSink(ctx context.Context, sr recipe.PluginRecipe, stream *s
255255 return err
256256 }, retryNotification )
257257
258- // error (after exhausted retries) will just be skipped and logged
258+ var success bool
259259 if err != nil {
260+ // once it reaches here, it means that the retry has been exhausted and still got error
261+ success = false
260262 r .logger .Error ("error running sink" , "sink" , sr .Name , "error" , err .Error ())
261- if ! r .stopOnSinkError {
262- err = nil
263- }
264- return err
263+ } else {
264+ success = true
265+ r .logger .Info ("Successfully published record" , "sink" , sr .Name , "recipe" , recipe .Name )
265266 }
266- r .logger .Info ("Successfully published record" , "sink" , sr .Name , "recipe" , recipe .Name )
267267
268+ r .monitor .RecordPlugin (recipe .Name , sr .Name , "sink" , success )
269+
270+ if ! r .stopOnSinkError {
271+ err = nil
272+ }
268273 // TODO: create a new error to signal stopping stream.
269274 // returning nil so stream wont stop.
270275 return err
271276 }, defaultBatchSize )
272277
278+ //TODO: the sink closes even though some records remain unpublished
279+ //TODO: once fixed, file sink's Close needs to close *File
273280 stream .onClose (func () {
274281 if err = sink .Close (); err != nil {
275282 r .logger .Warn ("error closing sink" , "sink" , sr .Name , "error" , err )
0 commit comments