-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathintegration_test.go
84 lines (75 loc) · 3.07 KB
/
integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:build integration
package postgresqlreceiver
import (
"net"
"path/filepath"
"testing"
"time"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"go.opentelemetry.io/collector/component"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/scraperinttest"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
)
const postgresqlPort = "5432"
func TestIntegration(t *testing.T) {
defer testutil.SetFeatureGateForTest(t, separateSchemaAttrGate, false)()
t.Run("single_db", integrationTest("single_db", []string{"otel"}))
t.Run("multi_db", integrationTest("multi_db", []string{"otel", "otel2"}))
t.Run("all_db", integrationTest("all_db", []string{}))
}
func TestIntegrationWithSeparateSchemaAttr(t *testing.T) {
defer testutil.SetFeatureGateForTest(t, separateSchemaAttrGate, true)()
t.Run("single_db_schemaattr", integrationTest("single_db_schemaattr", []string{"otel"}))
t.Run("multi_db_schemaattr", integrationTest("multi_db_schemaattr", []string{"otel", "otel2"}))
t.Run("all_db_schemaattr", integrationTest("all_db_schemaattr", []string{}))
}
func integrationTest(name string, databases []string) func(*testing.T) {
expectedFile := filepath.Join("testdata", "integration", "expected_"+name+".yaml")
return scraperinttest.NewIntegrationTest(
NewFactory(),
scraperinttest.WithContainerRequest(
testcontainers.ContainerRequest{
Image: "postgres:9.6.24",
Env: map[string]string{
"POSTGRES_USER": "root",
"POSTGRES_PASSWORD": "otel",
"POSTGRES_DB": "otel",
},
Files: []testcontainers.ContainerFile{{
HostFilePath: filepath.Join("testdata", "integration", "init.sql"),
ContainerFilePath: "/docker-entrypoint-initdb.d/init.sql",
FileMode: 700,
}},
ExposedPorts: []string{postgresqlPort},
WaitingFor: wait.ForListeningPort(postgresqlPort).
WithStartupTimeout(2 * time.Minute),
}),
scraperinttest.WithCustomConfig(
func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
rCfg := cfg.(*Config)
rCfg.CollectionInterval = time.Second
rCfg.Endpoint = net.JoinHostPort(ci.Host(t), ci.MappedPort(t, postgresqlPort))
rCfg.Databases = databases
rCfg.Username = "otelu"
rCfg.Password = "otelp"
rCfg.Insecure = true
rCfg.Metrics.PostgresqlDeadlocks.Enabled = true
rCfg.Metrics.PostgresqlTempFiles.Enabled = true
rCfg.Metrics.PostgresqlSequentialScans.Enabled = true
rCfg.Metrics.PostgresqlDatabaseLocks.Enabled = true
}),
scraperinttest.WithExpectedFile(expectedFile),
scraperinttest.WithCompareOptions(
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreSubsequentDataPoints("postgresql.backends"),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
),
).Run
}