fix(inputs.cgroup): Escape backslashes (#14187)
This commit is contained in:
parent
8c35dddc10
commit
fa1ba97540
|
|
@ -109,6 +109,8 @@ func (g *CGroup) generateDirs(list chan<- pathInfo) {
|
|||
}
|
||||
|
||||
func (g *CGroup) generateFiles(dir string, list chan<- pathInfo) {
|
||||
dir = strings.Replace(dir, "\\", "\\\\", -1)
|
||||
|
||||
defer close(list)
|
||||
for _, file := range g.Files {
|
||||
// getting all file paths that match the pattern 'dir + file'
|
||||
|
|
|
|||
|
|
@ -416,3 +416,29 @@ func TestCgroupStatistics_8(t *testing.T) {
|
|||
require.NoError(t, acc.GatherError(cg.Gather))
|
||||
require.Len(t, cg.logged, 1)
|
||||
}
|
||||
|
||||
func TestCgroupEscapeDir(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
var cg = &CGroup{
|
||||
Paths: []string{"testdata/backslash/machine-qemu\x2d1\x2d*"},
|
||||
Files: []string{"cpu.stat"},
|
||||
logged: make(map[string]bool),
|
||||
}
|
||||
|
||||
expected := []telegraf.Metric{
|
||||
metric.New(
|
||||
"cgroup",
|
||||
map[string]string{"path": `testdata/backslash/machine-qemu-1-ubuntu`},
|
||||
map[string]interface{}{
|
||||
"cpu.stat.core_sched.force_idle_usec": int64(0),
|
||||
"cpu.stat.system_usec": int64(103537582650),
|
||||
"cpu.stat.usage_usec": int64(614953149468),
|
||||
"cpu.stat.user_usec": int64(511415566817),
|
||||
},
|
||||
time.Unix(0, 0),
|
||||
),
|
||||
}
|
||||
|
||||
require.NoError(t, acc.GatherError(cg.Gather))
|
||||
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
usage_usec 614953149468
|
||||
user_usec 511415566817
|
||||
system_usec 103537582650
|
||||
core_sched.force_idle_usec 0
|
||||
Loading…
Reference in New Issue