Repository navigation
feat(dbi): split postgresql per-resource metrics to a dedicated 60s receiver - #2232
Conversation
f9c5e60 to
ca93050
Compare
2c01139 to
aeb133d
Compare
Binary Size Reportlinux/amd64
linux/arm64
windows/amd64
Investigating size changesUse go-size-analyzer to compare binaries: GOEXPERIMENT=jsonv2 go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa diff --old <baseline-binary> --new <new-binary> |
|
How would i customer set this up? Will this be in the JSON, do they have to do it int he yaml? |
|
Should also have yaml translations for all 3 options probably so we can confirm that the behavior is what we expect per field enabled |
| perResourceRx := t.pgReceiver("metrics_perresource", | ||
| postgresql.WithPerResourceMetricsOnly(), | ||
| postgresql.WithCollectionInterval(60*time.Second), | ||
| postgresql.WithEventsDisabled(), |
There was a problem hiding this comment.
Are these disabled by default?
| serverRx := t.pgReceiver("metrics", postgresql.WithServerMetricsOnly()) | ||
| perResourceRx := t.pgReceiver("metrics_perresource", | ||
| postgresql.WithPerResourceMetricsOnly(), | ||
| postgresql.WithCollectionInterval(60*time.Second), |
There was a problem hiding this comment.
Translator is updated when we need to translate a key in the agent JSON to expand into a template YAML config. The changes we've made in this PR doesn't give the customer a way to configure these values in the JSON.
Is this intended to be an opinionated YAML config that shouldn't let customers modify by JSON?
|
Can the PR description be updated with more details following the PR template |
aeb133d to
122e0c7
Compare
| // with a postgresql.table.name / postgresql.index.name resource attribute. | ||
| // postgresql.table.count is intentionally excluded: it is a per-database server metric | ||
| // recorded alongside the other server metrics. | ||
| var perResourceMetricNames = map[string]bool{ |
There was a problem hiding this comment.
Since this is hardcoded, we'll have to keep in mind that upstream could always add more metrics, which would then start being published every 10s like the rest of the metrics. Might be worth having some sort of test in the future
There was a problem hiding this comment.
Is this even possible? If so how?
There was a problem hiding this comment.
Technically it is. I think it's less likely in the sense that I don't think it's very common for them to implement new metrics as defaults. likely they'd be optional. BUt just a heads up
|
Did we test this on an actual instance? You can copy what our integ test for dbi does to setup and confirm that everything is working as expected |
122e0c7 to
190e97e
Compare
190e97e to
2fb7ddc
Compare
3caf30b to
619a30b
Compare
| s2mConn := signaltometrics.NewTranslator(common.DbiConnectorTopsql) | ||
|
|
||
| // Split postgresql metric collection into two receiver instances so per-resource | ||
| // (table/index) metrics are scraped at 60s while server metrics stay at the default |
There was a problem hiding this comment.
the comment could be more specific that it's defaulted at 60s unless configured otherwise
| top_query_collection: | ||
| collection_interval: 1m0s | ||
| max_explain_each_interval: 1000 | ||
| max_explain_each_interval: 0 |
There was a problem hiding this comment.
looks like this is reverting one of my changes.
5d1074a to
82423ad
Compare
82423ad to
1cadef7
Compare
| "per_resource_collection_interval": { | ||
| "description": "How often per-resource (table/index) metrics are collected, in seconds. Defaults to 60 if omitted.", | ||
| "type": "integer", | ||
| "minimum": 1 |
There was a problem hiding this comment.
this would make configurations like per_resource_collection_interval: 0 to be invalid which doesn't seem correct
1cadef7 to
612f0fd
Compare
612f0fd to
d72a4c2
Compare
Description of the issue
Database Insights collects per-resource (table/index) metrics and server metrics from a single PostgreSQL receiver at the default 10s interval. Per-resource metrics scale with the number of relations in the monitored database — a database with thousands of tables produces thousands of readings each scrape. Collecting them every 10s is unnecessary for the DBI experience and inflates ingestion volume.
Description of changes
Per-resource metrics split to a dedicated receiver at 60s (configurable):
postgresqlreceiver instances per monitored database: one for server/per-database metrics at the default 10s, and one for per-resource (table/index) metrics at 60s.per_resource_collection_interval(in seconds) lets customers override the 60s default. If omitted or zero, defaults to 60s.forEachMetric) walks the receiver's generated metrics config so per-resource metrics are matched by mapstructure name rather than hand-maintained field references.TestTranslator_MetricSets_Disjointasserts the two scopes are disjoint and their union equals the default enabled set, guarding against double emission or metric loss.Events receiver metrics disabled (
WithMetricsDisabled/metricScopeNone):Config shape (unchanged if field omitted):
{ "opentelemetry": { "collect": { "database_insights": { "postgresql": [{ "endpoint": "localhost:5432", "username": "cw_monitor", "password_file": "/opt/.pgpass", "per_resource_collection_interval": 120 }] } } } }License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
TestTranslator_MetricSets_Disjoint— proves server + per-resource union equals the default set (no drop, no double emission)TestTranslator_ServerMetricsOnly/TestTranslator_PerResourceMetricsOnly— per-field assertions on each scopeTestTranslator_MetricsDisabled— events receiver emits zero metrics, events surviveTestParseDbiPostgresqlInstances_PerResourceCollectionInterval— default (60s), custom (120s), zero-falls-back-to-defaultTestTranslator_Translate_Defaults_MetricScope— default scope unchangedTestDBIConfigLinux,TestCombinedV1V2EC2Config,TestCombinedV1V2EKSConfig) — regenerated and passingal2023:otel_collect_database_insights_testpassed in CI (16m58s) on an earlier push of this branchRequirements
make fmtandmake fmt-shmake lint