open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.92k stars 2.28k forks source link

[receiver/httpcheck] Add configuration option to prevent following redirections #34623

Open rogercoll opened 1 month ago

rogercoll commented 1 month ago

Component(s)

receiver/httpcheck

Is your feature request related to a problem? Please describe.

An HTTP endpoint can return either 307 or 308 as status code when it has been redirected. Let's say I want to monitor a temporal redirection (307) and act upon changes (e.g. end of redirection → 2xx).

For example, the http://wikipedia.com endpoint is redirected to the https://wikipedia.com but I don't want to ensure its reachability but its redirection. Receiver config:

        receivers:
          httpcheck:
            collection_interval: 180s
            targets:
              - endpoint: http://wikipedia.com
                method: GET

The default http client seems to be following redirects, thus getting a 2xx instead:

NumberDataPoints #1
Data point attributes:
     -> http.url: Str(http://wikipedia.com)
     -> http.status_code: Int(200)
     -> http.method: Str(GET)
     -> http.status_class: Str(2xx)
StartTimestamp: 2024-08-12 20:46:16.299435558 +0000 UTC
Timestamp: 2024-08-12 20:47:57.305112135 +0000 UTC
Value: 1
NumberDataPoints #2
Data point attributes:
     -> http.url: Str(http://wikipedia.com)
     -> http.status_code: Int(200)
     -> http.method: Str(GET)
     -> http.status_class: Str(3xx)
StartTimestamp: 2024-08-12 20:46:16.299435558 +0000 UTC
Timestamp: 2024-08-12 20:47:57.305112135 +0000 UTC
Value: 0

Describe the solution you'd like

A config option to define the maximum number of redirects or completely disable them by default.

NumberDataPoints #1
Data point attributes:
     -> http.url: Str(http://wikipedia.com)
     -> http.status_code: Int(200)
     -> http.method: Str(GET)
     -> http.status_class: Str(2xx)
StartTimestamp: 2024-08-12 20:46:16.299435558 +0000 UTC
Timestamp: 2024-08-12 20:47:57.305112135 +0000 UTC
Value: 0
NumberDataPoints #2
Data point attributes:
     -> http.url: Str(http://wikipedia.com)
     -> http.status_code: Int(200)
     -> http.method: Str(GET)
     -> http.status_class: Str(3xx)
StartTimestamp: 2024-08-12 20:46:16.299435558 +0000 UTC
Timestamp: 2024-08-12 20:47:57.305112135 +0000 UTC
Value: 1

For example, Elastic uses the max_redirects configuration options which defaults to 0 (so no redirects are followed, but the status of the redirect is reported)

Describe alternatives you've considered

Adding the configuration option in the confighttp

Additional context

No response

github-actions[bot] commented 1 month ago

Pinging code owners:

atoulme commented 1 month ago

Sounds good to me. Probably requires to be added to confighttp.

rogercoll commented 1 month ago

+1 to add the config option to confihttp (e.g max_redirects)

ref https://github.com/open-telemetry/opentelemetry-collector/issues/10870