postgres

package
v0.0.0-...-2473a21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PartitionBaseTableName = "proxied_request_metrics"
)
View Source
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

func (c *Client) CountAttachedProxiedRequestMetricPartitions(ctx context.Context) (int64, error)

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

func (c *Client) DeleteProxiedRequestMetricsOlderThanNDays(ctx context.Context, n int64) error

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

func (c *Client) Exec(query string, args ...interface{}) (sql.Result, error)

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

func (c *Client) HealthCheck() error

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

func (c *Client) Partition(prefillPeriodDays int) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL