Fix crash in lustre2 input plugin, when field name and value (#7967)

are not separated by whitespace, which happens when numbers grow large (#7966)

Co-authored-by: Oliver Mangold <o.mangold@gmail.com>
This commit is contained in:
omgold 2021-01-27 21:36:29 +01:00 committed by GitHub
parent fa16231770
commit 8707a2d847
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -15,6 +15,7 @@ package lustre2
import (
"io/ioutil"
"path/filepath"
"regexp"
"strconv"
"strings"
@ -367,6 +368,8 @@ func (l *Lustre2) GetLustreProcStats(fileglob string, wantedFields []*mapping, a
return err
}
fieldSplitter := regexp.MustCompile(`[ :]+`)
for _, file := range files {
/* Turn /proc/fs/lustre/obdfilter/<ost_name>/stats and similar
* into just the object store target name
@ -397,7 +400,11 @@ func (l *Lustre2) GetLustreProcStats(fileglob string, wantedFields []*mapping, a
if len(line) < 1 {
continue
}
parts := strings.Fields(line)
parts := fieldSplitter.Split(line, -1)
if len(parts[0]) == 0 {
parts = parts[1:]
}
var fields map[string]interface{}
fields, ok := l.allFields[tags{name, jobid}]
@ -408,7 +415,7 @@ func (l *Lustre2) GetLustreProcStats(fileglob string, wantedFields []*mapping, a
for _, wanted := range wantedFields {
var data uint64
if strings.TrimSuffix(parts[0], ":") == wanted.inProc {
if parts[0] == wanted.inProc {
wantedField := wanted.field
// if not set, assume field[1]. Shouldn't be field[0], as
// that's a string

View File

@ -47,7 +47,7 @@ const obdfilterJobStatsContents = `job_stats:
- job_id: cluster-testjob1
snapshot_time: 1461772761
read_bytes: { samples: 1, unit: bytes, min: 4096, max: 4096, sum: 4096 }
write_bytes: { samples: 25, unit: bytes, min: 1048576, max: 1048576, sum: 26214400 }
write_bytes: { samples: 25, unit: bytes, min: 1048576, max:16777216, sum: 26214400 }
getattr: { samples: 0, unit: reqs }
setattr: { samples: 0, unit: reqs }
punch: { samples: 1, unit: reqs }
@ -259,7 +259,7 @@ func TestLustre2GeneratesJobstatsMetrics(t *testing.T) {
"jobstats_read_bytes": uint64(4096),
"jobstats_write_calls": uint64(25),
"jobstats_write_min_size": uint64(1048576),
"jobstats_write_max_size": uint64(1048576),
"jobstats_write_max_size": uint64(16777216),
"jobstats_write_bytes": uint64(26214400),
"jobstats_ost_getattr": uint64(0),
"jobstats_ost_setattr": uint64(0),