influxdata / influxdata/telegraf

inputs.http_response returns body_read_error (2) on timeout, instead of timeout

Open
#16,614 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
17.8k
Forks
5.8k
Avg merge
1d 20h
Merged PRs (30d)
161

Description

### Relevant telegraf.conf

```toml
[[inputs.http_response]]
alias = "crl_http_resp"
name_override = "crl_http_resp"
taginclude = ["host","server"]
tagexclude = ["result","method","status_code"]
urls = ["http://CENSORED.com"]
follow_redirects = true
tls_ca = "CENSORED.pem"
insecure_skip_verify = true
## HTTP Request Headers (all values must be strings)
[inputs.http_response.headers]
Accept = "*/*"

[[outputs.file]]
files = ["stdout"]
```

### Logs from Telegraf

```text
telegraf --once --test --debug --config test.conf
....
2025-03-11T13:34:01Z D! [agent] Initializing plugins
2025-03-11T13:34:01Z D! [agent] Connecting outputs
2025-03-11T13:34:01Z D! [agent] Attempting connection to [outputs.file]
2025-03-11T13:34:01Z D! [agent] Successfully connected to outputs.file
2025-03-11T13:34:01Z D! [agent] Starting service inputs
2025-03-11T13:34:06Z D! [inputs.http_response::crl_http_resp] Failed to read body of HTTP Response : context deadline exceeded (Client.Timeout or context cancellation while reading body)
2025-03-11T13:34:06Z D! [agent] Stopping service inputs
2025-03-11T13:34:06Z D! [agent] Input channel closed
2025-03-11T13:34:06Z I! [agent] Hang on, flushing any cached metrics before shutdown
crl_http_resp,host=telegrafhost_censored.com,server=http://CENSORED.com response_time=0.278541397,http_response_code=200i,result_type="body_read_error",result_code=2i,content_length=6227802i 1741700046000000000
2025-03-11T13:34:06Z D! [outputs.file] Wrote batch of 1 metrics in 52.502µs
2025-03-11T13:34:06Z D! [outputs.file] Buffer fullness: 0 / 10000 metrics
2025-03-11T13:34:06Z I! [agent] Stopping running outputs
2025-03-11T13:34:06Z D! [agent] Stopped Successfully
```

### System info

Telegraf 1.33.3

### Docker

_No response_

### Steps to reproduce

1. Use inputs.http_response plugin to fetch simple HTTP url
2. due to large body (7MB), default timeout of 5 seconds of the plugin is hit
3. Plugin outputs different result than timeout
...

### Expected behavior

Get result_type="timeout",result_code=4i

### Actual behavior

Get result_type="body_read_error",result_code=2i

### Additional info

Hi, this one is simple, the plugin has default timeout of 5 seconds, when it is hit (in this case due to large body of 7MB which takes some time to download), the below error is logged:

`2025-03-11T13:34:06Z D! [inputs.http_response::crl_http_resp] Failed to read body of HTTP Response : context deadline exceeded (Client.Timeout or context cancellation while reading body)`

And on output fields is written:

result_type="body_read_error",result_code=2i

Which corresponds to this from documentation:

body_read_error | 2 | The option response_string_match was used, but the plugin wasn't able to read the body of the response. Responses with empty bodies (like 3xx, HEAD, etc) will trigger this error. Or the option response_body_field was used and the content of the response body was not a valid utf-8. Or the size of the body of the response exceeded the response_body_max_size

Its likely this should be the correct output written:

result_type="timeout",result_code=4i

Which corresponds to this from the documentation:

timeout | 4 | The plugin timed out while awaiting the HTTP connection to complete

Contributor guide

Open the contributing guide

Research direction

Start at the inputs.http_response plugin and reproduce the timeout with the provided Telegraf configuration and a large response body. Trace how a context deadline exceeded while reading the body is classified; done means the metric reports result_type="timeout" and result_code=4i rather than body_read_error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.