Skip to content

[receiver/sqlquery] Support for Executing Queries Across Multiple Database Instances #33119

Closed as not planned
@Talbalash-legit

Description

Component(s)

receiver/sqlquery

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

Currently, executing the same query across multiple database (e.g., several DBs on an AWS RDS cluster) requires duplicating the query for each instance. This leads to redundancy and increased maintenance overhead, as any change to the query must be replicated across all instances manually.

If i have 17 DBs in a cluster i will need to replicate the query configuration 17 times with the current solution.
How can it be achieved today? maybe i'm missing something

Describe the solution you'd like

I would like the SQLQuery Receiver to support executing a single query across multiple database instances. This could be achieved by allowing users to specify a list of database connections within a single configuration, so that the query is executed against each instance automatically. This feature would streamline the process and reduce the need for query duplication.

The current situation is:

    receivers:
      sqlquery/DB_1:
        driver: postgres
        datasource: "host=${HOST} port=5432 dbname=DB_1 user=${USER} password=${PASS}"
        collection_interval: 1h
        queries:
          - sql: "SELECT idstat.relname AS TABLE_NAME, indexrelname AS index_name, idstat.idx_scan AS index_scans_count, pg_relation_size(indexrelid) AS index_size_bytes FROM pg_stat_user_indexes AS idstat JOIN pg_indexes ON indexrelname = indexname AND idstat.schemaname = pg_indexes.schemaname WHERE indexdef !~* 'unique' ORDER BY idstat.idx_scan DESC"
            metrics:
              - metric_name: postgres_index_scans_count
                value_column: "index_scans_count"
                attribute_columns: ["table_name", "index_name"]
                static_attributes:
                  db_name: DB_1
              - metric_name: postgres_index_size_bytes
                value_column: "index_size_bytes"
                attribute_columns: ["table_name", "index_name"]
                static_attributes:
                  db_name: DB_1

      sqlquery/DB_2:
        driver: postgres
        datasource: "host=${HOST} port=5432 dbname=DB_2 user=${USER} password=${PASS}"
        collection_interval: 1h
        queries:
          - sql: "SELECT idstat.relname AS TABLE_NAME, indexrelname AS index_name, idstat.idx_scan AS index_scans_count, pg_relation_size(indexrelid) AS index_size_bytes FROM pg_stat_user_indexes AS idstat JOIN pg_indexes ON indexrelname = indexname AND idstat.schemaname = pg_indexes.schemaname WHERE indexdef !~* 'unique' ORDER BY idstat.idx_scan DESC"
            metrics:
              - metric_name: postgres_index_scans_count
                value_column: "index_scans_count"
                attribute_columns: ["table_name", "index_name"]
                static_attributes:
                  db_name: DB_2
              - metric_name: postgres_index_size_bytes
                value_column: "index_size_bytes"
                attribute_columns: ["table_name", "index_name"]
                static_attributes:
                  db_name: DB_2

I would propose the following:

receivers:
      sqlquery
        driver: postgres
        datasource: "host=${HOST} port=5432 dbnames=DB_1,DB_2,DB_3 user=${USER} password=${PASS}"
        collection_interval: 1h
        queries:
          - sql: "SELECT idstat.relname AS TABLE_NAME, indexrelname AS index_name, idstat.idx_scan AS index_scans_count, pg_relation_size(indexrelid) AS index_size_bytes FROM pg_stat_user_indexes AS idstat JOIN pg_indexes ON indexrelname = indexname AND idstat.schemaname = pg_indexes.schemaname WHERE indexdef !~* 'unique' ORDER BY idstat.idx_scan DESC"
            metrics:
              - metric_name: postgres_index_scans_count
                value_column: "index_scans_count"
                attribute_columns: ["table_name", "index_name"]
                static_attributes:
                  db_name: $$DB_NAME
              - metric_name: postgres_index_size_bytes
                value_column: "index_size_bytes"
                attribute_columns: ["table_name", "index_name"]
                static_attributes:
                  db_name: $$DB_NAME

In this configuration, $$DB_NAME would be dynamically replaced with the actual database name for each datasource during query execution.

Describe alternatives you've considered

  1. Manually duplicating the queries for each database instance, which is not efficient and prone to errors.
  2. Using external scripts or tools to handle the execution of queries across multiple instances, which adds complexity and is outside the scope of the SQLQuery Receiver

Additional context

No response

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions