pg

package
v4.3.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2016 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package dal is the Data Access Layer between the Application and PostgreSQL database.

Index

Constants

This section is empty.

Variables

View Source
var PROJECT_EPOCH = 1451606400

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Base
}

func NewAccessToken

func NewAccessToken(ctx context.Context) *AccessToken

func (*AccessToken) AllAccessTokens

func (t *AccessToken) AllAccessTokens(tx *sqlx.Tx) ([]*AccessTokenRow, error)

AllAccessTokens returns all access tokens.

func (*AccessToken) AllByClusterID

func (t *AccessToken) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*AccessTokenRow, error)

AllAccessTokens returns all access tokens by cluster id.

func (*AccessToken) Create

func (t *AccessToken) Create(tx *sqlx.Tx, userID, clusterID int64, level string) (*AccessTokenRow, error)

func (*AccessToken) GetByAccessToken

func (t *AccessToken) GetByAccessToken(tx *sqlx.Tx, token string) (*AccessTokenRow, error)

GetByAccessToken returns one record by token.

func (*AccessToken) GetByClusterID

func (t *AccessToken) GetByClusterID(tx *sqlx.Tx, clusterID int64) (*AccessTokenRow, error)

GetByClusterID returns one record by cluster_id.

func (*AccessToken) GetByID

func (t *AccessToken) GetByID(tx *sqlx.Tx, id int64) (*AccessTokenRow, error)

GetByID returns one record by id.

func (*AccessToken) GetByUserID

func (t *AccessToken) GetByUserID(tx *sqlx.Tx, userID int64) (*AccessTokenRow, error)

GetByUserID returns one record by user_id.

type AccessTokenRow

type AccessTokenRow struct {
	ID        int64  `db:"id"`
	UserID    int64  `db:"user_id"`
	ClusterID int64  `db:"cluster_id"`
	Token     string `db:"token"`
	Level     string `db:"level"` // read, write, execute
	Enabled   bool   `db:"enabled"`
}

type AgentResourcePayload

type AgentResourcePayload struct {
	Data map[string]interface{}
	Host struct {
		Name string
		Tags map[string]string
	}
}

type Base

type Base struct {
	AppContext context.Context
	// contains filtered or unexported fields
}

func (*Base) DeleteByClusterIDAndID

func (b *Base) DeleteByClusterIDAndID(tx *sqlx.Tx, clusterID, id int64) (result sql.Result, err error)

func (*Base) DeleteByID

func (b *Base) DeleteByID(tx *sqlx.Tx, id int64) (result sql.Result, err error)

func (*Base) DeleteFromTable

func (b *Base) DeleteFromTable(tx *sqlx.Tx, where string) (result sql.Result, err error)

func (*Base) GetPGDB

func (b *Base) GetPGDB() (*sqlx.DB, error)

func (*Base) InsertIntoTable

func (b *Base) InsertIntoTable(tx *sqlx.Tx, data map[string]interface{}) (sql.Result, error)

func (*Base) NewExplicitID

func (b *Base) NewExplicitID() int64

NewExplicitID uses UNIX timestamp in microseconds as ID.

func (*Base) UpdateByID

func (b *Base) UpdateByID(tx *sqlx.Tx, data map[string]interface{}, id int64) (result sql.Result, err error)

func (*Base) UpdateByKeyValueString

func (b *Base) UpdateByKeyValueString(tx *sqlx.Tx, data map[string]interface{}, key, value string) (result sql.Result, err error)

func (*Base) UpdateFromTable

func (b *Base) UpdateFromTable(tx *sqlx.Tx, data map[string]interface{}, where string) (result sql.Result, err error)

type BaseRow

type BaseRow struct {
}

func (*BaseRow) JSONAttrFloat64

func (br *BaseRow) JSONAttrFloat64(field sqlx_types.JSONText, attr string) float64

func (*BaseRow) JSONAttrString

func (br *BaseRow) JSONAttrString(field sqlx_types.JSONText, attr string) string

type Check

type Check struct {
	Base
}

func NewCheck

func NewCheck(ctx context.Context) *Check

func (*Check) AddTrigger

func (c *Check) AddTrigger(tx *sqlx.Tx, checkRow *CheckRow, trigger CheckTrigger) ([]CheckTrigger, error)

