Skip to content

Custom query with pg_database_size causes 500 after upgrading from 0.10.1 to 0.11.1 #692

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

Closed
dastrobu opened this issue Sep 21, 2022 · 1 comment

Comments

@dastrobu
Copy link

What did you do?

I upgraded from 0.10.1 to 0.11.1.

What did you expect to see?

the exporter works unchnged

What did you see instead? Under which circumstances?

the metrics endpoint fails with 500

Environment

  • System information:

    Linux 3.10.0-1160.59.1.el7.x86_64 x86_64

  • postgres_exporter version:

postgres_exporter, version 0.11.1 (branch: HEAD, revision: b5fd2465646a09bb1c8dbd5c9c00b852da93927a)
  build user:       root@a2c981f603ff
  build date:       20220818-20:58:17
  go version:       go1.18.5
  platform:         linux/amd64
  • postgres_exporter flags:
--log.format=json --log.level=debug
  • PostgreSQL version:

    12.7.0

  • Logs:

  | {"address":":9187","caller":"main.go:135","level":"info","msg":"Listening on address","ts":"2022-09-21T14:54:28.486Z"}
-- | --
  | {"caller":"tls_config.go:195","http2":false,"level":"info","msg":"TLS is disabled.","ts":"2022-09-21T14:54:28.492Z"}
  | {"caller":"server.go:74","fingerprint":"postgresql:5432","level":"info","msg":"Established new database connection","ts":"2022-09-21T14:55:00.262Z"}
  | {"caller":"postgres_exporter.go:617","level":"debug","msg":"Querying PostgreSQL version","server":"postgresql:5432","ts":"2022-09-21T14:55:00.388Z"}
  | {"caller":"postgres_exporter.go:645","from":"0.0.0","level":"info","msg":"Semantic version changed","server":"postgresql:5432","to":"12.7.0","ts":"2022-09-21T14:55:00.399Z"}
  | {"caller":"collector.go:200","duration_seconds":0.417803329,"level":"debug","msg":"collector succeeded","name":"database","ts":"2022-09-21T14:55:00.682Z"}
  | {"caller":"collector.go:200","duration_seconds":0.320640151,"level":"debug","msg":"collector succeeded","name":"bgwriter","ts":"2022-09-21T14:55:00.678Z"}
  | {"cache_seconds":30,"caller":"queries.go:213","level":"debug","metric":"pg_database","msg":"New user metric namespace from YAML metric","ts":"2022-09-21T14:55:00.883Z"}
  | {"cache_seconds":30,"caller":"queries.go:213","level":"debug","metric":"pg_stat_user_tables","msg":"New user metric namespace from YAML metric","ts":"2022-09-21T14:55:00.883Z"}
  | {"caller":"queries.go:267","level":"debug","metric":"pg_database","msg":"Adding new metric from user YAML file","ts":"2022-09-21T14:55:00.883Z"}
  | {"caller":"queries.go:267","level":"debug","metric":"pg_stat_user_tables","msg":"Adding new metric from user YAML file","ts":"2022-09-21T14:55:00.883Z"}
  | {"caller":"queries.go:278","level":"debug","msg":"Adding new query override from user YAML file","query_override":"pg_database","ts":"2022-09-21T14:55:00.883Z"}
  | {"caller":"queries.go:278","level":"debug","msg":"Adding new query override from user YAML file","query_override":"pg_stat_user_tables","ts":"2022-09-21T14:55:00.883Z"}
  | {"caller":"pg_setting.go:35","level":"debug","msg":"Querying pg_setting view","server":"postgresql:5432","ts":"2022-09-21T14:55:00.887Z"}
  | {"caller":"namespace.go:193","level":"debug","msg":"Querying namespace","namespace":"pg_database","ts":"2022-09-21T14:55:01.083Z"}
  | {"caller":"namespace.go:193","level":"debug","msg":"Querying namespace","namespace":"pg_stat_user_tables","ts":"2022-09-21T14:55:01.087Z"}


The query, which seems to cause the issue is as follows:

    queries:
      pg_database:
        query: "SELECT pg_database.datname, pg_database_size(pg_database.datname) as size_bytes FROM pg_database;"
        master: true
        cache_seconds: 30
        metrics:
          - datname:
              usage: "LABEL"
              description: "Name of the database"
          - size_bytes:
              usage: "GAUGE"
              description: "Disk space used by the database"

without the pg_database_size(pg_database.datname) it seems to work fine.

When downgrading again to version 0.10.1, everything works as expected.

@sysadmind
Copy link
Contributor

#613 Added the pg_database metrics into the exporter itself. You don't need it in the queries file with 0.11.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants