Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions aws/iam_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ type AuthToken struct {
}

func NewAuthToken(username, hostname string, cfg aws.Config) AuthToken {
// RDS auth tokens require the :3306 suffix
return NewAuthTokenWithDefaultPort(username, hostname, "3306", cfg)
}

// NewAuthTokenWithDefaultPort constructs an RDS authentication token signer,
// adding defaultPort when hostname does not already include a port.
func NewAuthTokenWithDefaultPort(username, hostname, defaultPort string, cfg aws.Config) AuthToken {
// RDS auth tokens require the database port in the signed endpoint.
if !portRe.MatchString(hostname) {
hostname += ":3306"
hostname += ":" + defaultPort
}

return AuthToken{
Expand Down
25 changes: 21 additions & 4 deletions blip.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const (
EVENT
)

// Metrics are metrics collected for one plan level, from one MySQL instance.
// Metrics are metrics collected for one plan level, from one monitor.
type Metrics struct {
Begin time.Time // when collection started
End time.Time // when collection completed
MonitorId string // ID of monitor (MySQL)
MonitorId string // ID of monitor
Plan string // plan name
Level string // level name
Interval uint // interval number
Expand Down Expand Up @@ -99,7 +99,7 @@ type SinkFactoryArgs struct {
Tags map[string]string // config.monitor.tags
}

// DbCredentials are MySQL credentials parsed or loaded for a connection.
// DbCredentials are database credentials parsed or loaded for a connection.
type DbCredentials struct {
Username string
Password string
Expand Down Expand Up @@ -173,7 +173,7 @@ type Plugins struct {
// ModifyDB modifies the *sql.DB connection pool. Use with caution.
ModifyDB func(*sql.DB, string)

// ParsePasswordSecret maps an AWS Secrets Manager payload to MySQL credentials.
// ParsePasswordSecret maps an AWS Secrets Manager payload to database credentials.
// If nil, Blip uses DefaultPasswordSecretParser.
ParsePasswordSecret PasswordSecretParser

Expand Down Expand Up @@ -218,6 +218,23 @@ type DbFactory interface {
Make(ConfigMonitor) (*sql.DB, string, error)
}

// DbProvider owns the database connections associated with one monitor.
// Primary returns the connection used by existing Blip subsystems and
// collectors. Close releases the primary connection and any additional
// database-specific resources owned by the provider.
type DbProvider interface {
Primary() *sql.DB
Close() error
}

// DbProviderFactory is an optional DbFactory capability for database engines
// that need to own more than one connection pool per monitor. Blip preserves
// the existing DbFactory.Make path for factories that do not implement it.
type DbProviderFactory interface {
DbFactory
MakeProvider(ConfigMonitor) (DbProvider, string, error)
}

type HTTPClientFactory interface {
MakeForSink(sinkName, monitorId string, opts, tags map[string]string) (*http.Client, error)
}
Expand Down
35 changes: 29 additions & 6 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Collector interface {
// Prepare prepares a plan for future calls to Collect. The return function
// is called once when the collector is destroyed; it allows the collector
// to clean up. If Prepare returns an error, Blip will retry preparing the
// plan. Therefore, Prepare should not retry on error (for example, if MySQL
// is not online yet).
// plan. Therefore, Prepare should not retry on error (for example, if the
// database is not online yet).
Prepare(ctx context.Context, plan Plan) (func(), error)

// Collect collects metrics for the previously prepared plan. Collect is only
Expand Down Expand Up @@ -111,13 +111,14 @@ func (h CollectorHelp) Validate(opts map[string]string) error {
// a Collector. The factory must use the args to create the collector.
type CollectorFactoryArgs struct {
// Config is the full and final monitor config. Most collectors do not need
// this, but some that collect metrics outside MySQL, like cloud metrics,
// this, but some that collect metrics outside the database, like cloud metrics,
// might need additional monitor config values.
Config ConfigMonitor

// DB is the connection to MySQL. It is safe for concurrent use, and it is
// used concurrently by other parts of a monitor. The Collector must not
// modify the connection, reconnect, and so forth--only use the connection.
// DB is the monitor's database connection. It is safe for concurrent use,
// and it is used concurrently by other parts of a monitor. The Collector
// must not modify the connection, reconnect, and so forth--only use the
// connection.
DB *sql.DB

// MonitorId is the monitor identifier. The Collector must include
Expand All @@ -135,5 +136,27 @@ type CollectorFactory interface {
Make(domain string, args CollectorFactoryArgs) (Collector, error)
}

// CollectorFactoryWithDBProvider is an optional CollectorFactory capability
// for database-specific collectors that need access to the monitor-owned
// database provider. Factories that do not implement it retain the historical
// Make behavior.
type CollectorFactoryWithDBProvider interface {
CollectorFactory
MakeWithDBProvider(domain string, args CollectorFactoryArgs, provider DbProvider) (Collector, error)
}

// CollectorFactoryDatabaseTypes is an optional CollectorFactory capability
// that identifies the database types supported by a domain. Factories that do
// not implement this interface retain Blip's historical MySQL behavior.
//
// The domain argument allows one factory to serve domains with different
// compatibility, such as MySQL collectors and database-neutral cloud metrics.
// Implementations must return at least one database type. Return
// DatabaseTypeAny by itself for a database-neutral domain.
type CollectorFactoryDatabaseTypes interface {
CollectorFactory
DatabaseTypes(domain string) []DatabaseType
}

// ErrMore signals that a collector will return more values. See https://block.github.io/blip/develop/collectors/#long-running.
var ErrMore = errors.New("more metrics")
Loading
Loading