Skip to content

Commit

Permalink
[receiver/postgresql] Transition receiver/postgresql to resource at…
Browse files Browse the repository at this point in the history
…tributes by default (#13812)

* transition postgresqlreceiver to use resource attributes by default
  • Loading branch information
schmikei authored Sep 6, 2022
1 parent a76b8cc commit e6b6ac7
Show file tree
Hide file tree
Showing 9 changed files with 6,469 additions and 5,848 deletions.
10 changes: 6 additions & 4 deletions receiver/postgresqlreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ func TestPostgreSQLIntegration(t *testing.T) {
expectedFile: filepath.Join("testdata", "integration", "expected_all_db.json"),
},
{
name: "with_resource_attributes",
name: "without_resource_attributes",
cfg: func(hostname string) *Config {
require.NoError(t, featuregate.GetRegistry().Apply(map[string]bool{
emitMetricsWithResourceAttributesFeatureGateID: true,
emitMetricsWithResourceAttributesFeatureGateID: false,
emitMetricsWithoutResourceAttributesFeatureGateID: true,
}))
f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
Expand All @@ -109,10 +110,11 @@ func TestPostgreSQLIntegration(t *testing.T) {
},
cleanup: func() {
require.NoError(t, featuregate.GetRegistry().Apply(map[string]bool{
emitMetricsWithResourceAttributesFeatureGateID: false,
emitMetricsWithResourceAttributesFeatureGateID: true,
emitMetricsWithoutResourceAttributesFeatureGateID: false,
}))
},
expectedFile: filepath.Join("testdata", "integration", "expected_all_with_resource_attributes.json"),
expectedFile: filepath.Join("testdata", "integration", "expected_all_without_resource_attributes.json"),
},
}

Expand Down
4 changes: 2 additions & 2 deletions receiver/postgresqlreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
var (
emitMetricsWithoutResourceAttributes = featuregate.Gate{
ID: emitMetricsWithoutResourceAttributesFeatureGateID,
Enabled: true,
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 old metrics without resource attributes. For more details, see: " +
Expand All @@ -48,7 +48,7 @@ var (

emitMetricsWithResourceAttributes = featuregate.Gate{
ID: emitMetricsWithResourceAttributesFeatureGateID,
Enabled: false,
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 new metrics with resource attributes. For more details, see: " +
Expand Down
13 changes: 9 additions & 4 deletions receiver/postgresqlreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestUnsuccessfulScrape(t *testing.T) {
cfg.Endpoint = "fake:11111"

scraper := newPostgreSQLScraper(componenttest.NewNopReceiverCreateSettings(), cfg, &defaultClientFactory{})
scraper.emitMetricsWithResourceAttributes = false
scraper.emitMetricsWithoutResourceAttributes = true

actualMetrics, err := scraper.scrape(context.Background())
require.Error(t, err)

Expand All @@ -48,6 +51,8 @@ func TestScraper(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Databases = []string{"otel"}
scraper := newPostgreSQLScraper(componenttest.NewNopReceiverCreateSettings(), cfg, factory)
scraper.emitMetricsWithResourceAttributes = false
scraper.emitMetricsWithoutResourceAttributes = true

actualMetrics, err := scraper.scrape(context.Background())
require.NoError(t, err)
Expand All @@ -65,6 +70,8 @@ func TestScraperNoDatabaseSingle(t *testing.T) {

cfg := createDefaultConfig().(*Config)
scraper := newPostgreSQLScraper(componenttest.NewNopReceiverCreateSettings(), cfg, factory)
scraper.emitMetricsWithResourceAttributes = false
scraper.emitMetricsWithoutResourceAttributes = true

actualMetrics, err := scraper.scrape(context.Background())
require.NoError(t, err)
Expand All @@ -82,6 +89,8 @@ func TestScraperNoDatabaseMultiple(t *testing.T) {

cfg := createDefaultConfig().(*Config)
scraper := newPostgreSQLScraper(componenttest.NewNopReceiverCreateSettings(), cfg, &factory)
scraper.emitMetricsWithResourceAttributes = false
scraper.emitMetricsWithoutResourceAttributes = true

actualMetrics, err := scraper.scrape(context.Background())
require.NoError(t, err)
Expand All @@ -99,8 +108,6 @@ func TestScraperWithResourceAttributeFeatureGate(t *testing.T) {

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)
Expand All @@ -118,8 +125,6 @@ func TestScraperWithResourceAttributeFeatureGateSingle(t *testing.T) {

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)
Expand Down
Loading

0 comments on commit e6b6ac7

Please sign in to comment.