forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add postgres receiver (open-telemetry#2564)
- Loading branch information
Showing
10 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright Splunk, Inc. | ||
// 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. | ||
|
||
//go:build integration | ||
|
||
package tests | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/signalfx/splunk-otel-collector/tests/testutils" | ||
) | ||
|
||
var postgresqldb = []testutils.Container{testutils.NewContainer().WithContext( | ||
path.Join(".", "testdata", "server"), | ||
).WithName("postgresqldb").WithExposedPorts("15432:5432").WillWaitForLogs("database system is ready to accept connections")} | ||
|
||
// This test ensures the collector can connect to a PostgreSQL DB, and properly get metrics. It's not intended to | ||
// test the receiver itself. | ||
func TestPostgresqlDBIntegration(t *testing.T) { | ||
tc := testutils.NewTestcase(t) | ||
defer tc.PrintLogsOnFailure() | ||
defer tc.ShutdownOTLPReceiverSink() | ||
|
||
_, stop := tc.Containers(postgresqldb...) | ||
defer stop() | ||
|
||
_, shutdown := tc.SplunkOtelCollector( | ||
"all_metrics_config.yaml", | ||
func(collector testutils.Collector) testutils.Collector { | ||
return collector.WithEnv(map[string]string{ | ||
"POSTGRESQLDB_ENDPOINT": "localhost:15432", | ||
"POSTGRESQLDB_USERNAME": "otelu", | ||
"POSTGRESQLDB_PASSWORD": "otelp", | ||
}) | ||
}, | ||
) | ||
defer shutdown() | ||
|
||
expectedResourceMetrics := tc.ResourceMetrics("all.yaml") | ||
require.NoError(t, tc.OTLPReceiverSink.AssertAllMetricsReceived(t, *expectedResourceMetrics, 30*time.Second)) | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/receivers/postgresql/testdata/all_metrics_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
receivers: | ||
postgresql: | ||
endpoint: "${POSTGRESQLDB_ENDPOINT}" | ||
username: "${POSTGRESQLDB_USERNAME}" | ||
password: "${POSTGRESQLDB_PASSWORD}" | ||
databases: | ||
- otel | ||
- otel2 | ||
tls: | ||
insecure: true | ||
exporters: | ||
otlp: | ||
endpoint: "${OTLP_ENDPOINT}" | ||
tls: | ||
insecure: true | ||
|
||
|
||
service: | ||
telemetry: | ||
logs: | ||
level: "debug" | ||
pipelines: | ||
metrics: | ||
receivers: | ||
- postgresql | ||
exporters: [otlp] |
109 changes: 109 additions & 0 deletions
109
tests/receivers/postgresql/testdata/resource_metrics/all.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
resource_metrics: | ||
- attributes: | ||
postgresql.database.name: <ANY> | ||
scope_metrics: | ||
- instrumentation_scope: | ||
name: otelcol/postgresqlreceiver | ||
version: <ANY> | ||
metrics: | ||
- name: postgresql.commits | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.db_size | ||
type: IntNonmonotonicCumulativeSum | ||
- name: postgresql.rollbacks | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.table.count | ||
type: IntNonmonotonicCumulativeSum | ||
- attributes: | ||
postgresql.database.name: <ANY> | ||
postgresql.index.name: <ANY> | ||
postgresql.table.name: <ANY> | ||
scope_metrics: | ||
- instrumentation_scope: | ||
name: otelcol/postgresqlreceiver | ||
version: <ANY> | ||
metrics: | ||
- name: postgresql.index.scans | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.index.size | ||
type: IntGauge | ||
- attributes: | ||
postgresql.database.name: <ANY> | ||
postgresql.table.name: <ANY> | ||
scope_metrics: | ||
- instrumentation_scope: | ||
name: otelcol/postgresqlreceiver | ||
version: <ANY> | ||
metrics: | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: heap_read | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: heap_hit | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: idx_read | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: idx_hit | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: toast_hit | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: tidx_read | ||
- name: postgresql.blocks_read | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
source: tidx_hit | ||
- name: postgresql.operations | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
operation: del | ||
- name: postgresql.operations | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
operation: upd | ||
- name: postgresql.operations | ||
type: IntMonotonicCumulativeSum | ||
attributes: | ||
operation: hot_upd | ||
- name: postgresql.rows | ||
type: IntNonmonotonicCumulativeSum | ||
attributes: | ||
state: dead | ||
- name: postgresql.rows | ||
type: IntNonmonotonicCumulativeSum | ||
attributes: | ||
state: live | ||
- name: postgresql.table.size | ||
type: IntNonmonotonicCumulativeSum | ||
- name: postgresql.table.vacuum.count | ||
type: IntMonotonicCumulativeSum | ||
- attributes: {} | ||
scope_metrics: | ||
- instrumentation_scope: | ||
name: otelcol/postgresqlreceiver | ||
version: <ANY> | ||
metrics: | ||
- name: postgresql.bgwriter.buffers.allocated | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.bgwriter.buffers.writes | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.bgwriter.checkpoint.count | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.bgwriter.duration | ||
type: DoubleMonotonicCumulativeSum | ||
- name: postgresql.bgwriter.maxwritten | ||
type: IntMonotonicCumulativeSum | ||
- name: postgresql.connection.max | ||
type: IntGauge | ||
- name: postgresql.database.count | ||
type: IntNonmonotonicCumulativeSum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM postgres:15-alpine | ||
|
||
ENV POSTGRES_USER=root | ||
ENV POSTGRES_PASSWORD=otel | ||
ENV POSTGRES_DB=otel | ||
|
||
COPY initPostgresqlDB.sql /docker-entrypoint-initdb.d/ |
26 changes: 26 additions & 0 deletions
26
tests/receivers/postgresql/testdata/server/initPostgresqlDB.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
CREATE USER otelu WITH PASSWORD 'otelp'; | ||
GRANT SELECT ON pg_stat_database TO otelu; | ||
|
||
CREATE TABLE table1 ( | ||
id serial PRIMARY KEY | ||
); | ||
CREATE TABLE table2 ( | ||
id serial PRIMARY KEY | ||
); | ||
|
||
CREATE DATABASE otel2 OWNER otelu; | ||
\c otel2 | ||
CREATE TABLE test1 ( | ||
id serial PRIMARY KEY | ||
); | ||
CREATE TABLE test2 ( | ||
id serial PRIMARY KEY | ||
); | ||
|
||
CREATE INDEX otelindex ON test1(id); | ||
CREATE INDEX otel2index ON test2(id); | ||
|
||
-- Generating usage of index | ||
INSERT INTO test2 (id) | ||
VALUES(67); | ||
SELECT * FROM test2; |