Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions entity-types/infra-postgresqlinstance/definition.stg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
domain: INFRA
type: POSTGRESQLINSTANCE

synthesis:
rules:
# opentelemetry (postgresqlreceiver); service.instance.id is host:port, enabled by default
- ruleName: infra_postgresqlinstance_service_instance_id
identifier: service.instance.id # host:port
name: service.instance.id
encodeIdentifierInGUID: true
conditions:
- attribute: eventType
value: Metric
- attribute: metricName
prefix: postgresql.
- attribute: instrumentation.provider
value: opentelemetry
tags:
# Environment resource attributes
host.type:
cloud.provider:
cloud.account.id:
cloud.region:
otel.library.name:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mraju1 Can we update the tags for both metrics and logs?

  • Add otel.library.version so we can identify customer collector versions.
  • Remove host.type, cloud.provider, cloud.account.id, and cloud.region since they aren't present in the PostgreSQL receiver's metadata.yaml.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove host.type, cloud.provider, cloud.account.id, and cloud.region since they aren't present

I think these are useful tags.
They are coming from the resourcedetectionprocessor and are all very popular.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nr-ksteinbach Thanks for the clarification!

One thing worth flagging though, resourcedetectionprocessor actually detects the collector's own VM/host, not the database's. It reads from the collector's local environment (EC2/GCP/Azure/system metadata).

So these tags are accurate only when the collector runs on the same VM as Postgres. If it runs on a separate VM (e.g. a centralized collector, or a managed/remote Postgres instance), host.type, cloud.provider, cloud.account.id, and cloud.region would describe the collector's VM, not the DB's - which could be misleading on POSTGRESQLINSTANCE.

Given that's a pretty common setup, I'd lean toward dropping them. Happy to hear your thoughts on this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a value for the a tag attribute entry is not present, does it ignore tagging it or creates a tag with empty value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mraju1 As per the synthesis docs: a tag is only created if the attribute is present on the matching data point. If it's absent, no tag gets written (not an empty-value tag).

So keeping host.type/cloud.provider/etc. in the rule is safe when the attribute is missing - the real risk we were discussing is only when the attribute is present but describes the wrong VM (collector's, not the DB's).

Also, can you please fix the errors thrown by entityBot?

entityTagName: instrumentation.name

# opentelemetry logs (db.server.top_query / db.server.query_sample);
# db.system.name is always present on these log events when enabled.
# Using service.instance.id (host:port) to match the metric rule above.
- ruleName: infra_postgresqlinstance_otel_logs
identifier: service.instance.id # host:port
name: service.instance.id
encodeIdentifierInGUID: true
conditions:
- attribute: eventType
value: Log
- attribute: instrumentation.provider
value: opentelemetry
- attribute: db.system.name
value: postgresql
tags:
host.type:
cloud.provider:
cloud.account.id:
cloud.region:
otel.library.name:
entityTagName: instrumentation.name

# nri-postgresql / PostgresqlInstanceSample
- ruleName: infra_postgresqlinstance_entityId
identifier: entityId
name: entityKey
legacyFeatures:
useNonStandardAttributes: true
overrideGuidType: true
prefixedTags:
label.:
ttl: PT4H
conditions:
- attribute: eventType
value: 'PostgresqlInstanceSample'
tags:
integrationName:
ttl: P1D
integrationVersion:
ttl: P1D
reportingAgent:
ttl: P1D
reportingEndpoint:
ttl: P1D

tags:
# For OpenTelemetry
telemetry.sdk.name:
entityTagName: instrumentation.provider

goldenTags:
- postgres.host
configuration:
entityExpirationTime: DAILY
alertable: true

dashboardTemplates:
# This should match the entity created from the ohi in the infra pipeline
newRelic:
template: newrelic_dashboard.json
opentelemetry:
template: opentelemetry_dashboard.json

ownership:
primaryOwner:
teamName: "Database Integrations"
35 changes: 35 additions & 0 deletions entity-types/infra-postgresqlinstance/tests/Log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"eventType": "Log",
"instrumentation.provider": "opentelemetry",
"db.system.name": "postgresql",
"db.namespace": "testdb",
"db.query.text": "SELECT 1",
"event.name": "db.server.top_query",
"service.instance.id": "localhost:5432",
"newrelic.source": "api.logs.otlp",
"otel.library.name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver",
"postgresql.calls": 10,
"postgresql.queryid": "12345",
"postgresql.rolname": "app_user",
"postgresql.rows": 100,
"postgresql.total_exec_time": 5.2,
"timestamp": 1784408557426
},
{
"eventType": "Log",
"instrumentation.provider": "opentelemetry",
"db.system.name": "postgresql",
"db.namespace": "testdb",
"db.query.text": "SELECT id FROM users WHERE active = $1",
"event.name": "db.server.query_sample",
"service.instance.id": "localhost:5432",
"newrelic.source": "api.logs.otlp",
"otel.library.name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver",
"postgresql.state": "active",
"postgresql.pid": 1234,
"postgresql.rolname": "app_user",
"postgresql.total_exec_time": 1.5,
"timestamp": 1784408557426
}
]
Loading