func (*Check) All

func (c *Check) All(tx *sqlx.Tx) ([]*CheckRow, error)

All returns all rows.

func (*Check) AllByClusterID

func (c *Check) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*CheckRow, error)

AllByClusterID returns all rows by cluster_id.

func (*Check) AllSplitToDaemons

func (c *Check) AllSplitToDaemons(tx *sqlx.Tx, daemons []string) (map[string][]*CheckRow, error)

AllSplitToDaemons returns all rows divided into daemons equally.

func (*Check) Create

func (c *Check) Create(tx *sqlx.Tx, clusterID int64, data map[string]interface{}) (*CheckRow, error)

func (*Check) DeleteTrigger

func (c *Check) DeleteTrigger(tx *sqlx.Tx, checkRow *CheckRow, trigger CheckTrigger) ([]CheckTrigger, error)

func (*Check) GetByID

func (c *Check) GetByID(tx *sqlx.Tx, id int64) (*CheckRow, error)

GetByID returns one record by id.

func (*Check) UpdateTrigger

func (c *Check) UpdateTrigger(tx *sqlx.Tx, checkRow *CheckRow, trigger CheckTrigger) ([]CheckTrigger, error)

type CheckExpression

type CheckExpression struct {
	Type       string
	MinHost    int
	Metric     string
	Operator   string
	Value      float64
	PrevRange  int
	PrevAggr   string
	Search     string
	Protocol   string
	Port       string
	Headers    string
	Username   string
	Password   string
	HTTPMethod string
	HTTPBody   string
	Result     struct {
		Value         bool
		Message       string
		BadHostnames  []string
		GoodHostnames []string
	}
}

type CheckRow

type CheckRow struct {
	ID                    int64               `db:"id"`
	ClusterID             int64               `db:"cluster_id"`
	Name                  string              `db:"name"`
	Interval              string              `db:"interval"`
	IsSilenced            bool                `db:"is_silenced"`
	HostsQuery            string              `db:"hosts_query"`
	HostsList             sqlx_types.JSONText `db:"hosts_list"`
	Expressions           sqlx_types.JSONText `db:"expressions"`
	Triggers              sqlx_types.JSONText `db:"triggers"`
	LastResultHosts       sqlx_types.JSONText `db:"last_result_hosts"`
	LastResultExpressions sqlx_types.JSONText `db:"last_result_expressions"`
}

func (*CheckRow) BuildEmailTriggerContent

func (checkRow *CheckRow) BuildEmailTriggerContent(lastViolation *TSCheckRow, templateRoot string) (string, error)

func (*CheckRow) GetExpressions

func (checkRow *CheckRow) GetExpressions() ([]CheckExpression, error)

func (*CheckRow) GetHostsList

func (checkRow *CheckRow) GetHostsList() ([]string, error)

func (*CheckRow) GetTriggers

func (checkRow *CheckRow) GetTriggers() []CheckTrigger

func (*CheckRow) RunEmailTrigger

func (checkRow *CheckRow) RunEmailTrigger(ctx context.Context, trigger CheckTrigger, lastViolation *TSCheckRow, violationsCount int) (err error)

func (*CheckRow) RunPagerDutyTrigger

func (checkRow *CheckRow) RunPagerDutyTrigger(ctx context.Context, trigger CheckTrigger, lastViolation *TSCheckRow) (err error)

func (*CheckRow) RunSMSTrigger

func (checkRow *CheckRow) RunSMSTrigger(ctx context.Context, trigger CheckTrigger, lastViolation *TSCheckRow, violationsCount int) (err error)

func (*CheckRow) RunTriggers

func (checkRow *CheckRow) RunTriggers(ctx context.Context) error

