Skip to content
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

Postgresql 15 has no tag_id and telegraf output #16127

Open
keith6014 opened this issue Nov 3, 2024 · 1 comment
Open

Postgresql 15 has no tag_id and telegraf output #16127

keith6014 opened this issue Nov 3, 2024 · 1 comment
Labels
bug unexpected problem or unintended behavior

Comments

@keith6014
Copy link

keith6014 commented Nov 3, 2024

Relevant telegraf.conf

Running postgresql 15.6 with pgbouncer

My configuration for telegraf looks like this

[outputs.postgresql]
           
	  schema = "telegraf"
          tags_as_foreign_keys = true
	  create_templates = [
	    '''CREATE TABLE {{ .table }} ({{ .allColumns }})''',
	    '''SELECT create_hypertable({{ .table|quoteLiteral }}, 'time', chunk_time_interval => INTERVAL '1d')''',
	    '''ALTER TABLE {{ .table }} SET (timescaledb.compress, timescaledb.compress_segmentby = 'tag_id')''',
	    '''SELECT add_compression_policy({{ .table|quoteLiteral }}, INTERVAL '2d')''',
	    '''CREATE VIEW {{ .table.WithSuffix "_data" }} AS
	         SELECT {{ .allColumns.Selectors | join "," }} FROM {{ .table }}''',
	    '''CREATE VIEW {{ .table.WithSchema "public" }} AS
	         SELECT time, {{ (.tagTable.Columns.Tags.Concat .allColumns.Fields).Identifiers | join "," }}
	         FROM {{ .table.WithSuffix "_data" }} t, {{ .tagTable }} tt
	         WHERE t.tag_id = tt.tag_id''',
	  ]
	  add_column_templates = [
	    '''ALTER TABLE {{ .table }} RENAME TO {{ (.table.WithSuffix "_" .table.Columns.Hash).WithSchema "" }}''',
	    '''ALTER VIEW {{ .table.WithSuffix "_data" }} RENAME TO {{ (.table.WithSuffix "_" .table.Columns.Hash "_data").WithSchema "" }}''',
	    '''DROP VIEW {{ .table.WithSchema "public" }}''',

	    '''CREATE TABLE {{ .table }} ({{ .allColumns }})''',
	    '''SELECT create_hypertable({{ .table|quoteLiteral }}, 'time', chunk_time_interval => INTERVAL '1d')''',
	    '''ALTER TABLE {{ .table }} SET (timescaledb.compress, timescaledb.compress_segmentby = 'tag_id')''',
	    '''SELECT add_compression_policy({{ .table|quoteLiteral }}, INTERVAL '2d')''',
	    '''CREATE VIEW {{ .table.WithSuffix "_data" }} AS
	         SELECT {{ .allColumns.Selectors | join "," }}
	         FROM {{ .table }}
	         UNION ALL
	         SELECT {{ (.allColumns.Union .table.Columns).Selectors | join "," }}
	         FROM {{ .table.WithSuffix "_" .table.Columns.Hash "_data" }}''',
	    '''CREATE VIEW {{ .table.WithSchema "public" }}
	         AS SELECT time, {{ (.tagTable.Columns.Tags.Concat .allColumns.Fields).Identifiers | join "," }}
	         FROM {{ .table.WithSuffix "_data" }} t, {{ .tagTable }} tt
	         WHERE t.tag_id = tt.tag_id''',
	  ]

Logs from Telegraf

No errors

System info

Linux, Telegraf 1.27.2, Postgresql 15.6 w timescaledb

Docker

No response

Steps to reproduce

  1. Download telegraf 1.27.2
  2. Setup postgresql w/timescaledb
  3. Set up proper outputs for postgresql
  4. Start telegraf
  5. Query postgresql
    ...

Expected behavior

select * from cpu limit 1

I would expect to see the hostname in the view. However, I see tag_id. The tag_id matches the proper hostname when doing select host from cpu_tag;

Actual behavior

I see tag_id. I would expect to see the hostname

Additional info

Using pgbouncer

@keith6014 keith6014 added the bug unexpected problem or unintended behavior label Nov 3, 2024
@srebhan
Copy link
Member

srebhan commented Nov 4, 2024

@keith6014 did you check the actual metrics e.g. by using the --test flag on a console or by using a outputs.file to check how the metrics look like?

Otherwise, I guess the insert templates mess something up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants