Version: v2.5.0 Latest Latest

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

Go to latest
Published: Apr 12, 2019 License: MIT Imports: 15 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Config

type Config struct {
	MasterName        string
	SentinelAddresses []string
	Host              string
	Port              string
	DB                int
	ConnectionLimit   int

Config - Redis database connection config

type DBSource added in v2.4.0

type DBSource string

DBSource is type for describing who create database instance

const (
	API      DBSource = "API"
	Checker  DBSource = "Checker"
	Filter   DBSource = "Filter"
	Notifier DBSource = "Notifier"
	Cli      DBSource = "Cli"

All types of database instances users

type DbConnector

type DbConnector struct {
	// contains filtered or unexported fields

DbConnector contains redis pool

func NewDatabase

func NewDatabase(logger moira.Logger, config Config, source DBSource) *DbConnector

NewDatabase creates Redis pool based on config

func (*DbConnector) AcquireTriggerCheckLock

func (connector *DbConnector) AcquireTriggerCheckLock(triggerID string, timeout int) error

AcquireTriggerCheckLock sets trigger lock by given id. If lock does not take, try again and repeat it for given attempts

func (*DbConnector) AddLocalTriggersToCheck added in v2.5.0

func (connector *DbConnector) AddLocalTriggersToCheck(triggerIDs []string) error

AddLocalTriggersToCheck gets trigger IDs and save it to Redis Set

func (*DbConnector) AddNotification

func (connector *DbConnector) AddNotification(notification *moira.ScheduledNotification) error

AddNotification store notification at given timestamp

func (*DbConnector) AddNotifications

func (connector *DbConnector) AddNotifications(notifications []*moira.ScheduledNotification, timestamp int64) error

AddNotifications store notification at given timestamp

func (*DbConnector) AddPatternMetric

func (connector *DbConnector) AddPatternMetric(pattern, metric string) error

AddPatternMetric adds new metrics by given pattern

func (*DbConnector) AddRemoteTriggersToCheck

func (connector *DbConnector) AddRemoteTriggersToCheck(triggerIDs []string) error

AddRemoteTriggersToCheck gets remote trigger IDs and save it to Redis Set

func (*DbConnector) DeleteTriggerCheckLock

func (connector *DbConnector) DeleteTriggerCheckLock(triggerID string) error

DeleteTriggerCheckLock deletes trigger check lock for given triggerID

func (*DbConnector) DeleteTriggerThrottling

func (connector *DbConnector) DeleteTriggerThrottling(triggerID string) error

DeleteTriggerThrottling deletes throttling and scheduled notifications delay for given triggerID

func (*DbConnector) FetchNotificationEvent

func (connector *DbConnector) FetchNotificationEvent() (moira.NotificationEvent, error)

FetchNotificationEvent waiting for event in events list

func (*DbConnector) FetchNotifications

func (connector *DbConnector) FetchNotifications(to int64) ([]*moira.ScheduledNotification, error)

FetchNotifications fetch notifications by given timestamp and delete it

func (*DbConnector) FetchTriggersToReindex added in v2.4.0

func (connector *DbConnector) FetchTriggersToReindex(from int64) ([]string, error)

FetchTriggersToReindex returns trigger IDs updated since 'from' param The trigger could be changed by user, or it's score was changed during trigger check

func (*DbConnector) GetAllContacts

func (connector *DbConnector) GetAllContacts() ([]*moira.ContactData, error)

GetAllContacts returns full contact list

func (*DbConnector) GetAllTriggerIDs

func (connector *DbConnector) GetAllTriggerIDs() ([]string, error)

GetAllTriggerIDs gets all moira triggerIDs

func (*DbConnector) GetChecksUpdatesCount

func (connector *DbConnector) GetChecksUpdatesCount() (int64, error)

GetChecksUpdatesCount return checks count by Moira-Checker

func (*DbConnector) GetContact

func (connector *DbConnector) GetContact(id string) (moira.ContactData, error)

GetContact returns contact data by given id, if no value, return database.ErrNil error

func (*DbConnector) GetContacts

func (connector *DbConnector) GetContacts(contactIDs []string) ([]*moira.ContactData, error)

GetContacts returns contacts data by given ids, len of contactIDs is equal to len of returned values array. If there is no object by current ID, then nil is returned

func (*DbConnector) GetIDByUsername

func (connector *DbConnector) GetIDByUsername(messenger, username string) (string, error)

GetIDByUsername read ID of user by messenger username

func (*DbConnector) GetLocalTriggerIDs added in v2.4.0

func (connector *DbConnector) GetLocalTriggerIDs() ([]string, error)

GetLocalTriggerIDs gets moira local triggerIDs

func (*DbConnector) GetLocalTriggersToCheck added in v2.5.0

func (connector *DbConnector) GetLocalTriggersToCheck(count int) ([]string, error)

GetLocalTriggersToCheck return random trigger ID from Redis Set

func (*DbConnector) GetLocalTriggersToCheckCount added in v2.5.0

func (connector *DbConnector) GetLocalTriggersToCheckCount() (int64, error)

GetLocalTriggersToCheckCount return number of triggers ID to check from Redis Set

func (*DbConnector) GetMetricRetention

func (connector *DbConnector) GetMetricRetention(metric string) (int64, error)

GetMetricRetention gets given metric retention, if retention is empty then return default retention value(60)

func (*DbConnector) GetMetricsUpdatesCount

func (connector *DbConnector) GetMetricsUpdatesCount() (int64, error)

GetMetricsUpdatesCount return metrics count received by Moira-Filter

func (*DbConnector) GetMetricsValues

func (connector *DbConnector) GetMetricsValues(metrics []string, from int64, until int64) (map[string][]*moira.MetricValue, error)

GetMetricsValues gets metrics values for given interval

func (*DbConnector) GetNotificationEventCount

func (connector *DbConnector) GetNotificationEventCount(triggerID string, from int64) int64

GetNotificationEventCount returns planned notifications count from given timestamp

func (*DbConnector) GetNotificationEvents

func (connector *DbConnector) GetNotificationEvents(triggerID string, start int64, size int64) ([]*moira.NotificationEvent, error)

GetNotificationEvents gets NotificationEvents by given triggerID and interval

func (*DbConnector) GetNotifications

func (connector *DbConnector) GetNotifications(start, end int64) ([]*moira.ScheduledNotification, int64, error)

GetNotifications gets ScheduledNotifications in given range and full range

func (*DbConnector) GetNotifierState

func (connector *DbConnector) GetNotifierState() (string, error)

GetNotifierState return current notifier state: <OK|ERROR>

func (*DbConnector) GetPatternMetrics

func (connector *DbConnector) GetPatternMetrics(pattern string) ([]string, error)

GetPatternMetrics gets all metrics by given pattern

func (*DbConnector) GetPatternTriggerIDs

func (connector *DbConnector) GetPatternTriggerIDs(pattern string) ([]string, error)

GetPatternTriggerIDs gets trigger list by given pattern

func (*DbConnector) GetPatterns

func (connector *DbConnector) GetPatterns() ([]string, error)

GetPatterns gets updated patterns array

func (*DbConnector) GetRemoteChecksUpdatesCount

func (connector *DbConnector) GetRemoteChecksUpdatesCount() (int64, error)

GetRemoteChecksUpdatesCount return remote checks count by Moira-Checker

func (*DbConnector) GetRemoteTriggerIDs

func (connector *DbConnector) GetRemoteTriggerIDs() ([]string, error)

GetRemoteTriggerIDs gets moira remote triggerIDs

func (*DbConnector) GetRemoteTriggersToCheck added in v2.5.0

func (connector *DbConnector) GetRemoteTriggersToCheck(count int) ([]string, error)

GetRemoteTriggersToCheck return random remote trigger ID from Redis Set

func (*DbConnector) GetRemoteTriggersToCheckCount

func (connector *DbConnector) GetRemoteTriggersToCheckCount() (int64, error)

GetRemoteTriggersToCheckCount return number of remote triggers ID to check from Redis Set

func (*DbConnector) GetSubscription

func (connector *DbConnector) GetSubscription(id string) (moira.SubscriptionData, error)

GetSubscription returns subscription data by given id, if no value, return database.ErrNil error

func (*DbConnector) GetSubscriptions

func (connector *DbConnector) GetSubscriptions(subscriptionIDs []string) ([]*moira.SubscriptionData, error)

GetSubscriptions returns subscriptions data by given ids, len of subscriptionIDs is equal to len of returned values array. If there is no object by current ID, then nil is returned

func (*DbConnector) GetTagNames

func (connector *DbConnector) GetTagNames() ([]string, error)

GetTagNames returns all tags from set with tag data

func (*DbConnector) GetTagTriggerIDs

func (connector *DbConnector) GetTagTriggerIDs(tagName string) ([]string, error)

GetTagTriggerIDs gets all triggersIDs by given tagName

func (*DbConnector) GetTagsSubscriptions

func (connector *DbConnector) GetTagsSubscriptions(tags []string) ([]*moira.SubscriptionData, error)

GetTagsSubscriptions gets all subscriptionsIDs by given tag list and read subscriptions. Len of subscriptionIDs is equal to len of returned values array. If there is no object by current ID, then nil is returned

func (*DbConnector) GetTrigger

func (connector *DbConnector) GetTrigger(triggerID string) (moira.Trigger, error)

GetTrigger gets trigger and trigger tags by given ID and return it in merged object

func (*DbConnector) GetTriggerChecks

func (connector *DbConnector) GetTriggerChecks(triggerIDs []string) ([]*moira.TriggerCheck, error)

GetTriggerChecks gets triggers data with tags, lastCheck data and throttling by given triggersIDs Len of triggerIDs is equal to len of returned values array. If there is no object by current ID, then nil is returned

func (*DbConnector) GetTriggerLastCheck

func (connector *DbConnector) GetTriggerLastCheck(triggerID string) (moira.CheckData, error)

GetTriggerLastCheck gets trigger last check data by given triggerID, if no value, return database.ErrNil error

func (*DbConnector) GetTriggerThrottling

func (connector *DbConnector) GetTriggerThrottling(triggerID string) (time.Time, time.Time)

GetTriggerThrottling get throttling or scheduled notifications delay for given triggerID

func (*DbConnector) GetTriggers

func (connector *DbConnector) GetTriggers(triggerIDs []string) ([]*moira.Trigger, error)

GetTriggers returns triggers data by given ids, len of triggerIDs is equal to len of returned values array. If there is no object by current ID, then nil is returned

func (*DbConnector) GetUnusedTriggerIDs added in v2.4.0

func (connector *DbConnector) GetUnusedTriggerIDs() ([]string, error)

GetUnusedTriggerIDs returns all unused trigger IDs

func (*DbConnector) GetUserContactIDs

func (connector *DbConnector) GetUserContactIDs(login string) ([]string, error)

GetUserContactIDs returns contacts ids by given login

func (*DbConnector) GetUserSubscriptionIDs

func (connector *DbConnector) GetUserSubscriptionIDs(login string) ([]string, error)

GetUserSubscriptionIDs returns subscriptions ids by given login

func (*DbConnector) MarkTriggersAsUnused added in v2.4.0

func (connector *DbConnector) MarkTriggersAsUnused(triggerIDs ...string) error

MarkTriggersAsUnused adds unused trigger IDs to Redis set

func (*DbConnector) MarkTriggersAsUsed added in v2.4.0

func (connector *DbConnector) MarkTriggersAsUsed(triggerIDs ...string) error

MarkTriggersAsUsed removes trigger IDs from Redis set

func (*DbConnector) NewLock added in v2.5.0

func (connector *DbConnector) NewLock(name string, ttl time.Duration) moira.Lock

NewLock returns the implementation of moira.Lock which can be used to Acquire or Release the lock

func (*DbConnector) PushNotificationEvent

func (connector *DbConnector) PushNotificationEvent(event *moira.NotificationEvent, ui bool) error

PushNotificationEvent adds new NotificationEvent to events list and to given triggerID events list and deletes events who are older than 30 days If ui=true, then add to ui events list

func (*DbConnector) RemoveAllNotificationEvents

func (connector *DbConnector) RemoveAllNotificationEvents() error

RemoveAllNotificationEvents removes all notification events from database

func (*DbConnector) RemoveAllNotifications

func (connector *DbConnector) RemoveAllNotifications() error

RemoveAllNotifications delete all notifications

func (*DbConnector) RemoveContact

func (connector *DbConnector) RemoveContact(contactID string) error

RemoveContact deletes contact data and contactID from user contacts

func (*DbConnector) RemoveMetricValues

func (connector *DbConnector) RemoveMetricValues(metric string, toTime int64) error

RemoveMetricValues remove metric timestamps values from 0 to given time

func (*DbConnector) RemoveMetricsValues

func (connector *DbConnector) RemoveMetricsValues(metrics []string, toTime int64) error

RemoveMetricsValues remove metrics timestamps values from 0 to given time

func (*DbConnector) RemoveNotification

func (connector *DbConnector) RemoveNotification(notificationKey string) (int64, error)

RemoveNotification delete notifications by key = timestamp + contactID + subID

func (*DbConnector) RemovePattern

func (connector *DbConnector) RemovePattern(pattern string) error

RemovePattern removes pattern from patterns list

func (*DbConnector) RemovePatternTriggerIDs

func (connector *DbConnector) RemovePatternTriggerIDs(pattern string) error

RemovePatternTriggerIDs removes all triggerIDs list accepted to given pattern

func (*DbConnector) RemovePatternWithMetrics

func (connector *DbConnector) RemovePatternWithMetrics(pattern string) error

RemovePatternWithMetrics removes pattern metrics with data and given pattern

func (*DbConnector) RemovePatternsMetrics

func (connector *DbConnector) RemovePatternsMetrics(patterns []string) error

RemovePatternsMetrics removes metrics by given patterns

func (*DbConnector) RemoveSubscription

func (connector *DbConnector) RemoveSubscription(subscriptionID string) error

RemoveSubscription deletes subscription data and removes subscriptionID from users and tags subscriptions

func (*DbConnector) RemoveTag

func (connector *DbConnector) RemoveTag(tagName string) error

RemoveTag deletes tag from tags list, deletes triggerIDs and subscriptionsIDs lists by given tag

func (*DbConnector) RemoveTrigger

func (connector *DbConnector) RemoveTrigger(triggerID string) error

RemoveTrigger deletes trigger data by given triggerID, delete trigger tag list, Deletes triggerID from containing tags triggers list and from containing patterns triggers list If containing patterns doesn't used in another triggers, then delete this patterns with metrics data

func (*DbConnector) RemoveTriggerLastCheck

func (connector *DbConnector) RemoveTriggerLastCheck(triggerID string) error

RemoveTriggerLastCheck removes trigger last check data

func (*DbConnector) RemoveTriggersToReindex added in v2.4.0

func (connector *DbConnector) RemoveTriggersToReindex(to int64) error

RemoveTriggersToReindex removes outdated triggerIDs from redis

func (*DbConnector) RemoveUser

func (connector *DbConnector) RemoveUser(messenger, username string) error

RemoveUser removes username from messenger data

func (*DbConnector) SaveContact

func (connector *DbConnector) SaveContact(contact *moira.ContactData) error

SaveContact writes contact data and updates user contacts

func (*DbConnector) SaveMetrics

func (connector *DbConnector) SaveMetrics(metrics map[string]*moira.MatchedMetric) error

SaveMetrics saves new metrics

func (*DbConnector) SaveSubscription

func (connector *DbConnector) SaveSubscription(subscription *moira.SubscriptionData) error

SaveSubscription writes subscription data, updates tags subscriptions and user subscriptions

func (*DbConnector) SaveSubscriptions

func (connector *DbConnector) SaveSubscriptions(newSubscriptions []*moira.SubscriptionData) error

SaveSubscriptions writes subscriptions, updates tags subscriptions and user subscriptions

func (*DbConnector) SaveTrigger

func (connector *DbConnector) SaveTrigger(triggerID string, trigger *moira.Trigger) error

SaveTrigger sets trigger data by given trigger and triggerID If trigger already exists, then merge old and new trigger patterns and tags list and cleanup not used tags and patterns from lists If given trigger contains new tags then create it. If given trigger has no subscription on it, add it to triggers-without-subscriptions

func (*DbConnector) SetNotifierState

func (connector *DbConnector) SetNotifierState(health string) error

SetNotifierState update current notifier state: <OK|ERROR>

func (*DbConnector) SetTriggerCheckLock

func (connector *DbConnector) SetTriggerCheckLock(triggerID string) (bool, error)

SetTriggerCheckLock create to database lock object with 30sec TTL and return true if object successfully created, or false if object already exists

func (*DbConnector) SetTriggerCheckMaintenance added in v2.4.0

func (connector *DbConnector) SetTriggerCheckMaintenance(triggerID string, metrics map[string]int64, triggerMaintenance *int64, userLogin string, timeCallMaintenance int64) error

SetTriggerCheckMaintenance sets maintenance for whole trigger and to given metrics, If during the update lastCheck was updated from another place, try update again If CheckData does not contain one of given metrics it will ignore this metric

func (*DbConnector) SetTriggerLastCheck

func (connector *DbConnector) SetTriggerLastCheck(triggerID string, checkData *moira.CheckData, isRemote bool) error

SetTriggerLastCheck sets trigger last check data

func (*DbConnector) SetTriggerThrottling

func (connector *DbConnector) SetTriggerThrottling(triggerID string, next time.Time) error

SetTriggerThrottling store throttling or scheduled notifications delay for given triggerID

func (*DbConnector) SetUsernameID

func (connector *DbConnector) SetUsernameID(messenger, username, id string) error

SetUsernameID store id of username

func (*DbConnector) SubscribeMetricEvents

func (connector *DbConnector) SubscribeMetricEvents(tomb *tomb.Tomb) (<-chan *moira.MetricEvent, error)

SubscribeMetricEvents creates subscription for new metrics and return channel for this events

func (*DbConnector) UpdateMetricsHeartbeat

func (connector *DbConnector) UpdateMetricsHeartbeat() error

UpdateMetricsHeartbeat increments redis counter

type DirectPoolDialer added in v2.5.0

type DirectPoolDialer struct {
	// contains filtered or unexported fields

DirectPoolDialer connects directly to Redis

func (*DirectPoolDialer) Dial added in v2.5.0

func (dialer *DirectPoolDialer) Dial() (redis.Conn, error)

Dial connects directly to the server

func (*DirectPoolDialer) Test added in v2.5.0

func (dialer *DirectPoolDialer) Test(c redis.Conn, t time.Time) error

Test checks the connection by sending PING to the server

type Lock added in v2.5.0

type Lock struct {
	// contains filtered or unexported fields

Lock is used to hide low-level details of redsync.Mutex such as an extension of it

func (*Lock) Acquire added in v2.5.0

func (lock *Lock) Acquire(stop <-chan struct{}) (<-chan struct{}, error)

Acquire attempts to acquire the lock and blocks while doing so Providing a non-nil stop channel can be used to abort the acquire attempt Returns lost channel that is closed if the lock is lost or an error

func (*Lock) Release added in v2.5.0

func (lock *Lock) Release()

Release releases the lock

type PoolDialer added in v2.5.0

type PoolDialer interface {
	// Dial creates a connection
	Dial() (redis.Conn, error)
	// Test helps to check if a connection
	Test(c redis.Conn, t time.Time) error

PoolDialer hides details of how connections are created and tested in a pool

type SentinelPoolDialer added in v2.5.0

type SentinelPoolDialer struct {
	// contains filtered or unexported fields

SentinelPoolDialer connects directly to Redis through sentinels

func NewSentinelPoolDialer added in v2.5.0

func NewSentinelPoolDialer(logger moira.Logger, config SentinelPoolDialerConfig) *SentinelPoolDialer

NewSentinelPoolDialer returns new SentinelPoolDialer

func (*SentinelPoolDialer) Dial added in v2.5.0

func (dialer *SentinelPoolDialer) Dial() (redis.Conn, error)

Dial finds the master and connects to it

func (*SentinelPoolDialer) Test added in v2.5.0

func (dialer *SentinelPoolDialer) Test(c redis.Conn, t time.Time) error

Test checks if connection is alive and connected to the master

type SentinelPoolDialerConfig added in v2.5.0

type SentinelPoolDialerConfig struct {
	MasterName        string
	SentinelAddresses []string
	DB                int
	DialTimeout       time.Duration

SentinelPoolDialerConfig provides options to configure SentinelPoolDialer


Path Synopsis

Jump to

Keyboard shortcuts

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