func (checkRow *CheckRow) RunTriggers(appConfig config.GeneralConfig, coreDB *sqlx.DB, tsCheckDB *sqlx.DB, mailr *mailer.Mailer) error {

func (*CheckRow) UnmarshalTriggers

func (checkRow *CheckRow) UnmarshalTriggers() ([]CheckTrigger, error)

type CheckRowsWithError

type CheckRowsWithError struct {
	Checks []*CheckRow
	Error  error
}

type CheckTrigger

type CheckTrigger struct {
	ID                    int64
	LowViolationsCount    int64
	HighViolationsCount   int64
	CreatedIntervalMinute int64
	Action                CheckTriggerAction
}

type CheckTriggerAction

type CheckTriggerAction struct {
	Transport            string
	Email                string
	SMSPhone             string
	SMSCarrier           string
	PagerDutyServiceKey  string
	PagerDutyIncidentKey string
	PagerDutyDescription string
}

type Cluster

type Cluster struct {
	Base
}

func NewCluster

func NewCluster(ctx context.Context) *Cluster

func (*Cluster) All

func (c *Cluster) All(tx *sqlx.Tx) ([]*ClusterRow, error)

All returns all clusters rows.

func (*Cluster) AllByUserID

func (c *Cluster) AllByUserID(tx *sqlx.Tx, userId int64) ([]*ClusterRow, error)

AllByUserID returns all clusters rows by user ID.

func (*Cluster) AllSplitToDaemons

func (c *Cluster) AllSplitToDaemons(tx *sqlx.Tx, daemons []string) (map[string][]*ClusterRow, error)

AllSplitToDaemons returns all rows divided into daemons equally.

func (*Cluster) Create

func (c *Cluster) Create(tx *sqlx.Tx, creator *UserRow, name string) (*ClusterRow, error)

Create a cluster row record with default settings.

func (*Cluster) GetByID

func (c *Cluster) GetByID(tx *sqlx.Tx, id int64) (*ClusterRow, error)

GetByID returns one record by id.

func (*Cluster) RemoveMember

func (c *Cluster) RemoveMember(tx *sqlx.Tx, id int64, user *UserRow) error

RemoveMember from a cluster.

func (*Cluster) UpdateMember

func (c *Cluster) UpdateMember(tx *sqlx.Tx, id int64, user *UserRow, level string, enabled bool) error

UpdateMember adds or updates cluster member information.

type ClusterMember

type ClusterMember struct {
	ID      int64
	Email   string
	Level   string
	Enabled bool
}

type ClusterRow

type ClusterRow struct {
	ID            int64               `db:"id"`
	Name          string              `db:"name"`
	CreatorID     int64               `db:"creator_id"`
	CreatorEmail  string              `db:"creator_email"`
	DataRetention sqlx_types.JSONText `db:"data_retention"`
	Members       sqlx_types.JSONText `db:"members"`
}

func (*ClusterRow) GetDataRetention

func (cr *ClusterRow) GetDataRetention() map[string]int

GetDataRetention returns DataRetention in map

func (*ClusterRow) GetDeletedFromUNIXTimestampForInsert

func (cr *ClusterRow) GetDeletedFromUNIXTimestampForInsert(tableName string) int64

GetDeletedFromUNIXTimestampForInsert returns UNIX timestamp for timeseries data on insert.

func (*ClusterRow) GetDeletedFromUNIXTimestampForSelect

func (cr *ClusterRow) GetDeletedFromUNIXTimestampForSelect(tableName string) int64

GetDeletedFromUNIXTimestampForSelect returns UNIX timestamp from which data should be queried.

func (*ClusterRow) GetLevelByUserID

func (cr *ClusterRow) GetLevelByUserID(id int64) string

GetLevelByUserID returns a specific cluster member level keyed by user id.

func (*ClusterRow) GetMembers

func (cr *ClusterRow) GetMembers() []ClusterMember

GetMembers returns Members in map

func (*ClusterRow) GetTTLDurationForInsert

func (cr *ClusterRow) GetTTLDurationForInsert(tableName string) time.Duration

GetTTLDurationForInsert returns TTL duration for timeseries data on insert.

type Graph

type Graph struct {
	Base
}

func NewGraph

func NewGraph(ctx context.Context) *Graph

func (*Graph) AllByClusterID

func (g *Graph) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*GraphRow, error)

AllByClusterID returns all rows by cluster_id.

func (*Graph) AllGraphs

func (g *Graph) AllGraphs(tx *sqlx.Tx) ([]*GraphRow, error)

AllGraphs returns all rows.

func (*Graph) Create

func (g *Graph) Create(tx *sqlx.Tx, clusterID int64, data map[string]interface{}) (*GraphRow, error)

func (*Graph) DeleteMetricFromGraphs

