Skip to content

feat(otel): support user-defined custom metric queries via ConfigMap references #343

@WentingWu666666

Description

@WentingWu666666

Summary

Add support for user-defined custom SQL metric queries in the OTel monitoring feature, allowing users to extend the built-in metrics without requiring operator upgrades.

Motivation

The current OTel monitoring (added in #342) embeds metric queries in base_config.yaml via go:embed. Users cannot add custom SQLmetric mappings without an operator upgrade. CNPG provides this extensibility via customQueriesConfigMap / customQueriesSecret.

Proposed API

spec:
  monitoring:
    enabled: true
    customQueries:
      - configMapRef:
          name: my-custom-metrics
          key: queries.yaml

Where queries.yaml uses the OTel sqlquery receiver format:

queries:
  - sql: "SELECT count(*) as total FROM pg_stat_activity WHERE state = 'active'"
    metrics:
      - metric_name: documentdb.postgres.active_connections
        value_column: total
        data_type: gauge

Implementation Notes

  • The operator would merge user-provided queries into the generated ConfigMap alongside base_config.yaml
  • The static/dynamic config split in feat(otel): add OTel Collector sidecar injection via CNPG plugin #342 was designed to support this extension
  • Also consider enriching base_config.yaml with more built-in queries (backends, replication lag, database size) as a prerequisite

Context

Raised by @xgerman in PR #342 review: #342 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions