Skip to content

Commit 57eba92

Browse files
authored
Merge pull request #542 from nokia/fix409
properly set deleted tags when using influxdb output
2 parents cc35c12 + 44eee4c commit 57eba92

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pkg/outputs/influxdb_output/influxdb_cache.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ func (i *influxDBOutput) stopCache() {
4040
func (i *influxDBOutput) runCache(ctx context.Context, name string) {
4141
for {
4242
select {
43+
case <-ctx.Done():
44+
return
4345
case <-i.done:
4446
return
4547
case <-i.cacheTicker.C:
4648
if i.Cfg.Debug {
4749
i.logger.Printf("cache timer tick")
4850
}
49-
i.readCache(ctx, name)
51+
i.readCache(ctx)
5052
}
5153
}
5254
}
5355

54-
func (i *influxDBOutput) readCache(ctx context.Context, name string) {
56+
func (i *influxDBOutput) readCache(ctx context.Context) {
5557
notifications, err := i.gnmiCache.ReadAll()
5658
if err != nil {
5759
i.logger.Printf("failed to read from cache: %v", err)
@@ -85,6 +87,8 @@ func (i *influxDBOutput) readCache(ctx context.Context, name string) {
8587

8688
for _, ev := range events {
8789
select {
90+
case <-ctx.Done():
91+
return
8892
case <-i.reset:
8993
return
9094
case i.eventChan <- ev:

pkg/outputs/influxdb_output/influxdb_output.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ START:
346346
i.logger.Printf("worker-%d terminating...", idx)
347347
return
348348
case ev := <-i.eventChan:
349-
if len(ev.Values) == 0 || (len(ev.Deletes) == 0 && i.Cfg.DeleteTag != "") {
349+
if len(ev.Values) == 0 && len(ev.Deletes) == 0 {
350+
continue
351+
}
352+
if len(ev.Values) == 0 && i.Cfg.DeleteTag == "" {
350353
continue
351354
}
352355
for n, v := range ev.Values {
@@ -368,7 +371,7 @@ START:
368371
i.convertUints(ev)
369372
writer.WritePoint(influxdb2.NewPoint(ev.Name, ev.Tags, ev.Values, time.Unix(0, ev.Timestamp)))
370373
}
371-
374+
372375
if len(ev.Deletes) > 0 && i.Cfg.DeleteTag != "" {
373376
tags := make(map[string]string, len(ev.Tags))
374377
for k, v := range ev.Tags {
@@ -377,7 +380,7 @@ START:
377380
tags[i.Cfg.DeleteTag] = deleteTagValue
378381
values := make(map[string]any, len(ev.Deletes))
379382
for _, del := range ev.Deletes {
380-
values[del] = 0
383+
values[del] = ""
381384
}
382385
writer.WritePoint(influxdb2.NewPoint(ev.Name, tags, values, time.Unix(0, ev.Timestamp)))
383386
}

0 commit comments

Comments
 (0)