func (g *Graph) DeleteMetricFromGraphs(tx *sqlx.Tx, clusterID, metricID int64) error

DeleteMetricFromGraphs deletes a particular metric from all rows by cluster_id.

func (*Graph) GetByClusterIDAndID

func (g *Graph) GetByClusterIDAndID(tx *sqlx.Tx, clusterID, id int64) (*GraphRow, error)

GetByClusterIDAndID returns one record by id.

func (*Graph) GetByID

func (g *Graph) GetByID(tx *sqlx.Tx, id int64) (*GraphRow, error)

GetByID returns one record by id.

func (*Graph) UpdateMetricsByClusterIDAndID

func (g *Graph) UpdateMetricsByClusterIDAndID(tx *sqlx.Tx, clusterID, id int64, metricsJSON []byte) (*GraphRow, error)

UpdateMetricsByClusterIDAndID updates metrics JSON and then returns record by id.

type GraphRow

type GraphRow struct {
	ID          int64               `db:"id"`
	ClusterID   int64               `db:"cluster_id"`
	Name        string              `db:"name"`
	Description string              `db:"description"`
	Range       string              `db:"range"`
	Metrics     sqlx_types.JSONText `db:"metrics"`
}

func (*GraphRow) MetricsFromJSON

func (gr *GraphRow) MetricsFromJSON() []*MetricRow

func (*GraphRow) MetricsFromJSONGroupByN

func (gr *GraphRow) MetricsFromJSONGroupByN(n int) [][]*MetricRow

func (*GraphRow) MetricsFromJSONGroupByThree

func (gr *GraphRow) MetricsFromJSONGroupByThree() [][]*MetricRow

type GraphRowsWithError

type GraphRowsWithError struct {
	Graphs []*GraphRow
	Error  error
}

type Host

type Host struct {
	Base
	// contains filtered or unexported fields
}

func NewHost

func NewHost(ctx context.Context, clusterID int64) *Host

func (*Host) AllByClusterID

func (h *Host) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*HostRow, error)

AllByClusterID returns all rows.

func (*Host) AllByClusterIDAndHostnames

func (h *Host) AllByClusterIDAndHostnames(tx *sqlx.Tx, clusterID int64, hostnames []string) ([]*HostRow, error)

AllByClusterIDAndHostnames returns all rows by hostnames.

func (*Host) AllByClusterIDAndUpdatedInterval

func (h *Host) AllByClusterIDAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, updatedInterval string) ([]*HostRow, error)

AllByClusterIDAndUpdatedInterval returns all rows.

func (*Host) AllByClusterIDQueryAndUpdatedInterval

func (h *Host) AllByClusterIDQueryAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, resourcedQuery, updatedInterval string) ([]*HostRow, error)

AllByClusterIDQueryAndUpdatedInterval returns all rows by resourced query.

func (*Host) AllCompactByClusterIDQueryAndUpdatedInterval

func (h *Host) AllCompactByClusterIDQueryAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, resourcedQuery, updatedInterval string) ([]*HostRow, error)

AllCompactByClusterIDQueryAndUpdatedInterval returns all rows by resourced query.

func (*Host) CountByClusterIDAndUpdatedInterval

func (h *Host) CountByClusterIDAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, updatedInterval string) (int, error)

CountByClusterIDAndUpdatedInterval returns the count of all rows.

func (*Host) CreateOrUpdate

func (h *Host) CreateOrUpdate(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, jsonData []byte) (*HostRow, error)

CreateOrUpdate performs insert/update for one host data.

func (*Host) GetByHostname

func (h *Host) GetByHostname(tx *sqlx.Tx, hostname string) (*HostRow, error)

GetByHostname returns record by hostname.

func (*Host) GetByID

func (h *Host) GetByID(tx *sqlx.Tx, id int64) (*HostRow, error)

GetByID returns record by id.

func (*Host) GetPGDB

func (h *Host) GetPGDB() (*sqlx.DB, error)

func (*Host) UpdateMasterTagsByHostname

func (h *Host) UpdateMasterTagsByHostname(tx *sqlx.Tx, hostname string, tags map[string]interface{}) error

UpdateMasterTagsByHostname updates master tags by hostname.

func (*Host) UpdateMasterTagsByID

func (h *Host) UpdateMasterTagsByID(tx *sqlx.Tx, id int64, tags map[string]interface{}) error

UpdateMasterTagsByID updates master tags by ID.

type HostRow

type HostRow struct {
	ID            int64               `db:"id" json:"-"`
	AccessTokenID int64               `db:"access_token_id" json:"-"`
	ClusterID     int64               `db:"cluster_id"`
	Hostname      string              `db:"hostname"`
	Updated       time.Time           `db:"updated"`
	Tags          sqlx_types.JSONText `db:"tags" json:",omitempty"`
	MasterTags    sqlx_types.JSONText `db:"master_tags" json:",omitempty"`
	Data          sqlx_types.JSONText `db:"data" json:",omitempty"`
}

func (*HostRow) DataAsFlatKeyValue

func (h *HostRow) DataAsFlatKeyValue() map[string]map[string]interface{}

func (*HostRow) GetClusterID

func (h *HostRow) GetClusterID() int64

func (*HostRow) GetHostname

func (h *HostRow) GetHostname() string

func (*HostRow) GetMasterTags

func (h *HostRow) GetMasterTags() map[string]interface{}

func (*HostRow) GetTags

func (h *HostRow) GetTags() map[string]string

type HostRowsWithError

type HostRowsWithError struct {
	Hosts []*HostRow
	Error error
}

type IPGDBGetter

type IPGDBGetter interface {
	GetPGDB() (*sqlx.DB, error)
}

type InsertResult

type InsertResult struct {
	// contains filtered or unexported fields
}

func (*InsertResult) LastInsertId

func (ir *InsertResult) LastInsertId() (int64, error)

func (*InsertResult) RowsAffected

func (ir *InsertResult) RowsAffected() (int64, error)

type Metric

type Metric struct {
	Base
}

func NewMetric

func NewMetric(ctx context.Context) *Metric

func (*Metric) AllByClusterID

func (m *Metric) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*MetricRow, error)

AllByClusterID returns all rows.

func (*Metric) AllByClusterIDAsMap

func (m *Metric) AllByClusterIDAsMap(tx *sqlx.Tx, clusterID int64) (map[string]int64, error)

AllByClusterIDAsMap returns all rows.

func (*Metric) CreateOrUpdate

func (m *Metric) CreateOrUpdate(tx *sqlx.Tx, clusterID int64, key string) (*MetricRow, error)

func (*Metric) GetByClusterIDAndKey

func (m *Metric) GetByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string) (*MetricRow, error)

GetByClusterIDAndKey returns one record by cluster_id and key.

func (*Metric) GetByID

func (m *Metric) GetByID(tx *sqlx.Tx, id int64) (*MetricRow, error)

GetByID returns one record by id.

type MetricRow

type MetricRow struct {
	ID        int64  `db:"id"`
	ClusterID int64  `db:"cluster_id"`
	Key       string `db:"key"`
}

type MetricRowsWithError

type MetricRowsWithError struct {
	Metrics []*MetricRow
	Error   error
}

type MetricsMapWithError

type MetricsMapWithError struct {
	MetricsMap map[string]int64
	Error      error
}

type SavedQuery

type SavedQuery struct {
	Base
}

func NewSavedQuery

func NewSavedQuery(ctx context.Context) *SavedQuery

func (*SavedQuery) AllByClusterID

func (sq *SavedQuery) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*SavedQueryRow, error)

AllByClusterID returns all saved_query rows.

func (*SavedQuery) AllByClusterIDAndType

func (sq *SavedQuery) AllByClusterIDAndType(tx *sqlx.Tx, clusterID int64, savedQueryType string) ([]*SavedQueryRow, error)

AllByClusterIDAndType returns all saved_query rows.

func (*SavedQuery) CreateOrUpdate

func (sq *SavedQuery) CreateOrUpdate(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, savedQueryType, savedQuery string) (*SavedQueryRow, error)

CreateOrUpdate performs insert/update for one savedQuery data.

func (*SavedQuery) GetByAccessTokenAndQuery

func (sq *SavedQuery) GetByAccessTokenAndQuery(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, savedQueryType, savedQuery string) (*SavedQueryRow, error)

GetByAccessTokenAndQuery returns record by savedQuery.

func (*SavedQuery) GetByID

func (sq *SavedQuery) GetByID(tx *sqlx.Tx, id int64) (*SavedQueryRow, error)

GetByID returns record by id.

type SavedQueryRow

type SavedQueryRow struct {
	ID        int64  `db:"id"`
	UserID    int64  `db:"user_id"`
	ClusterID int64  `db:"cluster_id"`
	Type      string `db:"type"`
	Query     string `db:"query"`
}

type SavedQueryRowsWithError

type SavedQueryRowsWithError struct {
	SavedQueries []*SavedQueryRow
	Error        error
}

type TSBase

type TSBase struct {
	Base
	// contains filtered or unexported fields
}

func (*TSBase) DeleteDeleted

func (ts *TSBase) DeleteDeleted(tx *sqlx.Tx, clusterID int64) error

DeleteDeleted deletes all "deleted" records.

type TSCheck

type TSCheck struct {
	TSBase
}

func NewTSCheck

func NewTSCheck(ctx context.Context, clusterID int64) *TSCheck

func (*TSCheck) AllViolationsByClusterIDCheckIDAndInterval

func (ts *TSCheck) AllViolationsByClusterIDCheckIDAndInterval(tx *sqlx.Tx, clusterID, CheckID, createdIntervalMinute, deletedFrom int64) ([]*TSCheckRow, error)

AllViolationsByClusterIDCheckIDAndInterval returns all ts_checks rows since last good marker.

func (*TSCheck) Create

func (ts *TSCheck) Create(tx *sqlx.Tx, clusterID, CheckID int64, result bool, expressions []CheckExpression, deletedFrom int64) error

Create a new record.

func (*TSCheck) GetPGDB

func (ts *TSCheck) GetPGDB() (*sqlx.DB, error)

func (*TSCheck) LastByClusterIDCheckIDAndLimit

func (ts *TSCheck) LastByClusterIDCheckIDAndLimit(tx *sqlx.Tx, clusterID, checkID, limit int64) ([]*TSCheckRow, error)

LastByClusterIDCheckIDAndLimit returns a row by cluster_id, check_id and result.

func (*TSCheck) LastByClusterIDCheckIDAndResult

func (ts *TSCheck) LastByClusterIDCheckIDAndResult(tx *sqlx.Tx, clusterID, checkID int64, result bool) (*TSCheckRow, error)

LastByClusterIDCheckIDAndResult returns a row by cluster_id, check_id and result.

type TSCheckRow

type TSCheckRow struct {
	ClusterID   int64               `db:"cluster_id"`
	CheckID     int64               `db:"check_id"`
	Created     time.Time           `db:"created"`
	Deleted     time.Time           `db:"deleted"`
	Result      bool                `db:"result"`
	Expressions sqlx_types.JSONText `db:"expressions"`
}

func (*TSCheckRow) GetExpressionsWithoutError

func (tsCheckRow *TSCheckRow) GetExpressionsWithoutError() []CheckExpression

type TSEvent

type TSEvent struct {
	TSBase
}

func NewTSEvent

func NewTSEvent(ctx context.Context, clusterID int64) *TSEvent

func (*TSEvent) AllBandsByClusterIDAndCreatedFromRangeForHighchart

func (ts *TSEvent) AllBandsByClusterIDAndCreatedFromRangeForHighchart(tx *sqlx.Tx, clusterID, from, to, deletedFrom int64) ([]shared.TSEventHighchartLinePayload, error)

AllBandsByClusterIDAndCreatedFromRangeForHighchart returns all rows with time stretch between created_from and created_to.

func (*TSEvent) AllLinesByClusterIDAndCreatedFromRangeForHighchart

func (ts *TSEvent) AllLinesByClusterIDAndCreatedFromRangeForHighchart(tx *sqlx.Tx, clusterID, from, to, deletedFrom int64) ([]shared.TSEventHighchartLinePayload, error)

AllLinesByClusterIDAndCreatedFromRangeForHighchart returns all rows given created_from range.

func (*TSEvent) Create

func (ts *TSEvent) Create(tx *sqlx.Tx, id, clusterID, fromUnix, toUnix int64, description string, deletedFrom int64) (*TSEventRow, error)

Create a new record.

func (*TSEvent) CreateFromJSON

func (ts *TSEvent) CreateFromJSON(tx *sqlx.Tx, id, clusterID int64, jsonData []byte, deletedFrom int64) (*TSEventRow, error)

func (*TSEvent) DeleteDeleted

func (ts *TSEvent) DeleteDeleted(tx *sqlx.Tx, clusterID int64) error

DeleteDeleted deletes all record older than x days ago.

func (*TSEvent) GetByID

func (ts *TSEvent) GetByID(tx *sqlx.Tx, id int64) (*TSEventRow, error)

GetByID returns record by id.

func (*TSEvent) GetPGDB

func (ts *TSEvent) GetPGDB() (*sqlx.DB, error)

type TSEventRow

type TSEventRow struct {
	ID          int64     `db:"id"`
	ClusterID   int64     `db:"cluster_id"`
	CreatedFrom time.Time `db:"created_from"`
	CreatedTo   time.Time `db:"created_to"`
	Deleted     time.Time `db:"deleted"`
	Description string    `db:"description"`
}

type TSLog

type TSLog struct {
	TSBase
}

func NewTSLog

func NewTSLog(ctx context.Context, clusterID int64) *TSLog

func (*TSLog) AllByClusterIDAndRange

func (ts *TSLog) AllByClusterIDAndRange(tx *sqlx.Tx, clusterID int64, from, to, deletedFrom int64) ([]*TSLogRow, error)

AllByClusterIDAndRange returns all logs within time range.

func (*TSLog) AllByClusterIDRangeAndQuery

func (ts *TSLog) AllByClusterIDRangeAndQuery(tx *sqlx.Tx, clusterID int64, from, to int64, resourcedQuery string, deletedFrom int64) ([]*TSLogRow, error)

AllByClusterIDRangeAndQuery returns all rows by cluster id, unix timestamp range, and resourced query.

func (*TSLog) CountByClusterIDFromTimestampHostAndQuery

func (ts *TSLog) CountByClusterIDFromTimestampHostAndQuery(tx *sqlx.Tx, clusterID int64, from int64, hostname, resourcedQuery string, deletedFrom int64) (int64, error)

CountByClusterIDFromTimestampHostAndQuery returns count by cluster id, from unix timestamp, host, and resourced query.

func (*TSLog) Create

func (ts *TSLog) Create(tx *sqlx.Tx, clusterID int64, hostname string, tags map[string]string, loglines []shared.AgentLoglinePayload, filename string, deletedFrom int64) (err error)

Create a new record.

func (*TSLog) CreateFromJSON

func (ts *TSLog) CreateFromJSON(tx *sqlx.Tx, clusterID int64, jsonData []byte, deletedFrom int64) error

func (*TSLog) GetPGDB

func (ts *TSLog) GetPGDB() (*sqlx.DB, error)

func (*TSLog) LastByClusterID

func (ts *TSLog) LastByClusterID(tx *sqlx.Tx, clusterID int64) (*TSLogRow, error)

LastByClusterID returns the last row by cluster id.

type TSLogRow

type TSLogRow struct {
	ClusterID int64               `db:"cluster_id"`
	Created   time.Time           `db:"created"`
	Deleted   time.Time           `db:"deleted"`
	Hostname  string              `db:"hostname"`
	Tags      sqlx_types.JSONText `db:"tags"`
	Filename  string              `db:"filename"`
	Logline   string              `db:"logline"`
}

func (*TSLogRow) CreatedUnix

func (tsr *TSLogRow) CreatedUnix() int64

func (*TSLogRow) GetTags

func (tsr *TSLogRow) GetTags() map[string]string

type TSLogRowsWithError

type TSLogRowsWithError struct {
	TSLogRows []*TSLogRow
	Error     error
}

type TSMetric

type TSMetric struct {
	TSBase
}

func NewTSMetric

func NewTSMetric(ctx context.Context, clusterID int64) *TSMetric

func (*TSMetric) AllByMetricIDAndRange

func (ts *TSMetric) AllByMetricIDAndRange(tx *sqlx.Tx, clusterID, metricID, from, to, deletedFrom int64) ([]*TSMetricRow, error)

func (*TSMetric) AllByMetricIDAndRangeForHighchart

