postgres

package
v0.0.0-...-f54f16c Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transact

func Transact(pg *Postgres, txFunc func(*DBTrans) error) error

Transact wraps your calls in a transaction. If the call should fail with an error it will perform a rollback. Otherwise the transaction will be committed.

Types

type DBTrans

type DBTrans struct {
	*gorp.Transaction
}

func (*DBTrans) StoreTelemetry

func (trans *DBTrans) StoreTelemetry(ctx context.Context, lastTelemetryReportedAt time.Time) error

StoreTelemetry Store last application service telemetry reported timestamp

type Postgres

type Postgres struct {
	*gorp.DbMap
	*config.Postgres
}

Postgres is a wrapping struct that will hold the database mapping object from the underlying db/sql implementation (gorp) plus our service config specifically for storage.

Additionally this struct implements our storage.Client interface

func Connect

func Connect(dbConf *config.Postgres) (*Postgres, error)

func ConnectAndMigrate

func ConnectAndMigrate(dbConf *config.Postgres) (*Postgres, error)

New creates a new Postgres client, connects to the database server and runs the migrations

func (*Postgres) DeleteDisconnectedServices

func (db *Postgres) DeleteDisconnectedServices(thresholdSeconds int32) ([]*storage.Service, error)

DeleteDisconnectedServices deletes any service records where the time elapsed since the last event is greater than the specified thresholdMinutes. After deleting the services, it also removes all supervisor, service_group, and deployment records that are not referenced by any service record because the application treats these things as emergent properties of groups of services so they shouldn't exist if there are no associated services. This also prevents the need for a second cleanup operation to delete these things.

func (*Postgres) DeleteServicesByID

func (db *Postgres) DeleteServicesByID(svcIDs []string) ([]*storage.Service, error)

func (*Postgres) DestructiveMigrateForTests

func (db *Postgres) DestructiveMigrateForTests() error

func (*Postgres) EmptyStorage

func (db *Postgres) EmptyStorage() error

EmptyStorage deletes all the data from the database @afiune This function is only used by our Integration Test framework

func (*Postgres) GetDeploymentsCount

func (db *Postgres) GetDeploymentsCount() (int32, error)

func (*Postgres) GetDisconnectedServices

func (db *Postgres) GetDisconnectedServices(thresholdSeconds int32) ([]*storage.Service, error)

GetDisconnectedServices returns a list of disconnected services

func (*Postgres) GetServiceFromUniqueFields

func (db *Postgres) GetServiceFromUniqueFields(name, member string) (*storage.Service, bool)

GetServiceFromUniqueFields retrieves a service from the db without the need of an id, it is based on the unique fields, name and member id

func (*Postgres) GetServiceGroups

func (db *Postgres) GetServiceGroups(
	sortField string, sortAsc bool,
	page int32, pageSize int32,
	filters map[string][]string) ([]*storage.ServiceGroupDisplay, error)

func (*Postgres) GetServiceGroupsCount

func (db *Postgres) GetServiceGroupsCount() (int32, error)

func (*Postgres) GetServiceGroupsHealthCounts

func (db *Postgres) GetServiceGroupsHealthCounts(filters map[string][]string) (*storage.HealthCounts, error)

GetServiceGroupsHealthCounts retrieves the health counts from all service groups in the database

func (*Postgres) GetServices

func (db *Postgres) GetServices(
	sortField string, sortAsc bool,
	page int32, pageSize int32,
	filters map[string][]string,
) ([]*storage.Service, error)

GetServices returns a list of services

func (*Postgres) GetServicesCount

func (db *Postgres) GetServicesCount() (int32, error)

func (*Postgres) GetServicesDistinctValues

func (db *Postgres) GetServicesDistinctValues(fieldName, queryFragment string, filters map[string][]string) ([]string, error)

func (*Postgres) GetServicesHealthCounts

func (db *Postgres) GetServicesHealthCounts(filters map[string][]string) (*storage.HealthCounts, error)

GetServicesHealthCounts retrieves the health counts from all services in the database. This function accepts a set of filters that can be applied to the SQL query to get the health counts of a subset of the services in the database

func (*Postgres) GetSupervisorsCount

func (db *Postgres) GetSupervisorsCount() (int32, error)

func (*Postgres) GetTelemetry

func (db *Postgres) GetTelemetry(ctx context.Context) (storage.Telemetry, error)

Get last services telemetry reported timestamp

func (*Postgres) GetUniqueServicesFromPostgres

func (db *Postgres) GetUniqueServicesFromPostgres(daysSinceLastPost int64, lastTelemetryReportedAt time.Time) (int64, error)

Get last 15 days services telemetry reported timestamp

func (*Postgres) IngestHealthCheckEvent

func (db *Postgres) IngestHealthCheckEvent(event *habitat.HealthCheckEvent) error

process a habitat HealthCheck event and store it into the database

func (*Postgres) IngestHealthCheckEventWithoutMetrics

func (db *Postgres) IngestHealthCheckEventWithoutMetrics(event *habitat.HealthCheckEvent) error

same as IngestHealthCheckEvent but without metrics

func (*Postgres) MarkDisconnectedServices

func (db *Postgres) MarkDisconnectedServices(thresholdSeconds int32) ([]*storage.Service, error)

func (*Postgres) ServiceGroupExists

func (db *Postgres) ServiceGroupExists(id string) (string, bool)

ServiceGroupExists returns the name of the service group if it exists

func (*Postgres) UpdateTelemetryReported

func (pg *Postgres) UpdateTelemetryReported(ctx context.Context, lastTelemetryReportedTime string) error

UpdateLastTelemetryReported Upsert the last application service telemetry reported date in postgres

Jump to

Keyboard shortcuts

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