moira

Форк
0
/
interfaces.go 
233 строки · 10.2 Кб
1
package moira
2

3
import (
4
	"time"
5

6
	"gopkg.in/tomb.v2"
7
)
8

9
// Database implements DB functionality
10
type Database interface {
11
	// SelfState
12
	UpdateMetricsHeartbeat() error
13
	GetMetricsUpdatesCount() (int64, error)
14
	GetChecksUpdatesCount() (int64, error)
15

16
	// Tag storing
17
	GetTagNames() ([]string, error)
18
	RemoveTag(tagName string) error
19
	GetTagTriggerIDs(tagName string) ([]string, error)
20
	GetTagsStats(tags ...string) ([]TagStats, error)
21

22
	// LastCheck storing
23
	GetTriggerLastCheck(triggerID string) (*CheckData, error)
24
	GetTriggerLastChecks(triggerIDs []string) (map[string]*CheckData, error)
25
	GetOrCreateTriggerLastCheck(triggerID string) (*CheckData, error)
26
	SetTriggerLastCheck(triggerID string, checkData *CheckData) error
27
	RemoveTriggerLastCheck(triggerID string) error
28
	GetTriggerCheckIDs(tags []string, onlyErrors bool) ([]string, error)
29

30
	// Maintenance operations
31
	GetMaintenanceSilent(spt SilentPatternType) (Maintenance, error)
32
	GetMaintenanceTrigger(id string) (Maintenance, error)
33
	GetOrCreateMaintenanceSilent(spt SilentPatternType) (Maintenance, error)
34
	GetOrCreateMaintenanceTrigger(id string) (Maintenance, error)
35
	SetMaintenanceTrigger(id string, maintenance Maintenance) error
36
	DelMaintenanceTrigger(id string) error
37

38
	// Trigger storing
39
	CheckTriggerExists(string) (bool, error)
40
	GetTriggerIDs(onlyPull bool) ([]string, error)
41
	GetTrigger(triggerID string) (*Trigger, error)
42
	GetTriggers(triggerIDs []string) ([]*Trigger, error)
43
	GetTriggerChecks(triggerIDs []string) ([]*TriggerCheck, error)
44
	SaveTrigger(triggerID string, trigger *Trigger) error
45
	RemoveTrigger(triggerID string) error
46
	GetPatternTriggerIDs(pattern string) ([]string, error)
47
	RemovePatternTriggerIDs(pattern string) error
48
	AddTriggerForcedNotification(triggerID string, metrics []string, time int64) error
49
	GetTriggerForcedNotifications(triggerID string) (map[string]bool, error)
50
	DeleteTriggerForcedNotification(triggerID string, metric string) error
51
	DeleteTriggerForcedNotifications(triggerID string, metrics []string) error
52

53
	// Throttling
54
	GetTriggerThrottling(triggerID string) (time.Time, time.Time)
55
	SetTriggerThrottling(triggerID string, next time.Time) error
56
	DeleteTriggerThrottling(triggerID string) error
57

58
	// NotificationEvent storing
59
	GetNotificationEvents(triggerID string, start, size int64) ([]*NotificationEvent, error)
60
	GetAllNotificationEvents(start, end int64) ([]*NotificationEvent, error)
61
	PushNotificationEvent(event *NotificationEvent) error
62
	GetNotificationEventCount(triggerID string, from int64) int64
63
	FetchNotificationEvent(withSaturations bool) (NotificationEvent, error)
64
	FetchDelayedNotificationEvents(to int64, withSaturations bool) ([]NotificationEvent, error)
65
	AddDelayedNotificationEvent(event NotificationEvent, timestamp int64) error
66

67
	// Event inheritance
68
	AddChildEvents(parentTriggerID string, parentMetric string, childTriggerID string, childMetrics []string) error
69
	GetChildEvents(parentTriggerID, parentMetric string) (map[string][]string, error)
70
	GetParentEvents(childTriggerID, childMetric string) (map[string][]string, error)
71
	DeleteChildEvents(parentTriggerID, parentMetric string, childTriggerID string, childMetrics []string) error
72

73
	// ContactData storing
74
	GetContact(contactID string) (ContactData, error)
75
	GetContacts(contactIDs []string) ([]*ContactData, error)
76
	GetAllContacts() ([]*ContactData, error)
77
	RemoveContact(contactID string) error
78
	SaveContact(contact *ContactData) error
79
	GetUserContactIDs(userLogin string) ([]string, error)
80

81
	// SilentPatterData storing
82
	GetSilentPatternsAll() ([]*SilentPatternData, error)
83
	GetSilentPatternsTyped(pt SilentPatternType) ([]*SilentPatternData, error)
84
	SaveSilentPatterns(pt SilentPatternType, spl ...*SilentPatternData) error
85
	RemoveSilentPatterns(pt SilentPatternType, spl ...*SilentPatternData) error
86
	LockSilentPatterns(pt SilentPatternType) error
87
	UnlockSilentPatterns(pt SilentPatternType) error
88

89
	// SubscriptionData storing
90
	GetSubscription(id string) (SubscriptionData, error)
91
	GetSubscriptions(subscriptionIDs []string) ([]*SubscriptionData, error)
92
	GetAllSubscriptions() ([]*SubscriptionData, error)
93
	MaybeUpdateEscalationsOfSubscription(subscription *SubscriptionData) error
94
	SaveSubscription(subscription *SubscriptionData) error
95
	SaveSubscriptions(subscriptions []*SubscriptionData) error
96
	RemoveSubscription(subscriptionID string) error
97
	GetUserSubscriptionIDs(userLogin string) ([]string, error)
98
	GetTagsSubscriptions(tags []string) ([]*SubscriptionData, error)
99

100
	// ScheduledNotification storing
101
	GetNotifications(start, end int64) ([]*ScheduledNotification, int64, error)
102
	RemoveNotification(notificationKey string) (int64, error)
103
	FetchNotifications(to int64) ([]*ScheduledNotification, error)
104
	AddNotification(notification *ScheduledNotification) error
105
	AddNotifications(notification []*ScheduledNotification, timestamp int64) error
106

107
	// Patterns and metrics storing
108
	GetPatterns() ([]string, error)
109
	AddPatternMetric(pattern, metric string) error
110
	GetPatternMetrics(pattern string) ([]string, error)
111
	RemovePattern(pattern string) error
112
	RemovePatternsMetrics(pattern []string) error
113
	RemovePatternWithMetrics(pattern string) error
114

115
	SubscribeMetricEvents(tomb *tomb.Tomb) (<-chan *MetricEvent, error)
116
	SaveMetrics(buffer map[string]*MatchedMetric) error
117
	GetMetricRetention(metric string) (int64, error)
118
	GetMetricsValues(metrics []string, from int64, until int64) (map[string][]*MetricValue, error)
119
	RemoveMetricValues(metric string, toTime int64) error
120
	RemoveMetricsValues(metrics []string, toTime int64) error
121

122
	// Locks
123
	AcquireLock(lockKey string, ttlSec int, timeout time.Duration) error
124
	AcquireTriggerCheckLock(triggerID string) error
125
	AcquireTriggerMaintenanceLock(triggerID string) error
126
	DeleteLock(lockKey string) error
127
	DeleteTriggerCheckLock(triggerID string) error
128
	DeleteTriggerMaintenanceLock(triggerID string) error
129
	SetLock(lockKey string, ttlSec int) (bool, error)
130
	SetTriggerCheckLock(triggerID string) (bool, error)
131
	SetTriggerCoolDown(triggerID string, ttlSec int) (bool, error)
132

133
	// Bot data storing
134
	GetIDByUsername(messenger, username string) (string, error)
135
	SetUsernameID(messenger, username, id string) error
136
	RemoveUser(messenger, username string) error
137
	RegisterBotIfAlreadyNot(messenger string, ttl time.Duration) bool
138
	RenewBotRegistration(messenger string) bool
139
	DeregisterBots()
140
	DeregisterBot(messenger string) bool
141

142
	// Escalations
143
	AddEscalations(ts int64, event NotificationEvent, trigger TriggerData, escalations []EscalationData) error
144
	TriggerHasPendingEscalations(triggerID string, withResolutions bool) (bool, error)
145
	MetricHasPendingEscalations(triggerID, metric string, withResolutions bool) (bool, error)
146
	AckEscalations(triggerID, metric string, withResolutions bool) error
147
	AckEscalationsBatch(triggerID string, metrics []string, withResolutions bool) error
148
	FetchScheduledEscalationEvents(to int64) ([]*ScheduledEscalationEvent, error)
149
	RegisterProcessedEscalationID(escalationID, triggerID, metric string) error
150
	AddUnacknowledgedMessage(triggerID string, metric string, link MessageLink) error
151
	GetUnacknowledgedMessages(triggerID, metric string) ([]MessageLink, error)
152
	AckUnacknowledgedMessages(triggerID, metric string) error
153

154
	// Global settings
155
	GetGlobalSettings() (GlobalSettings, error)
156
	SetGlobalSettings(GlobalSettings) error
157

158
	// Slack-specific
159
	GetSlackThreadLinks(contactID, triggerID string) (messages map[string]string, err error)
160
	AddSlackThreadLinks(contactID, triggerID, threadTs, payload string, expiryTime *time.Time) error
161
	RemoveSlackThreadLinks(contactID, triggerID string, threadsTs, completedThreads []string) error
162
	GetAllSlackThreadLinks(triggerID string) ([]SlackThreadLink, error)
163

164
	GetSlackDashboard(contactID, ts string) (SlackDashboard, error)
165
	UpdateSlackDashboard(contactID, ts string, db SlackDashboard, expiryTime *time.Time) error
166
	RemoveSlackDashboards(contactID string, dashboardsTs []string) error
167
	GetAllInheritedTriggerDashboards(triggerID, ancestorTriggerID, ancestorMetric string) ([]SlackThreadLink, error)
168
	SaveInheritedTriggerDashboard(contactID, threadTs, triggerID, ancestorTriggerID, ancestorMetric, newDashboardTs string) error
169
	DeleteInheritedTriggerDashboard(contactID, threadTs, triggerID, ancestorTriggerID, ancestorMetric, dashboardTs string) error
170

171
	UpdateInheritanceDataVersion() error
172

173
	FetchSlackDelayedActions(until time.Time) ([]SlackDelayedAction, error)
174
	SaveSlackDelayedAction(action SlackDelayedAction) error
175
	GetSlackUserGroups() (SlackUserGroupsCache, error)
176
	SaveSlackUserGroups(userGroups SlackUserGroupsCache) error
177

178
	GetServiceDuty(service string) (DutyData, error)
179
	UpdateServiceDuty(service string, dutyData DutyData) error
180
}
181

182
type TriggerInheritanceDatabase interface {
183
	Ping() bool
184

185
	GetMaxDepthInGraph(id string) (int, error)
186
	GetAllAncestors(id string) ([][]string, error)
187
	GetAllChildren(triggerID string) ([]string, error)
188
	SetTriggerParents(triggerID string, newParentIDs []string) error
189
}
190

191
// Logger implements logger abstraction
192
type Logger interface {
193
	Debug(message string)
194
	DebugE(message string, extra interface{})
195
	DebugF(format string, args ...interface{})
196
	Info(message string)
197
	InfoE(message string, extra interface{})
198
	InfoF(format string, args ...interface{})
199
	Warn(message string)
200
	WarnE(message string, extra interface{})
201
	WarnF(format string, args ...interface{})
202
	Error(message string)
203
	ErrorE(message string, extra interface{})
204
	ErrorF(format string, args ...interface{})
205
	Fatal(message string)
206
	FatalE(message string, extra interface{})
207
	FatalF(format string, args ...interface{})
208
	TracePanic(message string, extra interface{})
209
	TraceSelfStats(id string, started time.Time)
210
}
211

212
// Sender interface for implementing specified contact type sender
213
type Sender interface {
214
	Init(senderSettings map[string]string, location *time.Location) error
215
	SendEvents(events NotificationEvents, contact ContactData, trigger TriggerData, throttled, needAck bool) error
216
}
217

218
// SenderWithInheritance is a sender that can send messages to ancestor triggers' threads
219
type SenderWithInheritance interface {
220
	Sender
221
	SendEventsWithInheritance(
222
		events NotificationEvents, contact ContactData, trigger TriggerData,
223
		ancestorTriggerID, ancestorMetric string,
224
	) error
225
}
226

227
// MessageLink is a link to a message sent in a Sender.
228
type MessageLink interface {
229
	// StorageKey is used to serialize a Link to store it in a Database
230
	StorageKey() string
231
	FromString(string) error
232
	SenderName() string
233
}
234

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.