func (ts *TSMetric) AllByMetricIDAndRangeForHighchart(tx *sqlx.Tx, clusterID, metricID, from, to, deletedFrom int64) ([]*shared.TSMetricHighchartPayload, error)

func (*TSMetric) AllByMetricIDHostAndRange

func (ts *TSMetric) AllByMetricIDHostAndRange(tx *sqlx.Tx, clusterID, metricID int64, host string, from, to, deletedFrom int64) ([]*TSMetricRow, error)

func (*TSMetric) AllByMetricIDHostAndRangeForHighchart

func (ts *TSMetric) AllByMetricIDHostAndRangeForHighchart(tx *sqlx.Tx, clusterID, metricID int64, host string, from, to, deletedFrom int64) (*shared.TSMetricHighchartPayload, error)

func (*TSMetric) Create

func (ts *TSMetric) Create(tx *sqlx.Tx, clusterID, metricID int64, host, key string, value float64, deletedFrom int64) error

Create a new record.

func (*TSMetric) CreateByHostRow

func (ts *TSMetric) CreateByHostRow(tx *sqlx.Tx, hostRow shared.IHostRow, metricsMap map[string]int64, deletedFrom int64) error

func (*TSMetric) GetAggregateXMinutesByMetricIDAndHostname

func (ts *TSMetric) GetAggregateXMinutesByMetricIDAndHostname(tx *sqlx.Tx, clusterID, metricID int64, minutes int, hostname string) (*shared.TSMetricAggregateRow, error)

func (*TSMetric) GetPGDB

func (ts *TSMetric) GetPGDB() (*sqlx.DB, error)

type TSMetricRow

type TSMetricRow struct {
	ClusterID int64     `db:"cluster_id"`
	MetricID  int64     `db:"metric_id"`
	Created   time.Time `db:"created"`
	Deleted   time.Time `db:"deleted"`
	Key       string    `db:"key"`
	Host      string    `db:"host"`
	Value     float64   `db:"value"`
}

type User

type User struct {
	Base
}

func NewUser

func NewUser(ctx context.Context) *User

func (*User) AllUsers

func (u *User) AllUsers(tx *sqlx.Tx) ([]*UserRow, error)

AllUsers returns all user rows.

func (*User) GetByEmail

func (u *User) GetByEmail(tx *sqlx.Tx, email string) (*UserRow, error)

GetByEmail returns record by email.

func (*User) GetByEmailVerificationToken

func (u *User) GetByEmailVerificationToken(tx *sqlx.Tx, emailVerificationToken string) (*UserRow, error)

GetByEmailVerificationToken returns record by email_verification_token.

func (*User) GetByID

func (u *User) GetByID(tx *sqlx.Tx, id int64) (*UserRow, error)

GetByID returns record by id.

func (*User) GetUserByEmailAndPassword

func (u *User) GetUserByEmailAndPassword(tx *sqlx.Tx, email, password string) (*UserRow, error)

GetByEmail returns record by email but checks password first.

func (*User) Signup

func (u *User) Signup(tx *sqlx.Tx, email, password, passwordAgain string) (*UserRow, error)

Signup create a new record of user.

func (*User) SignupRandomPassword

func (u *User) SignupRandomPassword(tx *sqlx.Tx, email string) (*UserRow, error)

SignupRandomPassword create a new record of user with random password.

func (*User) UpdateEmailAndPasswordById

func (u *User) UpdateEmailAndPasswordById(tx *sqlx.Tx, userId int64, email, password, passwordAgain string) (*UserRow, error)

UpdateEmailAndPasswordById updates user email and password.

func (*User) UpdateEmailVerification

func (u *User) UpdateEmailVerification(tx *sqlx.Tx, emailVerificationToken string) (*UserRow, error)

UpdateEmailVerification acknowledge email verification.

type UserRow

type UserRow struct {
	ID                     int64          `db:"id"`
	Email                  string         `db:"email"`
	Password               string         `db:"password"`
	EmailVerificationToken sql.NullString `db:"email_verification_token"`
	EmailVerified          bool           `db:"email_verified"`
}

Directories

Path Synopsis
Package querybuilder parses ResourceD query and turn it into PostgreSQL query.
Package querybuilder parses ResourceD query and turn it into PostgreSQL query.

Jump to

Keyboard shortcuts

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