Skip to content

settings metric should be rewritten with values casted to integer #1247

@pashagolub

Description

@pashagolub

The current settings metric SQL returns many configuration values as text.

Because pgwatch automatically converts SQL result sets into Prometheus metrics:

  • text columns → labels
  • numeric columns → metric values

this causes configuration parameters to be exported as labels instead of values.

Example (simplified SQL result):

name              | setting
------------------+----------
lock_timeout      | 100 (ms)
shared_buffers    | 128MB
archive_mode      | off

After automatic conversion, this becomes something like:

pgwatch_settings_server_version_num{
  lock_timeout="100 (ms)",
  shared_buffers="128MB",
  archive_mode="off",
  ...
} 180000

This leads to:

  • Cardinality explosion
  • New time series on every config change
  • Stale series accumulation
  • Difficult aggregation
  • Unintuitive promql query behavior

Proposed solution should use this trick:

select 
	name, 
	case vartype when 
        'integer' then setting::int
	else 
        case setting when 'on' then 1 else 0 end
	end
from pg_settings 
where vartype in ('bool', 'integer')

Metadata

Metadata

Assignees

Labels

metricsMetrics related issuesrefactoringSomething done as it should've been done from the start

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions