Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsaks committed Oct 8, 2024
1 parent 3e48d5a commit 22fe659
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion metricbeat/module/pgbouncer/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
/*
Package pgbouncer is a Metricbeat module that contains MetricSets.
*/
package pgbouncer
package pgbouncer
8 changes: 7 additions & 1 deletion metricbeat/module/pgbouncer/metricset.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package pgbouncer

import (
"context"
"database/sql"
Expand All @@ -8,14 +9,17 @@ import (
// Register pgbouncer database/sql driver
_ "github.com/lib/pq"
)

type MetricSet struct {
mb.BaseMetricSet
db *sql.DB
}

// NewMetricSet creates a pgbouncer metricset with a pool of connections
func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
return &MetricSet{BaseMetricSet: base}, nil
}

// DB creates a database connection, it must be freed after use with `Close()`
func (ms *MetricSet) DB(ctx context.Context) (*sql.Conn, error) {
if ms.db == nil {
Expand All @@ -27,6 +31,7 @@ func (ms *MetricSet) DB(ctx context.Context) (*sql.Conn, error) {
}
return ms.db.Conn(ctx)
}

// QueryStats makes the database call for a given metric
func (ms *MetricSet) QueryStats(ctx context.Context, query string) ([]map[string]interface{}, error) {
db, err := ms.DB(ctx)
Expand Down Expand Up @@ -62,6 +67,7 @@ func (ms *MetricSet) QueryStats(ctx context.Context, query string) ([]map[string
}
return results, nil
}

// Close closes the metricset and its connections
func (ms *MetricSet) Close() error {
if ms.db == nil {
Expand All @@ -71,4 +77,4 @@ func (ms *MetricSet) Close() error {
return fmt.Errorf("failed to close connection: %w", err)
}
return nil
}
}
4 changes: 2 additions & 2 deletions metricbeat/module/pgbouncer/pgbouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestParseUrl(t *testing.T) {
Username: test.Username,
Password: test.Password,
Timeout: test.Timeout,
RequireUsername: test.RequireUsername, // Ustawienie na podstawie testu
RequireUsername: test.RequireUsername,
}

hostData, err := ParseURL(mod, test.URL)
Expand All @@ -139,7 +139,7 @@ type MockModule struct {
Username string
Password string
Timeout time.Duration
RequireUsername bool // Defaultowo false
RequireUsername bool
}

func (m *MockModule) UnpackConfig(to interface{}) error {
Expand Down

0 comments on commit 22fe659

Please sign in to comment.