-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[receiver/sqlquery] Multiple connections despite max_open_conn = 1 #39270
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
Labels
Comments
Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
Thanks for filing this issue and including so much relevant information, @cbandy, agreed this is a bug that needs resolved. |
I can submit a fix in the next day or two. |
cbandy
added a commit
to cbandy/opentelemetry-collector-contrib
that referenced
this issue
Apr 11, 2025
I've opened #39312 to address this. |
cbandy
added a commit
to cbandy/opentelemetry-collector-contrib
that referenced
this issue
Apr 11, 2025
Fixes: open-telemetry#39270 Signed-off-by: Chris Bandy <[email protected]>
atoulme
pushed a commit
that referenced
this issue
Apr 17, 2025
) #### Description Rather than creating a separate `*sql.DB` provider function for each query, this creates one provider for the receiver and passes a method value to each query. The method uses a mutex to ensure exactly one `*sql.DB` is created when it is called concurrently. The `max_open_conn` config is defined in `sqlqueryreceiver`, so I put the implementation in its `internal` package. #### Link to tracking issue Fixes #39270 #### Testing Using the configuration and steps in #39270, I see only one connection to Postgres: ```console $ psql -h localhost -U postgres -c 'SELECT pid, backend_type, datname, usename, query, state FROM pg_stat_activity' ┌─────┬──────────────────────────────┬──────────┬──────────┬────────────────────────────────────────────────────────────────────────────────┬────────┐ │ pid │ backend_type │ datname │ usename │ query │ state │ ├─────┼──────────────────────────────┼──────────┼──────────┼────────────────────────────────────────────────────────────────────────────────┼────────┤ │ 68 │ client backend │ postgres │ postgres │ SELECT 3 AS number │ idle │ │ 70 │ client backend │ postgres │ postgres │ SELECT pid, backend_type, datname, usename, query, state FROM pg_stat_activity │ active │ │ 65 │ autovacuum launcher │ ␀ │ ␀ │ │ ␀ │ │ 66 │ logical replication launcher │ ␀ │ postgres │ │ ␀ │ │ 61 │ checkpointer │ ␀ │ ␀ │ │ ␀ │ │ 62 │ background writer │ ␀ │ ␀ │ │ ␀ │ │ 64 │ walwriter │ ␀ │ ␀ │ │ ␀ │ └─────┴──────────────────────────────┴──────────┴──────────┴────────────────────────────────────────────────────────────────────────────────┴────────┘ (7 rows) ``` Signed-off-by: Chris Bandy <[email protected]>
akshays-19
pushed a commit
to akshays-19/opentelemetry-collector-contrib
that referenced
this issue
Apr 23, 2025
…n-telemetry#39312) #### Description Rather than creating a separate `*sql.DB` provider function for each query, this creates one provider for the receiver and passes a method value to each query. The method uses a mutex to ensure exactly one `*sql.DB` is created when it is called concurrently. The `max_open_conn` config is defined in `sqlqueryreceiver`, so I put the implementation in its `internal` package. #### Link to tracking issue Fixes open-telemetry#39270 #### Testing Using the configuration and steps in open-telemetry#39270, I see only one connection to Postgres: ```console $ psql -h localhost -U postgres -c 'SELECT pid, backend_type, datname, usename, query, state FROM pg_stat_activity' ┌─────┬──────────────────────────────┬──────────┬──────────┬────────────────────────────────────────────────────────────────────────────────┬────────┐ │ pid │ backend_type │ datname │ usename │ query │ state │ ├─────┼──────────────────────────────┼──────────┼──────────┼────────────────────────────────────────────────────────────────────────────────┼────────┤ │ 68 │ client backend │ postgres │ postgres │ SELECT 3 AS number │ idle │ │ 70 │ client backend │ postgres │ postgres │ SELECT pid, backend_type, datname, usename, query, state FROM pg_stat_activity │ active │ │ 65 │ autovacuum launcher │ ␀ │ ␀ │ │ ␀ │ │ 66 │ logical replication launcher │ ␀ │ postgres │ │ ␀ │ │ 61 │ checkpointer │ ␀ │ ␀ │ │ ␀ │ │ 62 │ background writer │ ␀ │ ␀ │ │ ␀ │ │ 64 │ walwriter │ ␀ │ ␀ │ │ ␀ │ └─────┴──────────────────────────────┴──────────┴──────────┴────────────────────────────────────────────────────────────────────────────────┴────────┘ (7 rows) ``` Signed-off-by: Chris Bandy <[email protected]>
Fiery-Fenix
pushed a commit
to Fiery-Fenix/opentelemetry-collector-contrib
that referenced
this issue
Apr 24, 2025
…n-telemetry#39312) #### Description Rather than creating a separate `*sql.DB` provider function for each query, this creates one provider for the receiver and passes a method value to each query. The method uses a mutex to ensure exactly one `*sql.DB` is created when it is called concurrently. The `max_open_conn` config is defined in `sqlqueryreceiver`, so I put the implementation in its `internal` package. #### Link to tracking issue Fixes open-telemetry#39270 #### Testing Using the configuration and steps in open-telemetry#39270, I see only one connection to Postgres: ```console $ psql -h localhost -U postgres -c 'SELECT pid, backend_type, datname, usename, query, state FROM pg_stat_activity' ┌─────┬──────────────────────────────┬──────────┬──────────┬────────────────────────────────────────────────────────────────────────────────┬────────┐ │ pid │ backend_type │ datname │ usename │ query │ state │ ├─────┼──────────────────────────────┼──────────┼──────────┼────────────────────────────────────────────────────────────────────────────────┼────────┤ │ 68 │ client backend │ postgres │ postgres │ SELECT 3 AS number │ idle │ │ 70 │ client backend │ postgres │ postgres │ SELECT pid, backend_type, datname, usename, query, state FROM pg_stat_activity │ active │ │ 65 │ autovacuum launcher │ ␀ │ ␀ │ │ ␀ │ │ 66 │ logical replication launcher │ ␀ │ postgres │ │ ␀ │ │ 61 │ checkpointer │ ␀ │ ␀ │ │ ␀ │ │ 62 │ background writer │ ␀ │ ␀ │ │ ␀ │ │ 64 │ walwriter │ ␀ │ ␀ │ │ ␀ │ └─────┴──────────────────────────────┴──────────┴──────────┴────────────────────────────────────────────────────────────────────────────────┴────────┘ (7 rows) ``` Signed-off-by: Chris Bandy <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Component(s)
receiver/sqlquery
What happened?
Description
#36752 is happening despite #37748. The sqlquery receiver opens one connection for every query, regardless of the
max_open_conn
setting.Steps to Reproduce
Use the configuration below with a recent collector and Postgres:
$ docker run --rm -it --net host --env POSTGRES_HOST_AUTH_METHOD=trust docker.io/library/postgres $ docker run --rm -it --net host -v "$(pwd)/config.yaml:/etc/otelcol-contrib/config.yaml:ro" \ ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.123.1
Use
psql
to see the open connections at Postgres:Expected Result
I expected one "client backend" connection because
max_open_conn: 1
in the receiver config.Actual Result
Three "client backend" connections, one for each query.
Collector version
v0.123.1
Environment information
Environment
OS: Debian 12 (bookworm)
OpenTelemetry Collector configuration
Log output
Additional context
This function is called during every Scraper's startup, creating multiple pools:
opentelemetry-collector-contrib/receiver/sqlqueryreceiver/receiver.go
Lines 47 to 48 in 19d98da
The text was updated successfully, but these errors were encountered: