From 491b92aa19e894b93bc2aa8d596809b5bfa2ae0a Mon Sep 17 00:00:00 2001 From: Greg Schrock Date: Thu, 11 Sep 2025 12:18:46 -0400 Subject: [PATCH] t128_tank: stream from the beginning if parsing the index fails I95-62311 #time 4h --- plugins/inputs/t128_tank/reader.go | 4 +--- plugins/inputs/t128_tank/t128_tank_test.go | 28 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/t128_tank/reader.go b/plugins/inputs/t128_tank/reader.go index 7cf65090fe4ba..98b8f706a7c30 100644 --- a/plugins/inputs/t128_tank/reader.go +++ b/plugins/inputs/t128_tank/reader.go @@ -128,9 +128,7 @@ func (r *Reader) Run(mainCtx context.Context) { var observedValue uint64 lastIndex, err := r.getIndex(r.indexPath, r.defaultIndex) if err != nil { - r.log.Errorf("Error in get index %v", err) - readCtxCancel() - return + r.log.Infof("Failed to get index %v", err) } nextSaveCheck := time.NewTicker(2 * time.Second) defer func() { diff --git a/plugins/inputs/t128_tank/t128_tank_test.go b/plugins/inputs/t128_tank/t128_tank_test.go index 061d72a604675..96b57a02b9caf 100644 --- a/plugins/inputs/t128_tank/t128_tank_test.go +++ b/plugins/inputs/t128_tank/t128_tank_test.go @@ -30,6 +30,7 @@ func TestT128TankReader(t *testing.T) { Name string IndexFile string IndexFileContent string + IndexFileEmpty bool Topic string PortNumber int ServerAddress string @@ -38,7 +39,7 @@ func TestT128TankReader(t *testing.T) { ExpectedMetrics []IndexedMessage }{ { - Name: "index file with no value", + Name: "index file does not exist", Topic: "events", PortNumber: 11011, ServerAddress: "127.0.0.2", @@ -54,6 +55,24 @@ func TestT128TankReader(t *testing.T) { }, }, }, + { + Name: "index file empty", + Topic: "events", + IndexFileEmpty: true, + PortNumber: 11011, + ServerAddress: "127.0.0.2", + DefaultIndex: StartIndex, + TankReadCommandContext: func(ctx context.Context, name string, arg ...string) *exec.Cmd { + cmd := exec.CommandContext(ctx, "echo", "seq=1:measurement,core=2,node=test-1,port=corp-dmz-p value=0i 1586886775") + return cmd + }, + ExpectedMetrics: []IndexedMessage{ + { + Message: []byte("measurement,core=2,node=test-1,port=corp-dmz-p value=0i 1586886775"), + Index: index{value: 1}, + }, + }, + }, { Name: "index file with value", IndexFileContent: "150", @@ -87,7 +106,7 @@ func TestT128TankReader(t *testing.T) { var wg sync.WaitGroup indexFileName := strings.ReplaceAll(testcase.Name, " ", "_") plugin.IndexFile = path.Join(t.TempDir(), fmt.Sprintf("%s.index", indexFileName)) - if testcase.IndexFileContent != "" { + if testcase.IndexFileContent != "" || testcase.IndexFileEmpty { err := os.WriteFile(plugin.IndexFile, []byte(testcase.IndexFileContent), 0755) assert.NoError(t, err) } @@ -116,9 +135,12 @@ func TestT128TankReader(t *testing.T) { cancel() + if len(testcase.ExpectedMetrics) > 0 { + assert.NotNil(t, receivedMessages) + } + if len(testcase.ExpectedMetrics) > 0 && receivedMessages != nil { assert.Equal(t, testcase.ExpectedMetrics, receivedMessages) - } }) }