Skip to content

Commit

Permalink
Merge pull request #15 from 128technology/gschrock/merge-upstream-1.14
Browse files Browse the repository at this point in the history
Merge Upstream 1.14.5
  • Loading branch information
gregschrock committed Jul 1, 2020
2 parents 40a7e28 + 7318c05 commit 6403210
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 23 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v1.14.5 [2020-06-30]

### Bugfixes

- [#7686](https://github.com/influxdata/telegraf/pull/7686): Improve the performance of the procstat input.
- [#7658](https://github.com/influxdata/telegraf/pull/7658): Fix ping exit code handling on non-Linux.
- [#7718](https://github.com/influxdata/telegraf/pull/7718): Skip overs errors in the output of the sensors command.
- [#7748](https://github.com/influxdata/telegraf/issues/7748): Prevent startup when tags have incorrect type in configuration file.
- [#7699](https://github.com/influxdata/telegraf/issues/7699): Fix panic with GJSON multiselect query in json parser.
- [#7754](https://github.com/influxdata/telegraf/issues/7754): Allow any key usage type on x509 certificate.
- [#7705](https://github.com/influxdata/telegraf/issues/7705): Allow histograms and summary types without buckets or quantiles in prometheus_client output.

## v1.14.4 [2020-06-09]

#### Bugfixes
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ func buildAggregator(name string, tbl *ast.Table) (*models.AggregatorConfig, err
var err error
conf.DropOriginal, err = strconv.ParseBool(b.Value)
if err != nil {
log.Printf("Error parsing boolean value for %s: %s\n", name, err)
return nil, fmt.Errorf("error parsing boolean value for %s: %s", name, err)
}
}
}
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func buildAggregator(name string, tbl *ast.Table) (*models.AggregatorConfig, err
if node, ok := tbl.Fields["tags"]; ok {
if subtbl, ok := node.(*ast.Table); ok {
if err := toml.UnmarshalTable(subtbl, conf.Tags); err != nil {
log.Printf("Could not parse tags for input %s\n", name)
return nil, fmt.Errorf("could not parse tags for input %s", name)
}
}
}
Expand Down Expand Up @@ -1165,7 +1165,7 @@ func buildProcessor(name string, tbl *ast.Table) (*models.ProcessorConfig, error
var err error
conf.Order, err = strconv.ParseInt(b.Value, 10, 64)
if err != nil {
log.Printf("Error parsing int value for %s: %s\n", name, err)
return nil, fmt.Errorf("error parsing int value for %s: %s", name, err)
}
}
}
Expand Down Expand Up @@ -1380,7 +1380,7 @@ func buildInput(name string, tbl *ast.Table) (*models.InputConfig, error) {
if node, ok := tbl.Fields["tags"]; ok {
if subtbl, ok := node.(*ast.Table); ok {
if err := toml.UnmarshalTable(subtbl, cp.Tags); err != nil {
log.Printf("E! Could not parse tags for input %s\n", name)
return nil, fmt.Errorf("could not parse tags for input %s\n", name)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ require (
github.com/stretchr/testify v1.4.0
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 // indirect
github.com/tidwall/gjson v1.3.0
github.com/tidwall/gjson v1.6.0
github.com/vishvananda/netlink v0.0.0-20171020171820-b2de5d10e38e // indirect
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect
github.com/vjeantet/grok v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOs
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw=
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 h1:mujcChM89zOHwgZBBNr5WZ77mBXP1yR+gLThGCYZgAg=
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0=
github.com/tidwall/gjson v1.3.0 h1:kfpsw1W3trbg4Xm6doUtqSl9+LhLB6qJ9PkltVAQZYs=
github.com/tidwall/gjson v1.3.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
Expand Down
14 changes: 14 additions & 0 deletions internal/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ func CombinedOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error) {
return b.Bytes(), err
}

// StdOutputTimeout runs the given command with the given timeout and
// returns the output of stdout.
// If the command times out, it attempts to kill the process.
func StdOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error) {
var b bytes.Buffer
c.Stdout = &b
c.Stderr = nil
if err := c.Start(); err != nil {
return nil, err
}
err := WaitTimeout(c, timeout)
return b.Bytes(), err
}

// RunTimeout runs the given command with the given timeout.
// If the command times out, it attempts to kill the process.
func RunTimeout(c *exec.Cmd, timeout time.Duration) error {
Expand Down
15 changes: 13 additions & 2 deletions plugins/inputs/ping/ping_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) {

out, err := p.pingHost(p.Binary, 60.0, p.args(u, runtime.GOOS)...)
if err != nil {
// Some implementations of ping return a 1 exit code on
// Some implementations of ping return a non-zero exit code on
// timeout, if this occurs we will not exit and try to parse
// the output.
// Linux iputils-ping returns 1, BSD-derived ping returns 2.
status := -1
if exitError, ok := err.(*exec.ExitError); ok {
if ws, ok := exitError.Sys().(syscall.WaitStatus); ok {
Expand All @@ -32,7 +33,17 @@ func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) {
}
}

if status != 1 {
var timeoutExitCode int
switch runtime.GOOS {
case "freebsd", "netbsd", "openbsd", "darwin":
timeoutExitCode = 2
case "linux":
timeoutExitCode = 1
default:
timeoutExitCode = 1
}

if status != timeoutExitCode {
// Combine go err + stderr output
out = strings.TrimSpace(out)
if len(out) > 0 {
Expand Down
13 changes: 13 additions & 0 deletions plugins/inputs/procstat/native_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ func (pg *NativeFinder) PidFile(path string) ([]PID, error) {
return pids, nil

}

func (pg *NativeFinder) FastProcessList() ([]*process.Process, error) {
pids, err := process.Pids()
if err != nil {
return nil, err
}

result := make([]*process.Process, len(pids))
for i, pid := range pids {
result[i] = &process.Process{Pid: pid}
}
return result, nil
}
6 changes: 2 additions & 4 deletions plugins/inputs/procstat/native_finder_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package procstat

import (
"regexp"

"github.com/shirou/gopsutil/process"
)

//Pattern matches on the process name
Expand All @@ -15,7 +13,7 @@ func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) {
if err != nil {
return pids, err
}
procs, err := process.Processes()
procs, err := pg.FastProcessList()
if err != nil {
return pids, err
}
Expand All @@ -40,7 +38,7 @@ func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) {
if err != nil {
return pids, err
}
procs, err := process.Processes()
procs, err := pg.FastProcessList()
if err != nil {
return pids, err
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/procstat/native_finder_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) {
if err != nil {
return pids, err
}
procs, err := process.Processes()
procs, err := pg.FastProcessList()
if err != nil {
return pids, err
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/sensors/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *Sensors) parse(acc telegraf.Accumulator) error {
fields := map[string]interface{}{}
chip := ""
cmd := execCommand(s.path, "-A", "-u")
out, err := internal.CombinedOutputTimeout(cmd, s.Timeout.Duration)
out, err := internal.StdOutputTimeout(cmd, s.Timeout.Duration)
if err != nil {
return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out))
}
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/x509_cert/x509_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (c *X509Cert) Gather(acc telegraf.Accumulator) error {
// name validation against the URL hostname.
opts := x509.VerifyOptions{
Intermediates: x509.NewCertPool(),
KeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageAny},
}
if i == 0 {
if c.ServerName == "" {
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/x509_cert/x509_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func TestGatherLocal(t *testing.T) {
{name: "not a certificate", mode: 0640, content: "test", error: true},
{name: "wrong certificate", mode: 0640, content: wrongCert, error: true},
{name: "correct certificate", mode: 0640, content: pki.ReadServerCert()},
{name: "correct client certificate", mode: 0640, content: pki.ReadClientCert()},
{name: "correct certificate and extra trailing space", mode: 0640, content: pki.ReadServerCert() + " "},
{name: "correct certificate and extra leading space", mode: 0640, content: " " + pki.ReadServerCert()},
{name: "correct multiple certificates", mode: 0640, content: pki.ReadServerCert() + pki.ReadCACert()},
Expand Down
59 changes: 59 additions & 0 deletions plugins/outputs/prometheus_client/prometheus_client_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ func TestMetricVersion2(t *testing.T) {
# HELP cpu_time_idle Telegraf collected metric
# TYPE cpu_time_idle untyped
cpu_time_idle{host="example.org"} 42
`),
},
{
name: "summary no quantiles",
output: &PrometheusClient{
Listen: ":0",
MetricVersion: 2,
CollectorsExclude: []string{"gocollector", "process"},
Path: "/metrics",
Log: Logger,
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"prometheus",
map[string]string{},
map[string]interface{}{
"rpc_duration_seconds_sum": 1.7560473e+07,
"rpc_duration_seconds_count": 2693,
},
time.Unix(0, 0),
telegraf.Summary,
),
},
expected: []byte(`
# HELP rpc_duration_seconds Telegraf collected metric
# TYPE rpc_duration_seconds summary
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
`),
},
{
Expand Down Expand Up @@ -239,6 +267,37 @@ cpu_usage_idle_bucket{cpu="cpu1",le="100"} 20
cpu_usage_idle_bucket{cpu="cpu1",le="+Inf"} 20
cpu_usage_idle_sum{cpu="cpu1"} 2000
cpu_usage_idle_count{cpu="cpu1"} 20
`),
},
{
name: "histogram no buckets",
output: &PrometheusClient{
Listen: ":0",
MetricVersion: 2,
CollectorsExclude: []string{"gocollector", "process"},
Path: "/metrics",
Log: Logger,
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"cpu",
map[string]string{
"cpu": "cpu1",
},
map[string]interface{}{
"usage_idle_sum": 2000.0,
"usage_idle_count": 20.0,
},
time.Unix(0, 0),
telegraf.Histogram,
),
},
expected: []byte(`
# HELP cpu_usage_idle Telegraf collected metric
# TYPE cpu_usage_idle histogram
cpu_usage_idle_bucket{cpu="cpu1",le="+Inf"} 20
cpu_usage_idle_sum{cpu="cpu1"} 2000
cpu_usage_idle_count{cpu="cpu1"} 20
`),
},
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/serializers/prometheus/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,6 @@ func (c *Collection) GetProto() []*dto.MetricFamily {
})
}

if len(buckets) == 0 {
continue
}

m.Histogram = &dto.Histogram{
Bucket: buckets,
SampleCount: proto.Uint64(metric.Histogram.Count),
Expand All @@ -464,10 +460,6 @@ func (c *Collection) GetProto() []*dto.MetricFamily {
})
}

if len(quantiles) == 0 {
continue
}

m.Summary = &dto.Summary{
Quantile: quantiles,
SampleCount: proto.Uint64(metric.Summary.Count),
Expand Down
26 changes: 26 additions & 0 deletions plugins/serializers/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ http_requests_total{code="400",method="post"} 3
telegraf.Histogram,
),
expected: []byte(`
# HELP http_request_duration_seconds Telegraf collected metric
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="+Inf"} 144320
http_request_duration_seconds_sum 53423
http_request_duration_seconds_count 144320
`),
},
{
Expand Down Expand Up @@ -645,6 +650,27 @@ cpu_time_user{cpu="cpu0"} 92904.33
cpu_time_user{cpu="cpu1"} 96912.57
cpu_time_user{cpu="cpu2"} 96034.08
cpu_time_user{cpu="cpu3"} 94148
`),
},
{
name: "summary with no quantile",
metrics: []telegraf.Metric{
testutil.MustMetric(
"prometheus",
map[string]string{},
map[string]interface{}{
"rpc_duration_seconds_sum": 1.7560473e+07,
"rpc_duration_seconds_count": 2693,
},
time.Unix(0, 0),
telegraf.Summary,
),
},
expected: []byte(`
# HELP rpc_duration_seconds Telegraf collected metric
# TYPE rpc_duration_seconds summary
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
`),
},
}
Expand Down

0 comments on commit 6403210

Please sign in to comment.