bosun.org: bosun.org/cmd/bosun/database Index | Files | Directories

package database

import "bosun.org/cmd/bosun/database"

Package database implements all persistent data access for bosun. Internally it runs ledisdb locally, but uses a redis client to access all data. Thus it should be able to migrate to a remote redis instance with minimal effort.

Index

Package Files

config_data.go database.go error_data.go metric_metadata.go migrate.go models.go notification_data.go search_data.go silence_data.go state_data.go tag_metadata.go

Constants

const Search_All = "__all__"

Variables

var SchemaVersion = int64(2)

func IsRedisNil Uses

func IsRedisNil(err error) bool

func StartLedis Uses

func StartLedis(dataDir string, bind string) (stop func(), err error)

Start in-process ledis server. Data will go in the specified directory and it will bind to the given port. Return value is a function you can call to stop the server.

type ConfigDataAccess Uses

type ConfigDataAccess interface {
    SaveTempConfig(text string) (hash string, err error)
    GetTempConfig(hash string) (text string, err error)

    ShortenLink(fullURL string) (id int, err error)
    GetShortLink(id int) (fullURL string, err error)
}

type DataAccess Uses

type DataAccess interface {
    RedisConnector
    Metadata() MetadataDataAccess
    Configs() ConfigDataAccess
    Search() SearchDataAccess
    Errors() ErrorDataAccess
    State() StateDataAccess
    Silence() SilenceDataAccess
    Notifications() NotificationDataAccess
    Migrate() error
}

Core data access interface for everything sched needs

func NewDataAccess Uses

func NewDataAccess(addr []string, isRedis bool, masterName string, redisDb int, redisPass string) DataAccess

Create a new data access object pointed at the specified address. isRedis parameter used to distinguish true redis from ledis in-proc.

type ErrorDataAccess Uses

type ErrorDataAccess interface {
    MarkAlertSuccess(name string) error
    MarkAlertFailure(name string, msg string) error
    GetFailingAlertCounts() (int, int, error)

    GetFailingAlerts() (map[string]bool, error)
    IsAlertFailing(name string) (bool, error)

    GetFullErrorHistory() (map[string][]*models.AlertError, error)
    ClearAlert(name string) error
    ClearAll() error
}

type LastInfo Uses

type LastInfo struct {
    LastVal      float64
    DiffFromPrev float64
    Timestamp    int64
}

type MetadataDataAccess Uses

type MetadataDataAccess interface {
    // Insert Metric Metadata. Field must be one of "desc", "rate", or "unit".
    PutMetricMetadata(metric string, field string, value string) error
    // Get Metric Metadata for given metric.
    GetMetricMetadata(metric string) (*MetricMetadata, error)

    PutTagMetadata(tags opentsdb.TagSet, name string, value string, updated time.Time) error
    GetTagMetadata(tags opentsdb.TagSet, name string) ([]*TagMetadata, error)
    DeleteTagMetadata(tags opentsdb.TagSet, name string) error
}

type MetricMetadata Uses

type MetricMetadata struct {
    Desc        string `redis:"desc" json:",omitempty"`
    Unit        string `redis:"unit" json:",omitempty"`
    Rate        string `redis:"rate" json:",omitempty"`
    LastTouched int64  `redis:"lastTouched"`
}

type Migration Uses

type Migration struct {
    UID     string
    Task    func(d *dataAccess) error
    Version int64
}

type NotificationDataAccess Uses

type NotificationDataAccess interface {
    InsertNotification(ak models.AlertKey, notification string, dueAt time.Time) error

    //Get notifications that are currently due or past due. Does not delete.
    GetDueNotifications() (map[models.AlertKey]map[string]time.Time, error)

    //Clear all notifications due on or before a given timestamp. Intended is to use the max returned from GetDueNotifications once you have processed them.
    ClearNotificationsBefore(time.Time) error

    ClearNotifications(ak models.AlertKey) error

    GetNextNotificationTime() (time.Time, error)
}

type RedisConnector Uses

type RedisConnector interface {
    Get() redis.Conn
}

RedisConnector is a simple interface so things can get a raw connection (mostly tests), but still discourage it. makes dataAccess interchangable with redis.Pool

type SearchDataAccess Uses

type SearchDataAccess interface {
    AddMetricForTag(tagK, tagV, metric string, time int64) error
    GetMetricsForTag(tagK, tagV string) (map[string]int64, error)

    AddTagKeyForMetric(metric, tagK string, time int64) error
    GetTagKeysForMetric(metric string) (map[string]int64, error)

    AddMetric(metric string, time int64) error
    GetAllMetrics() (map[string]int64, error)

    AddTagValue(metric, tagK, tagV string, time int64) error
    GetTagValues(metric, tagK string) (map[string]int64, error)

    AddMetricTagSet(metric, tagSet string, time int64) error
    GetMetricTagSets(metric string, tags opentsdb.TagSet) (map[string]int64, error)

    BackupLastInfos(map[string]map[string]*LastInfo) error
    LoadLastInfos() (map[string]map[string]*LastInfo, error)
}

type SilenceDataAccess Uses

type SilenceDataAccess interface {
    GetActiveSilences() ([]*models.Silence, error)
    AddSilence(*models.Silence) error
    DeleteSilence(id string) error

    ListSilences(endingAfter int64) (map[string]*models.Silence, error)
}

type StateDataAccess Uses

type StateDataAccess interface {
    TouchAlertKey(ak models.AlertKey, t time.Time) error
    GetUntouchedSince(alert string, time int64) ([]models.AlertKey, error)

    GetOpenIncident(ak models.AlertKey) (*models.IncidentState, error)
    GetLatestIncident(ak models.AlertKey) (*models.IncidentState, error)
    GetAllOpenIncidents() ([]*models.IncidentState, error)
    GetIncidentState(incidentId int64) (*models.IncidentState, error)

    GetAllIncidentsByAlertKey(ak models.AlertKey) ([]*models.IncidentState, error)
    GetAllIncidentIdsByAlertKey(ak models.AlertKey) ([]int64, error)

    UpdateIncidentState(s *models.IncidentState) (int64, error)
    ImportIncidentState(s *models.IncidentState) error

    // SetIncidentNext gets the incident for previousIncidentId, and sets its NextId field to be nextIncidentId and then saves the incident
    SetIncidentNext(incidentId, nextIncidentId int64) error

    SetRenderedTemplates(incidentId int64, rt *models.RenderedTemplates) error
    GetRenderedTemplates(incidentId int64) (*models.RenderedTemplates, error)
    GetRenderedTemplateKeys() ([]string, error)
    CleanupOldRenderedTemplates(olderThan time.Duration)
    DeleteRenderedTemplates(incidentIds []int64) error

    Forget(ak models.AlertKey) error
    SetUnevaluated(ak models.AlertKey, uneval bool) error
    GetUnknownAndUnevalAlertKeys(alert string) ([]models.AlertKey, []models.AlertKey, error)
}

type TagMetadata Uses

type TagMetadata struct {
    Tags        opentsdb.TagSet
    Name        string
    Value       string
    LastTouched int64
}

Directories

PathSynopsis
sentinel
test
test/util

Package database imports 22 packages (graph) and is imported by 10 packages. Updated 2020-05-30. Refresh now. Tools for package owners.