fix x509 cert timeout issue (#8741)

This commit is contained in:
viperstars 2021-01-27 02:02:23 +08:00 committed by GitHub
parent 358633bc4d
commit eda1dbc4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -215,7 +215,7 @@ func (c *X509Cert) Gather(acc telegraf.Accumulator) error {
return nil
}
certs, err := c.getCert(u, c.Timeout.Duration*time.Second)
certs, err := c.getCert(u, c.Timeout.Duration)
if err != nil {
acc.AddError(fmt.Errorf("cannot get SSL cert '%s': %s", location, err.Error()))
}

View File

@ -350,6 +350,24 @@ func TestGatherCert(t *testing.T) {
assert.True(t, acc.HasMeasurement("x509_cert"))
}
func TestGatherCertMustNotTimeout(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
duration := time.Duration(15) * time.Second
m := &X509Cert{
Sources: []string{"https://www.influxdata.com:443"},
Timeout: internal.Duration{Duration: duration},
}
m.Init()
var acc testutil.Accumulator
err := m.Gather(&acc)
require.NoError(t, err)
require.Empty(t, acc.Errors)
assert.True(t, acc.HasMeasurement("x509_cert"))
}
func TestServerName(t *testing.T) {
tests := []struct {
name string