Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) CountAttachedProxiedRequestMetricPartitions(ctx context.Context) (int64, error)
- func (c *Client) DeleteProxiedRequestMetricsOlderThanNDays(ctx context.Context, n int64) error
- func (c *Client) Exec(query string, args ...interface{}) (sql.Result, error)
- func (c *Client) GetLastCreatedAttachedProxiedRequestMetricsPartitionName(ctx context.Context) (string, error)
- func (c *Client) HealthCheck() error
- func (c *Client) ListProxiedRequestMetricsWithPagination(ctx context.Context, cursor int64, limit int) ([]*database.ProxiedRequestMetric, int64, error)
- func (c *Client) Migrate(ctx context.Context, migrations migrate.Migrations, ...) (*migrate.MigrationSlice, error)
- func (c *Client) Partition(prefillPeriodDays int) error
- func (c *Client) SaveProxiedRequestMetric(ctx context.Context, metric *database.ProxiedRequestMetric) error
- type DatabaseConfig
- type PartitionPeriod
- type ProxiedRequestMetric
Constants ¶
const (
PartitionBaseTableName = "proxied_request_metrics"
)
const (
ProxiedRequestMetricsTableName = "proxied_request_metrics"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a connection to a postgres database
func NewClient ¶
func NewClient(config DatabaseConfig) (Client, error)
NewClient returns a new connection to the specified postgres data and error (if any)
func (*Client) CountAttachedProxiedRequestMetricPartitions ¶
CountAttachedProxiedRequestMetricPartitions returns the current count of attached partitions for the ProxiedRequestMetricsTableName and error (if any). If db is nil, returns 0 and nil error.
func (*Client) DeleteProxiedRequestMetricsOlderThanNDays ¶
DeleteProxiedRequestMetricsOlderThanNDays deletes all proxied request metrics older than the specified days, returning error (if any). Used during pruning process. If db is nil, returns nil error.
func (*Client) Exec ¶
Exec is not part of database.MetricsDatabase interface, so it is used only in the implementation for test purposes.
func (*Client) GetLastCreatedAttachedProxiedRequestMetricsPartitionName ¶
func (c *Client) GetLastCreatedAttachedProxiedRequestMetricsPartitionName(ctx context.Context) (string, error)
GetLastCreatedAttachedProxiedRequestMetricsPartitionName gets the table name for the last created (and attached) proxied request metrics partition Used for status check. If db is nil, returns empty string and nil error.
func (*Client) HealthCheck ¶
HealthCheck returns an error if the database can not be connected to and queried, nil otherwise
func (*Client) ListProxiedRequestMetricsWithPagination ¶
func (c *Client) ListProxiedRequestMetricsWithPagination(ctx context.Context, cursor int64, limit int) ([]*database.ProxiedRequestMetric, int64, error)
ListProxiedRequestMetricsWithPagination returns a page of max `limit` ProxiedRequestMetrics from the offset specified by`cursor` error (if any) along with a cursor to use to fetch the next page if the cursor is 0 no more pages exists. Uses only in tests. If db is nil, returns empty slice and 0 cursor.
func (*Client) Migrate ¶
func (c *Client) Migrate(ctx context.Context, migrations migrate.Migrations, logger *logging.ServiceLogger) (*migrate.MigrationSlice, error)
Migrate sets up and runs all migrations in the migrations model that haven't been run on the database being used by the proxy service returning error (if any) and a list of migrations that have been run and any that were not
func (*Client) Partition ¶
partition attempts to create (idempotently) future partitions for storing proxied request metrics, returning error (if any)
func (*Client) SaveProxiedRequestMetric ¶
func (c *Client) SaveProxiedRequestMetric(ctx context.Context, metric *database.ProxiedRequestMetric) error
Save saves the current ProxiedRequestMetric to the database, returning error (if any). If db is nil, returns nil error.
type DatabaseConfig ¶
type DatabaseConfig struct { DatabaseName string DatabaseEndpointURL string DatabaseUsername string DatabasePassword string ReadTimeoutSeconds int64 WriteTimeoutSeconds int64 DatabaseMaxIdleConnections int64 DatabaseConnectionMaxIdleSeconds int64 DatabaseMaxOpenConnections int64 SSLEnabled bool QueryLoggingEnabled bool RunDatabaseMigrations bool Logger *logging.ServiceLogger }
DatabaseConfig contains values for creating a new connection to a postgres database
type PartitionPeriod ¶
type PartitionPeriod struct { TableName string InclusiveStartPeriod time.Time ExclusiveEndPeriod time.Time }
PartitionPeriod represents a single postgres partitioned table from a starting point (inclusive of that point in time) to an end point (exclusive of that point in time)
func PartitionsForPeriod ¶
func PartitionsForPeriod(start time.Time, numDaysToPrefill int) ([]PartitionPeriod, error)
PartitionsForPeriod attempts to generate the partitions to create when prefilling numDaysToPrefill, returning the list of of partitions and error (if any)
type ProxiedRequestMetric ¶
type ProxiedRequestMetric struct { bun.BaseModel `bun:"table:proxied_request_metrics,alias:prm"` ID int64 `bun:",pk,autoincrement"` MethodName string BlockNumber *int64 ResponseLatencyMilliseconds int64 Hostname string RequestIP string `bun:"request_ip"` RequestTime time.Time UserAgent *string Referer *string Origin *string ResponseBackend string ResponseBackendRoute string CacheHit bool PartOfBatch bool }
ProxiedRequestMetric contains request metrics for a single request proxied by the proxy service
func (*ProxiedRequestMetric) ToProxiedRequestMetric ¶
func (prm *ProxiedRequestMetric) ToProxiedRequestMetric() *database.ProxiedRequestMetric
Directories ¶
Path | Synopsis |
---|---|
when this package is loaded the package directory will be searched for any go or sql migration files and register for them to the proxy service to run https://bun.uptrace.dev/guide/migrations.html#go-based-migrations
|
when this package is loaded the package directory will be searched for any go or sql migration files and register for them to the proxy service to run https://bun.uptrace.dev/guide/migrations.html#go-based-migrations |