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

haproxy receiver fails to collect data via unix socket when "stat" data exceeds 4k #32652

Closed
ubcharron opened this issue Apr 23, 2024 · 2 comments · Fixed by #32661
Closed

haproxy receiver fails to collect data via unix socket when "stat" data exceeds 4k #32652

ubcharron opened this issue Apr 23, 2024 · 2 comments · Fixed by #32661
Assignees
Labels
bug Something isn't working receiver/haproxy

Comments

@ubcharron
Copy link

Component(s)

receiver/haproxy

What happened?

Description

When receiving stats via unix socket, the haproxy receiver only captures up to 4096 bytes: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.99.0/receiver/haproxyreceiver/scraper.go#L73

If the actual csv data is bigger than this, otel collector will return the following error and produce no metrics:

2024-04-23T19:34:33.325Z        error        scraperhelper/scrapercontroller.go:197        Error scraping metrics        {"kind": "receiver", "name": "haproxy", "data_type": "metrics", "error": "error reading stats: record on line 21: wrong number of fields", "scraper": "haproxy"}

Steps to Reproduce

Setup an haproxy that listens on a unix socket for stats, and has enough frontends/backends/listeners to make its "stat" bigger than 4096 bytes. Configure otel collector to collect those stats via the unix socket (see below for config).

Expected Result

Successfully capture stats

Actual Result

Generates the following error:

2024-04-23T19:34:33.325Z        error        scraperhelper/scrapercontroller.go:197        Error scraping metrics        {"kind": "receiver", "name": "haproxy", "data_type": "metrics", "error": "error reading stats: record on line 21: wrong number of fields", "scraper": "haproxy"}

Collector version

0.99.0

Environment information

Environment

OS: Ubuntu 20.04.6 LTS

OpenTelemetry Collector configuration

receivers:
  haproxy:
    endpoint: /run/haproxy/admin.sock
    collection_interval: 10s

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    metrics:
      receivers: [haproxy]
      exporters: [debug]

Log output

2024-04-23T19:48:13.794Z        error   scraperhelper/scrapercontroller.go:197  Error scraping metrics  {"kind": "receiver", "name": "haproxy", "data_type": "metrics", "error": "error reading stats: record on line 21: wrong number of fields", "scraper": "haproxy"}
go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).scrapeMetricsAndReport
        go.opentelemetry.io/collector/receiver@v0.99.0/scraperhelper/scrapercontroller.go:197
go.opentelemetry.io/collector/receiver/scraperhelper.(*controller).startScraping.func1
        go.opentelemetry.io/collector/receiver@v0.99.0/scraperhelper/scrapercontroller.go:169
2024-04-23T19:48:13.794Z        info    MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "debug", "resource metrics": 0, "metrics": 0, "data points": 0}

Additional context

One of our haproxies has 43,279 bytes (178 lines) of "stats" data:

echo 'show stat' | socat /var/lib/haproxy/stats stdio | wc
    178     444   43279

And the 4096th byte is in the middle of line 21:

echo 'show stat' | socat /var/lib/haproxy/stats stdio | head -c 4096 | wc -l
20
@ubcharron ubcharron added bug Something isn't working needs triage New item requiring triage labels Apr 23, 2024
Copy link
Contributor

Pinging code owners:

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

@atoulme
Copy link
Contributor

atoulme commented Apr 24, 2024

Alright, I'll work on it. Thanks for the report.

@atoulme atoulme removed the needs triage New item requiring triage label Apr 24, 2024
@atoulme atoulme self-assigned this Apr 24, 2024
codeboten pushed a commit that referenced this issue May 3, 2024
This makes sure to read the whole data when interacting over the socket
with haproxy.

Fixes #32652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working receiver/haproxy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants