Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/httpcheck] receiver should fail fast if endpoint with no scheme is provided #23020

Closed
andrzej-stencel opened this issue Jun 1, 2023 · 2 comments · Fixed by #23808
Closed
Assignees
Labels
enhancement New feature or request receiver/httpcheck HTTP Check receiver

Comments

@andrzej-stencel
Copy link
Member

andrzej-stencel commented Jun 1, 2023

Component(s)

receiver/httpcheck

Collector version

v0.78.0

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

If I configure the HTTP Check receiver with an endpoint URL without a scheme, the receiver does not fail, but instead produces the httpcheck.error metric on each scrape.

exporters:
  logging:
    verbosity: detailed

receivers:
  httpcheck:
    endpoint: opentelemetry.io

service:
  pipelines:
    metrics:
      exporters:
      - logging
      receivers:
      - httpcheck

Expected output:

$ otelcontribcol --config config.yaml
Error: invalid configuration: receivers::httpcheck: "endpoint" must be in the form of <scheme>://<hostname>:<port>: parse "opentelemetry.io": invalid URI for request
2023/06/01 23:48:58 collector server run finished with error: invalid configuration: receivers::httpcheck: "endpoint" must be in the form of <scheme>://<hostname>:<port>: parse "opentelemetry.io": invalid URI for request

Actual result:

$ otelcontribcol --config config.yaml
2023-06-01T23:21:00.657+0200    info    service/telemetry.go:104        Setting up own telemetry...
2023-06-01T23:21:00.657+0200    info    service/telemetry.go:127        Serving Prometheus metrics      {"address": ":8888", "level": "Basic"}
2023-06-01T23:21:00.657+0200    info    [email protected]/exporter.go:275        Development component. May change in the future.        {"kind": "exporter", "data_type": "metrics", "name": "logging"}
2023-06-01T23:21:00.658+0200    info    [email protected]/receiver.go:296        Development component. May change in the future.        {"kind": "receiver", "name": "httpcheck", "data_type": "metrics"}
2023-06-01T23:21:00.679+0200    info    service/service.go:131  Starting otelcontribcol...      {"Version": "0.78.0-dev", "NumCPU": 16}
2023-06-01T23:21:00.679+0200    info    extensions/extensions.go:30     Starting extensions...
2023-06-01T23:21:00.679+0200    info    service/service.go:148  Everything is ready. Begin running and processing data.
2023-06-01T23:21:03.680+0200    info    MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "logging", "resource metrics": 1, "metrics": 2, "data points": 6}
2023-06-01T23:21:03.680+0200    info    ResourceMetrics #0
Resource SchemaURL: 
ScopeMetrics #0
ScopeMetrics SchemaURL: 
InstrumentationScope otelcol/httpcheckreceiver 0.78.0-dev
Metric #0
Descriptor:
     -> Name: httpcheck.error
     -> Description: Records errors occurring during HTTP check.
     -> Unit: {error}
     -> DataType: Sum
     -> IsMonotonic: false
     -> AggregationTemporality: Cumulative
NumberDataPoints #0
Data point attributes:
     -> http.url: Str()
     -> error.message: Str(Get "": unsupported protocol scheme "")
StartTimestamp: 2023-06-01 21:21:00.658226525 +0000 UTC
Timestamp: 2023-06-01 21:21:03.6801654 +0000 UTC
Value: 1
Metric #1
Descriptor:
     -> Name: httpcheck.status
     -> Description: 1 if the check resulted in status_code matching the status_class, otherwise 0.
     -> Unit: 1
     -> DataType: Sum
     -> IsMonotonic: false
     -> AggregationTemporality: Cumulative
NumberDataPoints #0
Data point attributes:
     -> http.url: Str()
     -> http.status_code: Int(0)
     -> http.method: Str(GET)
     -> http.status_class: Str(1xx)
StartTimestamp: 2023-06-01 21:21:00.658226525 +0000 UTC
Timestamp: 2023-06-01 21:21:03.6801654 +0000 UTC
Value: 0
NumberDataPoints #1
Data point attributes:
     -> http.url: Str()
     -> http.status_code: Int(0)
     -> http.method: Str(GET)
     -> http.status_class: Str(2xx)
StartTimestamp: 2023-06-01 21:21:00.658226525 +0000 UTC
Timestamp: 2023-06-01 21:21:03.6801654 +0000 UTC
Value: 0
NumberDataPoints #2
Data point attributes:
     -> http.url: Str()
     -> http.status_code: Int(0)
     -> http.method: Str(GET)
     -> http.status_class: Str(3xx)
StartTimestamp: 2023-06-01 21:21:00.658226525 +0000 UTC
Timestamp: 2023-06-01 21:21:03.6801654 +0000 UTC
Value: 0
NumberDataPoints #3
Data point attributes:
     -> http.url: Str()
     -> http.status_code: Int(0)
     -> http.method: Str(GET)
     -> http.status_class: Str(4xx)
StartTimestamp: 2023-06-01 21:21:00.658226525 +0000 UTC
Timestamp: 2023-06-01 21:21:03.6801654 +0000 UTC
Value: 0
NumberDataPoints #4
Data point attributes:
     -> http.url: Str()
     -> http.status_code: Int(0)
     -> http.method: Str(GET)
     -> http.status_class: Str(5xx)
StartTimestamp: 2023-06-01 21:21:00.658226525 +0000 UTC
Timestamp: 2023-06-01 21:21:03.6801654 +0000 UTC
Value: 0
        {"kind": "exporter", "data_type": "metrics", "name": "logging"}

Describe the solution you'd like

The receiver should fail fast during configuration validation, saying that you need to provide a URL with a scheme.

Describe alternatives you've considered

No response

Additional context

There's already an error message prepared for this scenario in code, but it's not being used because the url.Parse function used in Validate() method does not fail on URLs without scheme. I believe we should use url.ParseRequestURI function instead.

@andrzej-stencel andrzej-stencel added enhancement New feature or request needs triage New item requiring triage labels Jun 1, 2023
@github-actions github-actions bot added the receiver/httpcheck HTTP Check receiver label Jun 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@codeboten
Copy link
Contributor

This enhancement makes sense to me, do you want to submit a PR for it @astencel-sumo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request receiver/httpcheck HTTP Check receiver
Projects
None yet
2 participants