Skip to content

Commit baedcc8

Browse files
committed
create excludes map in constructor
1 parent 987ae42 commit baedcc8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

receiver/postgresqlreceiver/scraper.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type postgreSQLScraper struct {
2424
config *Config
2525
clientFactory postgreSQLClientFactory
2626
mb *metadata.MetricsBuilder
27+
excludes map[string]struct{}
2728
}
2829
type errsMux struct {
2930
sync.RWMutex
@@ -69,11 +70,16 @@ func newPostgreSQLScraper(
6970
config *Config,
7071
clientFactory postgreSQLClientFactory,
7172
) *postgreSQLScraper {
73+
excludes := make(map[string]struct{})
74+
for _, db := range config.ExcludeDatabases {
75+
excludes[db] = struct{}{}
76+
}
7277
return &postgreSQLScraper{
7378
logger: settings.Logger,
7479
config: config,
7580
clientFactory: clientFactory,
7681
mb: metadata.NewMetricsBuilder(config.MetricsBuilderConfig, settings),
82+
excludes: excludes,
7783
}
7884
}
7985

@@ -102,13 +108,9 @@ func (p *postgreSQLScraper) scrape(ctx context.Context) (pmetric.Metrics, error)
102108
}
103109
databases = dbList
104110
}
105-
exclude := make(map[string]struct{})
106-
for _, db := range p.config.ExcludeDatabases {
107-
exclude[db] = struct{}{}
108-
}
109111
var filteredDatabases []string
110112
for _, db := range databases {
111-
if _, ok := exclude[db]; !ok {
113+
if _, ok := p.excludes[db]; !ok {
112114
filteredDatabases = append(filteredDatabases, db)
113115
}
114116
}

0 commit comments

Comments
 (0)