diff --git a/receiver/postgresqlreceiver/README.md b/receiver/postgresqlreceiver/README.md index 7345fe1ff251..35f4920171a9 100644 --- a/receiver/postgresqlreceiver/README.md +++ b/receiver/postgresqlreceiver/README.md @@ -64,4 +64,33 @@ The full list of settings exposed for this receiver are documented [here](./conf Details about the metrics produced by this receiver can be found in [metadata.yaml](./metadata.yaml) [beta]: https://github.com/open-telemetry/opentelemetry-collector#beta -[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib \ No newline at end of file +[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib + +### Feature gate configurations + +#### Transition from metrics without "resource_attributes" + +All metrics are being transitioning to moving the metric attributes `table` and `database` to resource attributes `postgresql.table` and `postgresql.database` respectively. This effort is motivated via the resource specification found [in the metrics data model](https://github.com/open-telemetry/opentelemetry-specification/blob/141a3ef0bf1eba0b6d260335bbe0ce7af9387cfc/specification/metrics/data-model.md#resource-attributes-1). + +Eventually the move will be finalized, but there will be a transitional period where metrics will emit with resource attributes behind a feature gate. + +##### Transition Schedule + +1. v0.58.0, August 2022: + + - The version of the metrics receiver with resource attributes will be available via feature gates. + - The old metrics with `table` and `database` metric attributes are deprecated with a warning. + - `receiver.postgresql.emitMetricsWithResourceAttributes` is *disabled* by default. + - `receiver.postgresql.emitMetricsWithoutResourceAttributes` is *enabled* by default. + +2. v0.60.0, September 2022: + + - The new collection method with resource attributes is enabled by default. The old metrics with the `table` and `database` metric attributes is disabled by default. + - `receiver.postgresql.emitMetricsWithResourceAttributes` is *enabled* by default. + - `receiver.postgresql.emitMetricsWithoutResourceAttributes` is *disabled* by default. + +3. v0.62.0, October 2022: + + - The feature gates are removed. + - Metrics collection using resource attributes are always emitted + - Metrics collection using the `database` and `table` metric attributes are no longer available. diff --git a/receiver/postgresqlreceiver/documentation.md b/receiver/postgresqlreceiver/documentation.md index 50a052d100e2..ec4a0e26ce1f 100644 --- a/receiver/postgresqlreceiver/documentation.md +++ b/receiver/postgresqlreceiver/documentation.md @@ -25,6 +25,13 @@ metrics: enabled: ``` +## Resource attributes + +| Name | Description | Type | +| ---- | ----------- | ---- | +| postgresql.database.name | The name of the database. | String | +| postgresql.table.name | The schema name followed by the table name. | String | + ## Metric attributes | Name | Description | Values | diff --git a/receiver/postgresqlreceiver/integration_test.go b/receiver/postgresqlreceiver/integration_test.go index c636404d673a..cdfa8b1d7a74 100644 --- a/receiver/postgresqlreceiver/integration_test.go +++ b/receiver/postgresqlreceiver/integration_test.go @@ -29,6 +29,7 @@ import ( "github.com/testcontainers/testcontainers-go/wait" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/service/featuregate" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/scrapertest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/scrapertest/golden" @@ -36,9 +37,14 @@ import ( type configFunc func(hostname string) *Config +// cleanupFunc exists to allow integration test cases to clean any registries it had +// to modify in order to change behavior of the integration test. i.e. featuregates +type cleanupFunc func() + type testCase struct { name string cfg configFunc + cleanup cleanupFunc expectedFile string } @@ -86,6 +92,28 @@ func TestPostgreSQLIntegration(t *testing.T) { }, expectedFile: filepath.Join("testdata", "integration", "expected_all_db.json"), }, + { + name: "with_resource_attributes", + cfg: func(hostname string) *Config { + featuregate.GetRegistry().MustApply(map[string]bool{ + emitMetricsWithResourceAttributesFeatureGateID: true, + }) + f := NewFactory() + cfg := f.CreateDefaultConfig().(*Config) + cfg.Endpoint = net.JoinHostPort(hostname, "15432") + cfg.Databases = []string{} + cfg.Username = "otel" + cfg.Password = "otel" + cfg.Insecure = true + return cfg + }, + cleanup: func() { + featuregate.GetRegistry().MustApply(map[string]bool{ + emitMetricsWithResourceAttributesFeatureGateID: false, + }) + }, + expectedFile: filepath.Join("testdata", "integration", "expected_all_with_resource_attributes.json"), + }, } container := getContainer(t, testcontainers.ContainerRequest{ @@ -105,6 +133,9 @@ func TestPostgreSQLIntegration(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + if tc.cleanup != nil { + defer tc.cleanup() + } expectedMetrics, err := golden.ReadMetrics(tc.expectedFile) require.NoError(t, err) diff --git a/receiver/postgresqlreceiver/internal/metadata/custom.go b/receiver/postgresqlreceiver/internal/metadata/custom.go new file mode 100644 index 000000000000..423fdf536621 --- /dev/null +++ b/receiver/postgresqlreceiver/internal/metadata/custom.go @@ -0,0 +1,125 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package metadata // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver/internal/metadata" + +import "go.opentelemetry.io/collector/pdata/pcommon" + +// RecordPostgresqlDbSizeDataPointWithoutDatabase adds a data point to postgresql.db_size metric without a database metric attribute +func (mb *MetricsBuilder) RecordPostgresqlDbSizeDataPointWithoutDatabase(ts pcommon.Timestamp, val int64) { + mb.metricPostgresqlDbSize.recordDatapointWithoutDatabase(mb.startTime, ts, val) +} + +func (m *metricPostgresqlDbSize) recordDatapointWithoutDatabase(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) +} + +// RecordPostgresqlBackendsDataPointWithoutDatabase adds a data point to postgresql.backends metric. +func (mb *MetricsBuilder) RecordPostgresqlBackendsDataPointWithoutDatabase(ts pcommon.Timestamp, val int64) { + mb.metricPostgresqlBackends.recordDatapointWithoutDatabase(mb.startTime, ts, val) +} + +func (m *metricPostgresqlBackends) recordDatapointWithoutDatabase(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) +} + +// RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable adds a data point to postgresql.blocks_read metric. +func (mb *MetricsBuilder) RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(ts pcommon.Timestamp, val int64, sourceAttributeValue AttributeSource) { + mb.metricPostgresqlBlocksRead.recordDatapointWithoutDatabaseAndTable(mb.startTime, ts, val, sourceAttributeValue.String()) +} + +func (m *metricPostgresqlBlocksRead) recordDatapointWithoutDatabaseAndTable(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, sourceAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().InsertString("source", sourceAttributeValue) +} + +// RecordPostgresqlCommitsDataPointWithoutDatabase adds a data point to postgresql.commits metric without the database metric attribute +func (mb *MetricsBuilder) RecordPostgresqlCommitsDataPointWithoutDatabase(ts pcommon.Timestamp, val int64) { + mb.metricPostgresqlCommits.recordDatapointWithoutDatabase(mb.startTime, ts, val) +} + +func (m *metricPostgresqlCommits) recordDatapointWithoutDatabase(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) +} + +// RecordPostgresqlRollbacksDataPointWithoutDatabase adds a data point to postgresql.commits metric without the database metric attribute +func (mb *MetricsBuilder) RecordPostgresqlRollbacksDataPointWithoutDatabase(ts pcommon.Timestamp, val int64) { + mb.metricPostgresqlRollbacks.recordDatapointWithoutDatabase(mb.startTime, ts, val) +} + +func (m *metricPostgresqlRollbacks) recordDatapointWithoutDatabase(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) +} + +// RecordPostgresqlRowsDataPointWithoutDatabaseAndTable adds a data point to postgresql.rows metric without the database or table metric attribute. +func (mb *MetricsBuilder) RecordPostgresqlRowsDataPointWithoutDatabaseAndTable(ts pcommon.Timestamp, val int64, stateAttributeValue AttributeState) { + mb.metricPostgresqlRows.recordDatapointWithoutDatabaseAndTable(mb.startTime, ts, val, stateAttributeValue.String()) +} + +func (m *metricPostgresqlRows) recordDatapointWithoutDatabaseAndTable(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, stateAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().InsertString("state", stateAttributeValue) +} + +// RecordPostgresqlOperationsDataPointWithoutDatabaseAndTable adds a data point to postgresql.operations metric without the database or table metric attribute +func (mb *MetricsBuilder) RecordPostgresqlOperationsDataPointWithoutDatabaseAndTable(ts pcommon.Timestamp, val int64, operationAttributeValue AttributeOperation) { + mb.metricPostgresqlOperations.recordDatapointWithoutDatabaseAndTable(mb.startTime, ts, val, operationAttributeValue.String()) +} + +func (m *metricPostgresqlOperations) recordDatapointWithoutDatabaseAndTable(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, operationAttributeValue string) { + if !m.settings.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntVal(val) + dp.Attributes().InsertString("operation", operationAttributeValue) +} diff --git a/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go b/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go index 919a2db503d5..62b8bbf83c35 100644 --- a/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go +++ b/receiver/postgresqlreceiver/internal/metadata/generated_metrics_v2.go @@ -598,6 +598,20 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { // ResourceMetricsOption applies changes to provided resource metrics. type ResourceMetricsOption func(pmetric.ResourceMetrics) +// WithPostgresqlDatabaseName sets provided value as "postgresql.database.name" attribute for current resource. +func WithPostgresqlDatabaseName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("postgresql.database.name", val) + } +} + +// WithPostgresqlTableName sets provided value as "postgresql.table.name" attribute for current resource. +func WithPostgresqlTableName(val string) ResourceMetricsOption { + return func(rm pmetric.ResourceMetrics) { + rm.Resource().Attributes().UpsertString("postgresql.table.name", val) + } +} + // WithStartTimeOverride overrides start time for all the resource metrics data points. // This option should be only used if different start time has to be set on metrics coming from different resources. func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { diff --git a/receiver/postgresqlreceiver/metadata.yaml b/receiver/postgresqlreceiver/metadata.yaml index 48660c8a3bf8..f2a2afe6f84e 100644 --- a/receiver/postgresqlreceiver/metadata.yaml +++ b/receiver/postgresqlreceiver/metadata.yaml @@ -1,20 +1,37 @@ name: postgresqlreceiver +resource_attributes: + postgresql.database.name: + description: The name of the database. + type: string + postgresql.table.name: + description: The schema name followed by the table name. + type: string + attributes: database: description: The name of the database. + type: string table: description: The schema name followed by the table name. + type: string source: description: The block read source type. - enum: [ heap_read, heap_hit, idx_read, idx_hit, toast_read, toast_hit, tidx_read, tidx_hit ] + enum: + - heap_read + - heap_hit + - idx_read + - idx_hit + - toast_read + - toast_hit + - tidx_read + - tidx_hit operation: description: The database operation. - enum: [ ins, upd, del, hot_upd ] + enum: [ins, upd, del, hot_upd] state: description: The tuple (row) state. - enum: [ dead, live ] - + enum: [dead, live] metrics: postgresql.blocks_read: @@ -25,7 +42,7 @@ metrics: value_type: int monotonic: true aggregation: cumulative - attributes: [ database, table, source ] + attributes: [database, table, source] postgresql.commits: enabled: true description: The number of commits. @@ -34,7 +51,7 @@ metrics: value_type: int monotonic: true aggregation: cumulative - attributes: [ database ] + attributes: [database] postgresql.db_size: enabled: true description: The database disk usage. @@ -43,7 +60,7 @@ metrics: value_type: int monotonic: false aggregation: cumulative - attributes: [ database ] + attributes: [database] postgresql.backends: enabled: true description: The number of backends. @@ -52,7 +69,7 @@ metrics: value_type: int monotonic: false aggregation: cumulative - attributes: [ database ] + attributes: [database] postgresql.rows: enabled: true description: The number of rows in the database. @@ -61,7 +78,7 @@ metrics: value_type: int monotonic: false aggregation: cumulative - attributes: [ database, table, state ] + attributes: [database, table, state] postgresql.operations: enabled: true description: The number of db row operations. @@ -70,7 +87,7 @@ metrics: value_type: int monotonic: true aggregation: cumulative - attributes: [ database, table, operation ] + attributes: [database, table, operation] postgresql.rollbacks: enabled: true description: The number of rollbacks. @@ -79,4 +96,4 @@ metrics: value_type: int monotonic: true aggregation: cumulative - attributes: [ database ] + attributes: [database] diff --git a/receiver/postgresqlreceiver/scraper.go b/receiver/postgresqlreceiver/scraper.go index 6730dfa6bc75..112b00401177 100644 --- a/receiver/postgresqlreceiver/scraper.go +++ b/receiver/postgresqlreceiver/scraper.go @@ -23,16 +23,49 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/scrapererror" + "go.opentelemetry.io/collector/service/featuregate" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver/internal/metadata" ) +const ( + emitMetricsWithResourceAttributesFeatureGateID = "receiver.postgresql.emitMetricsWithResourceAttributes" + emitMetricsWithoutResourceAttributesFeatureGateID = "receiver.postgresql.emitMetricsWithoutResourceAttributes" +) + +var ( + emitMetricsWithoutResourceAttributes = featuregate.Gate{ + ID: emitMetricsWithoutResourceAttributesFeatureGateID, + Enabled: true, + Description: "Postgresql metrics are transitioning from being reported with identifying metric attributes " + + "to being identified via resource attributes in order to fit the OpenTelemetry specification. This feature " + + "gate controls emitting the old metrics without resource attributes. For more details, see: " + + "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/postgresqlreceiver/README.md#feature-gate-configurations", + } + + emitMetricsWithResourceAttributes = featuregate.Gate{ + ID: emitMetricsWithResourceAttributesFeatureGateID, + Enabled: false, + Description: "Postgresql metrics are transitioning from being reported with identifying metric attributes " + + "to being identified via resource attributes in order to fit the OpenTelemetry specification. This feature " + + "gate controls emitting the new metrics with resource attributes. For more details, see: " + + "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/postgresqlreceiver/README.md#feature-gate-configurations", + } +) + +func init() { + featuregate.GetRegistry().MustRegister(emitMetricsWithoutResourceAttributes) + featuregate.GetRegistry().MustRegister(emitMetricsWithResourceAttributes) +} + type postgreSQLScraper struct { - logger *zap.Logger - config *Config - clientFactory postgreSQLClientFactory - mb *metadata.MetricsBuilder + logger *zap.Logger + config *Config + clientFactory postgreSQLClientFactory + mb *metadata.MetricsBuilder + emitMetricsWithoutResourceAttributes bool + emitMetricsWithResourceAttributes bool } type postgreSQLClientFactory interface { @@ -57,10 +90,12 @@ func newPostgreSQLScraper( clientFactory postgreSQLClientFactory, ) *postgreSQLScraper { return &postgreSQLScraper{ - logger: settings.Logger, - config: config, - clientFactory: clientFactory, - mb: metadata.NewMetricsBuilder(config.Metrics, settings.BuildInfo), + logger: settings.Logger, + config: config, + clientFactory: clientFactory, + mb: metadata.NewMetricsBuilder(config.Metrics, settings.BuildInfo), + emitMetricsWithResourceAttributes: featuregate.GetRegistry().IsEnabled(emitMetricsWithResourceAttributesFeatureGateID), + emitMetricsWithoutResourceAttributes: featuregate.GetRegistry().IsEnabled(emitMetricsWithoutResourceAttributesFeatureGateID), } } @@ -133,15 +168,30 @@ func (p *postgreSQLScraper) retrieveDBMetrics( } func (p *postgreSQLScraper) recordDatabase(now pcommon.Timestamp, db string, r *dbRetrieval) { - if activeConnections, ok := r.activityMap[databaseName(db)]; ok { - p.mb.RecordPostgresqlBackendsDataPoint(now, activeConnections, db) - } - if size, ok := r.dbSizeMap[databaseName(db)]; ok { - p.mb.RecordPostgresqlDbSizeDataPoint(now, size, db) - } - if stats, ok := r.dbStats[databaseName(db)]; ok { - p.mb.RecordPostgresqlCommitsDataPoint(now, stats.transactionCommitted, db) - p.mb.RecordPostgresqlRollbacksDataPoint(now, stats.transactionRollback, db) + dbName := databaseName(db) + if p.emitMetricsWithResourceAttributes { + if activeConnections, ok := r.activityMap[dbName]; ok { + p.mb.RecordPostgresqlBackendsDataPointWithoutDatabase(now, activeConnections) + } + if size, ok := r.dbSizeMap[dbName]; ok { + p.mb.RecordPostgresqlDbSizeDataPointWithoutDatabase(now, size) + } + if stats, ok := r.dbStats[dbName]; ok { + p.mb.RecordPostgresqlCommitsDataPointWithoutDatabase(now, stats.transactionCommitted) + p.mb.RecordPostgresqlRollbacksDataPointWithoutDatabase(now, stats.transactionRollback) + } + p.mb.EmitForResource(metadata.WithPostgresqlDatabaseName(db)) + } else { + if activeConnections, ok := r.activityMap[dbName]; ok { + p.mb.RecordPostgresqlBackendsDataPoint(now, activeConnections, db) + } + if size, ok := r.dbSizeMap[dbName]; ok { + p.mb.RecordPostgresqlDbSizeDataPoint(now, size, db) + } + if stats, ok := r.dbStats[dbName]; ok { + p.mb.RecordPostgresqlCommitsDataPoint(now, stats.transactionCommitted, db) + p.mb.RecordPostgresqlRollbacksDataPoint(now, stats.transactionRollback, db) + } } } @@ -157,22 +207,48 @@ func (p *postgreSQLScraper) collectTables(ctx context.Context, now pcommon.Times } for tableKey, tm := range tableMetrics { - p.mb.RecordPostgresqlRowsDataPoint(now, tm.dead, db, tm.table, metadata.AttributeStateDead) - p.mb.RecordPostgresqlRowsDataPoint(now, tm.live, db, tm.table, metadata.AttributeStateLive) - p.mb.RecordPostgresqlOperationsDataPoint(now, tm.inserts, db, tm.table, metadata.AttributeOperationIns) - p.mb.RecordPostgresqlOperationsDataPoint(now, tm.del, db, tm.table, metadata.AttributeOperationDel) - p.mb.RecordPostgresqlOperationsDataPoint(now, tm.upd, db, tm.table, metadata.AttributeOperationUpd) - p.mb.RecordPostgresqlOperationsDataPoint(now, tm.hotUpd, db, tm.table, metadata.AttributeOperationHotUpd) - br, ok := blockReads[tableKey] - if ok { - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.heapRead, db, br.table, metadata.AttributeSourceHeapRead) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.heapHit, db, br.table, metadata.AttributeSourceHeapHit) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.idxRead, db, br.table, metadata.AttributeSourceIdxRead) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.idxHit, db, br.table, metadata.AttributeSourceIdxHit) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.toastHit, db, br.table, metadata.AttributeSourceToastHit) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.toastRead, db, br.table, metadata.AttributeSourceToastRead) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.tidxRead, db, br.table, metadata.AttributeSourceTidxRead) - p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.tidxHit, db, br.table, metadata.AttributeSourceTidxHit) + if p.emitMetricsWithResourceAttributes { + p.mb.RecordPostgresqlRowsDataPointWithoutDatabaseAndTable(now, tm.dead, metadata.AttributeStateDead) + p.mb.RecordPostgresqlRowsDataPointWithoutDatabaseAndTable(now, tm.live, metadata.AttributeStateLive) + p.mb.RecordPostgresqlOperationsDataPointWithoutDatabaseAndTable(now, tm.inserts, metadata.AttributeOperationIns) + p.mb.RecordPostgresqlOperationsDataPointWithoutDatabaseAndTable(now, tm.del, metadata.AttributeOperationDel) + p.mb.RecordPostgresqlOperationsDataPointWithoutDatabaseAndTable(now, tm.upd, metadata.AttributeOperationUpd) + p.mb.RecordPostgresqlOperationsDataPointWithoutDatabaseAndTable(now, tm.hotUpd, metadata.AttributeOperationHotUpd) + + br, ok := blockReads[tableKey] + if ok { + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.heapRead, metadata.AttributeSourceHeapRead) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.heapHit, metadata.AttributeSourceHeapHit) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.idxRead, metadata.AttributeSourceIdxRead) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.idxHit, metadata.AttributeSourceIdxHit) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.toastHit, metadata.AttributeSourceToastHit) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.toastRead, metadata.AttributeSourceToastHit) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.tidxRead, metadata.AttributeSourceTidxRead) + p.mb.RecordPostgresqlBlocksReadDataPointWithoutDatabaseAndTable(now, br.tidxHit, metadata.AttributeSourceTidxHit) + } + p.mb.EmitForResource( + metadata.WithPostgresqlDatabaseName(db), + metadata.WithPostgresqlTableName(tm.table), + ) + } else { + p.mb.RecordPostgresqlRowsDataPoint(now, tm.dead, db, tm.table, metadata.AttributeStateDead) + p.mb.RecordPostgresqlRowsDataPoint(now, tm.live, db, tm.table, metadata.AttributeStateLive) + p.mb.RecordPostgresqlOperationsDataPoint(now, tm.inserts, db, tm.table, metadata.AttributeOperationIns) + p.mb.RecordPostgresqlOperationsDataPoint(now, tm.del, db, tm.table, metadata.AttributeOperationDel) + p.mb.RecordPostgresqlOperationsDataPoint(now, tm.upd, db, tm.table, metadata.AttributeOperationUpd) + p.mb.RecordPostgresqlOperationsDataPoint(now, tm.hotUpd, db, tm.table, metadata.AttributeOperationHotUpd) + + br, ok := blockReads[tableKey] + if ok { + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.heapRead, db, br.table, metadata.AttributeSourceHeapRead) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.heapHit, db, br.table, metadata.AttributeSourceHeapHit) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.idxRead, db, br.table, metadata.AttributeSourceIdxRead) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.idxHit, db, br.table, metadata.AttributeSourceIdxHit) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.toastHit, db, br.table, metadata.AttributeSourceToastHit) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.toastRead, db, br.table, metadata.AttributeSourceToastRead) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.tidxRead, db, br.table, metadata.AttributeSourceTidxRead) + p.mb.RecordPostgresqlBlocksReadDataPoint(now, br.tidxHit, db, br.table, metadata.AttributeSourceTidxHit) + } } } } diff --git a/receiver/postgresqlreceiver/scraper_test.go b/receiver/postgresqlreceiver/scraper_test.go index 2abc39a9aea7..09ac78d44a40 100644 --- a/receiver/postgresqlreceiver/scraper_test.go +++ b/receiver/postgresqlreceiver/scraper_test.go @@ -92,6 +92,44 @@ func TestScraperNoDatabaseMultiple(t *testing.T) { require.NoError(t, scrapertest.CompareMetrics(expectedMetrics, actualMetrics)) } +func TestScraperWithResourceAttributeFeatureGate(t *testing.T) { + factory := mockClientFactory{} + factory.initMocks([]string{"otel", "open", "telemetry"}) + + cfg := createDefaultConfig().(*Config) + scraper := newPostgreSQLScraper(componenttest.NewNopReceiverCreateSettings(), cfg, &factory) + scraper.emitMetricsWithResourceAttributes = true + scraper.emitMetricsWithoutResourceAttributes = false + + actualMetrics, err := scraper.scrape(context.Background()) + require.NoError(t, err) + + expectedFile := filepath.Join("testdata", "scraper", "multiple", "expected_with_resource.json") + expectedMetrics, err := golden.ReadMetrics(expectedFile) + require.NoError(t, err) + + require.NoError(t, scrapertest.CompareMetrics(expectedMetrics, actualMetrics)) +} + +func TestScraperWithResourceAttributeFeatureGateSingle(t *testing.T) { + factory := mockClientFactory{} + factory.initMocks([]string{"otel"}) + + cfg := createDefaultConfig().(*Config) + scraper := newPostgreSQLScraper(componenttest.NewNopReceiverCreateSettings(), cfg, &factory) + scraper.emitMetricsWithResourceAttributes = true + scraper.emitMetricsWithoutResourceAttributes = false + + actualMetrics, err := scraper.scrape(context.Background()) + require.NoError(t, err) + + expectedFile := filepath.Join("testdata", "scraper", "otel", "expected_with_resource.json") + expectedMetrics, err := golden.ReadMetrics(expectedFile) + require.NoError(t, err) + + require.NoError(t, scrapertest.CompareMetrics(expectedMetrics, actualMetrics)) +} + type mockClientFactory struct{ mock.Mock } type mockClient struct{ mock.Mock } diff --git a/receiver/postgresqlreceiver/testdata/integration/expected_all_with_resource_attributes.json b/receiver/postgresqlreceiver/testdata/integration/expected_all_with_resource_attributes.json new file mode 100644 index 000000000000..b0a6dfd0c3b6 --- /dev/null +++ b/receiver/postgresqlreceiver/testdata/integration/expected_all_with_resource_attributes.json @@ -0,0 +1,1194 @@ +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "postgres" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "11" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "7256600" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.backends", + "description": "The number of backends.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "3" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "92" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "7256600" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table1" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "20" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "7256600" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel2" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.test2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel2" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.test1" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1660149731480073000", + "timeUnixNano": "1660149741492944000", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + } + ] +} diff --git a/receiver/postgresqlreceiver/testdata/scraper/multiple/expected_with_resource.json b/receiver/postgresqlreceiver/testdata/scraper/multiple/expected_with_resource.json new file mode 100644 index 000000000000..6112dad4ea68 --- /dev/null +++ b/receiver/postgresqlreceiver/testdata/scraper/multiple/expected_with_resource.json @@ -0,0 +1,1708 @@ +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.backends", + "description": "The number of backends.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "3" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "1" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "4" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "2" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table1" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "19" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "20" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "21" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "22" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "24" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "23" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "25" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "26" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "39" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "41" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "40" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "42" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "8" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "7" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "27" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "28" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "29" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "30" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "32" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "31" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "33" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "34" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "43" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "45" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "44" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "46" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "10" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "9" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "open" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.backends", + "description": "The number of backends.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "4" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "2" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "5" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "3" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "open" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table1" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "20" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "21" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "22" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "23" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "25" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "24" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "26" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "27" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "40" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "42" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "41" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "43" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "9" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "8" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "open" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "28" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "29" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "30" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "31" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "33" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "32" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "34" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "35" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "44" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "46" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "45" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "47" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "11" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "10" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "telemetry" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.backends", + "description": "The number of backends.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "5" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "3" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "6" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "4" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "telemetry" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table1" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "21" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "22" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "23" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "24" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "26" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "25" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "27" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "28" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "41" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "43" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "42" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "44" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "10" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "9" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "telemetry" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "29" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "30" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "31" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "32" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "34" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "33" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "35" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "36" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "45" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "47" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "46" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "48" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "12" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659729983548135000", + "timeUnixNano": "1659729983548240000", + "asInt": "11" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/receiver/postgresqlreceiver/testdata/scraper/otel/expected_with_resource.json b/receiver/postgresqlreceiver/testdata/scraper/otel/expected_with_resource.json new file mode 100644 index 000000000000..dcd3a9ff3d30 --- /dev/null +++ b/receiver/postgresqlreceiver/testdata/scraper/otel/expected_with_resource.json @@ -0,0 +1,572 @@ +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.backends", + "description": "The number of backends.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "3" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.commits", + "description": "The number of commits.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "1" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.db_size", + "description": "The database disk usage.", + "unit": "By", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "4" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "postgresql.rollbacks", + "description": "The number of rollbacks.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "2" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table2" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "27" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "28" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "29" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "30" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "32" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "31" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "33" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "34" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "43" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "45" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "44" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "46" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "10" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "9" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "postgresql.database.name", + "value": { + "stringValue": "otel" + } + }, + { + "key": "postgresql.table.name", + "value": { + "stringValue": "public.table1" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "otelcol/postgresqlreceiver", + "version": "latest" + }, + "metrics": [ + { + "name": "postgresql.blocks_read", + "description": "The number of blocks read.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_read" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "19" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "heap_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "20" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_read" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "21" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "idx_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "22" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "24" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "toast_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "23" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_read" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "25" + }, + { + "attributes": [ + { + "key": "source", + "value": { + "stringValue": "tidx_hit" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "26" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.operations", + "description": "The number of db row operations.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "ins" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "39" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "del" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "41" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "upd" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "40" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "hot_upd" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "42" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + }, + { + "name": "postgresql.rows", + "description": "The number of rows in the database.", + "unit": "1", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "dead" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "8" + }, + { + "attributes": [ + { + "key": "state", + "value": { + "stringValue": "live" + } + } + ], + "startTimeUnixNano": "1659730117884584000", + "timeUnixNano": "1659730117884734000", + "asInt": "7" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/unreleased/postgres-resource-attributes.yaml b/unreleased/postgres-resource-attributes.yaml new file mode 100755 index 000000000000..a40eb1eae11c --- /dev/null +++ b/unreleased/postgres-resource-attributes.yaml @@ -0,0 +1,25 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: postgresqlreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Moves metric attributes `table` and `database` to resource attributes. + +# One or more tracking issues related to the change +issues: [12960] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + This move has been hidden behind a featuregate. Please see https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/postgresqlreceiver/README.md#feature-gate-configurations for more information transitioning. + This affects the following metrics. + - postgresql.blocks_read + - postgresql.commits + - postgresql.db_size + - postgresql.backends + - postgresql.operations + - postgresql.rollbacks +