Skip to content

[*] refactor TryCreateMissingExtensions #1186

Open
gemy26 wants to merge 1 commit intocybertec-postgresql:masterfrom
gemy26:refactor-TryCreateMissingExtensions
Open

[*] refactor TryCreateMissingExtensions #1186
gemy26 wants to merge 1 commit intocybertec-postgresql:masterfrom
gemy26:refactor-TryCreateMissingExtensions

Conversation

@gemy26
Copy link

@gemy26 gemy26 commented Feb 8, 2026

  • Refactored TryCreateMissingExtensions to use direct pgx connection instead of the QueryMeasurements wrapper.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 21789834250

Details

  • 0 of 28 (0.0%) changed or added relevant lines in 1 file are covered.
  • 61 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-1.3%) to 75.56%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/reaper/database.go 0 28 0.0%
Files with Coverage Reduction New Missed Lines %
internal/sinks/prometheus.go 61 39.51%
Totals Coverage Status
Change from base Build 21722664308: -1.3%
Covered Lines: 4118
Relevant Lines: 5450

💛 - Coveralls

@0xgouda 0xgouda added the refactoring Something done as it should've been done from the start label Feb 10, 2026

// For security reasons don't allow to execute random strings but check that it's an existing extension
data, err := QueryMeasurements(ctx, md, sqlAvailable)
if !md.IsPostgresSource() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not a postgres source, there is no any extensions. we can return immediately

rows, err := md.Conn.Query(ctx, sqlAvailable, queryArgs...)
if err != nil {
log.GetLogger(ctx).Infof("[%s] Failed to get a list of available extensions: %v", md, err)
l.Infof("[%s] Failed to get a list of available extensions: %v", md, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not how we form logging messages

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review,
Could you clarify the correct logging format? , Should I use source-aware logger like:
l.WithField("source", md.Name).Infof("Failed to get a list of available extensions: %v", err)
Or would you prefer a different approach?

Comment on lines +497 to +502
for rows.Next() {
if err := rows.Scan(&extentionName); err != nil {
l.Infof("[%s] Failed to scan extension name: %v", md, err)
continue
}
availableExtentions[extentionName] = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's easier to use pgx.CollectRows functionality https://pkg.go.dev/github.com/jackc/pgx/v5#CollectRows

for _, row := range data {
availableExts[row["name"].(string)] = true
// For security reasons don't allow to execute random strings but check that it's an existing extension
availableExtentions := make(map[string]bool)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need map[string]bool here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for lookup when checking if extension exist since we check each extension in extensionNames against the available extensions.

if err != nil {
log.GetLogger(ctx).Errorf("[%s] Failed to create extension %s (based on --try-create-listed-exts-if-missing input): %v", md, extToCreate, err)
execArgs := []any{}
if !md.IsPostgresSource() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not a postgres source, we don't want to create any extensions. It's impossible to create extension in pg_bouncer, for example

Copy link
Collaborator

@pashagolub pashagolub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to refactor we must do it properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Something done as it should've been done from the start

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants