Skip to content

[receiver/postgresql] add basic query sample collection for postgresqlreceiver #39573

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

Merged
merged 7 commits into from
Apr 29, 2025

Conversation

cuichenli
Copy link
Contributor

Description

we introduced the top query collection to postgresql receiver. this will collect the queries from pg_stat_statements and report the related metrics. this will help the end user to identify which queries are most executed, and resources most used.

Example output:

resourceLogs:
  - resource:
      attributes: []
    scopeLogs:
      - logRecords:
          - attributes:
              - key: db.system.name
                value:
                  stringValue: postgresql
              - key: db.namespace
                value:
                  stringValue: postgres
              - key: db.query.text
                value:
                  stringValue: "select * from pg_stat_activity where id = ?"
              - key: postgresql.calls 
                value: 
                  intValue: 3
              - key: postgresql.rows 
                value:
                  intValue: 10
              - key: postgresql.shared_blks_dirtied
                value:
                  intValue: 1 
              - key: postgresql.shared_blks_hit
                value:
                  intValue: 2
              - key: postgresql.shared_blks_read
                value:
                  intValue: 3
              - key: postgresql.shared_blks_written
                value:
                  intValue: 4
              - key: postgresql.temp_blks_read
                value:
                  intValue: 5
              - key: postgresql.temp_blks_written
                value:
                  intValue: 6
              - key: postgresql.queryid 
                value: 
                  stringValue: "114514"
              - key: postgresql.rolname 
                value: 
                  stringValue: master
              - key: postgresql.total_exec_time 
                value: 
                  doubleValue: 1
              - key: postgresql.total_plan_time 
                value: 
                  doubleValue: 1
            body:
              stringValue: top query
        scope:
          name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver
          version: 0.0.1

@cuichenli cuichenli requested a review from a team as a code owner April 23, 2025 02:22
@cuichenli cuichenli requested a review from mwear April 23, 2025 02:22

p.collectTopQuery(ctx, dbClient, &logRecords, maxRowsPerQuery, topNQuery, &errs, p.logger)

defer dbClient.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the defer call be before we collect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@atoulme atoulme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Some small things to address.

@atoulme atoulme marked this pull request as draft April 27, 2025 00:12
@atoulme
Copy link
Contributor

atoulme commented Apr 27, 2025

Moving to draft, please address comments and mark ready for review.

@cuichenli cuichenli marked this pull request as ready for review April 28, 2025 01:49
@atoulme atoulme merged commit efb145c into open-telemetry:main Apr 29, 2025
176 checks passed
@github-actions github-actions bot added this to the next release milestone Apr 29, 2025
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 6, 2025
…lreceiver (open-telemetry#39573)

#### Description
we introduced the top query collection to postgresql receiver. this will
collect the queries from `pg_stat_statements` and report the related
metrics. this will help the end user to identify which queries are most
executed, and resources most used.

Example output:
```
resourceLogs:
  - resource:
      attributes: []
    scopeLogs:
      - logRecords:
          - attributes:
              - key: db.system.name
                value:
                  stringValue: postgresql
              - key: db.namespace
                value:
                  stringValue: postgres
              - key: db.query.text
                value:
                  stringValue: "select * from pg_stat_activity where id = ?"
              - key: postgresql.calls 
                value: 
                  intValue: 3
              - key: postgresql.rows 
                value:
                  intValue: 10
              - key: postgresql.shared_blks_dirtied
                value:
                  intValue: 1 
              - key: postgresql.shared_blks_hit
                value:
                  intValue: 2
              - key: postgresql.shared_blks_read
                value:
                  intValue: 3
              - key: postgresql.shared_blks_written
                value:
                  intValue: 4
              - key: postgresql.temp_blks_read
                value:
                  intValue: 5
              - key: postgresql.temp_blks_written
                value:
                  intValue: 6
              - key: postgresql.queryid 
                value: 
                  stringValue: "114514"
              - key: postgresql.rolname 
                value: 
                  stringValue: master
              - key: postgresql.total_exec_time 
                value: 
                  doubleValue: 1
              - key: postgresql.total_plan_time 
                value: 
                  doubleValue: 1
            body:
              stringValue: top query
        scope:
          name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver
          version: 0.0.1
```
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 20, 2025
…lreceiver (open-telemetry#39573)

#### Description
we introduced the top query collection to postgresql receiver. this will
collect the queries from `pg_stat_statements` and report the related
metrics. this will help the end user to identify which queries are most
executed, and resources most used.

Example output:
```
resourceLogs:
  - resource:
      attributes: []
    scopeLogs:
      - logRecords:
          - attributes:
              - key: db.system.name
                value:
                  stringValue: postgresql
              - key: db.namespace
                value:
                  stringValue: postgres
              - key: db.query.text
                value:
                  stringValue: "select * from pg_stat_activity where id = ?"
              - key: postgresql.calls
                value:
                  intValue: 3
              - key: postgresql.rows
                value:
                  intValue: 10
              - key: postgresql.shared_blks_dirtied
                value:
                  intValue: 1
              - key: postgresql.shared_blks_hit
                value:
                  intValue: 2
              - key: postgresql.shared_blks_read
                value:
                  intValue: 3
              - key: postgresql.shared_blks_written
                value:
                  intValue: 4
              - key: postgresql.temp_blks_read
                value:
                  intValue: 5
              - key: postgresql.temp_blks_written
                value:
                  intValue: 6
              - key: postgresql.queryid
                value:
                  stringValue: "114514"
              - key: postgresql.rolname
                value:
                  stringValue: master
              - key: postgresql.total_exec_time
                value:
                  doubleValue: 1
              - key: postgresql.total_plan_time
                value:
                  doubleValue: 1
            body:
              stringValue: top query
        scope:
          name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver
          version: 0.0.1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants