Redis Data Layer

Redis database objects:
  • KEY moira-metric-last-check:<trigger_id>
  • SET moira-pattern-metrics:<pattern>
  • SET moira-pattern-triggers:<pattern>
  • KEY moira-trigger:<trigger_id>
  • LIST moira-trigger-events
  • LIST moira-trigger-events-ui
  • SORTED SET moira-metric-data:<metric>
  • KEY moira-metric-retention:<metric>
  • SET moira-triggers-list
  • SET moira-pattern-list
  • SET moira-trigger-tags:<trigger_id>
  • SET moira-tags
  • SET moira-tag-triggers:<tag>
  • SET moira-triggers-tocheck
  • SET moira-user-subscriptions:<login>
  • SET moira-tag-subscriptions:<tag>
  • KEY moira-subscription:<subscription_id>
  • KEY moira-contact:<contact_id>
  • SET moira-user-contacts:<login>
  • SORTED SET moira-trigger-events:<trigger_id>
  • SET moira-notifier-throttling-beginning:<trigger_id>
  • KEY moira-tag:<tag>
  • KEY moira-metric-check-lock:trigger_id
  • SORTED SET moira-triggers-checks
  • SET moira-bad-state-triggers
  • KEY moira-selfstate:checks-counter
class moira.db.Db

Redis database service class

accuireTriggerCheckLock(self, trigger_id, timeout)

Try to accuire lock for trigger check until timeout

Parameters:
  • trigger_id (string) – trigger identity
  • timeout (float) – timeout in seconds
addPatternMetric(self, pattern, metric)

Add metric to set moira-pattern-metrics:<pattern>

Parameters:
  • pattern (string) – pattern of graphite that match multiple metric
  • metric (string) – metric of graphite
addTriggerCheck(self, trigger_id)

Add trigger_id to set moira-triggers-tocheck

Parameters:trigger_id (string) – trigger identity
addTriggerTag(self, trigger_id, tag)
Creates redis transaction for:
  • Add tag to set moira-trigger-tags:<trigger_id>
  • Add trigger_id to set moira-tag-triggers:<tag>
  • Add tag to set moira-tags
Parameters:trigger_id (string) – trigger identity
cleanupMetricValues(self, metric, toTime)

Remove metric values from sorted set moira-metric-data:<metric> until toTime

Parameters:startTime (long) – unix epoch time
delMetric(self, metric)

Delete metric sorted set moira-metric-data:<metric>

Parameters:metric (string) – metric of graphite
delPatternMetrics(self, pattern)

Delete whole set moira-pattern-metrics:<pattern> of metrics for given pattern

Parameters:pattern (string) – pattern of graphite that match multiple metric
delTriggerCheckLock(self, trigger_id)

Delete lock for trigger check moira-metric-check-lock:<trigger_id>

Parameters:trigger_id (string) – trigger identity
deleteTriggerThrottling(self, trigger_id)

Read all planning notifications from sorted set moira-notifier-notifications and rescheduling it delivery to now

Parameters:trigger_id (string) – trigger identity
deleteUserContact(self, contact_id, login)
Creates redis transaction for:
  • remove key moira-contact:<contact_id>
  • remove contact_id from set moira-user-contacts:login
Parameters:
  • contact_id (string) – contact id
  • login (string) – user login
getAllContacts(self, login)

Returns all contacts json

Return type:array of strings
getContact(self, contact_id)

Returns contact by given id from key moira-contact:contact_id

Parameters:contact_id (string) – contact id
Return type:json dict
getEvents(self)

Returns all events for given trigger_id

Parameters:trigger_id (string) – trigger identity
Return type:list of dict
getFilteredTriggersChecksPage(self, page, size, filter_ok, filter_tags)
  • Returns filtered triggers page
Parameters:
  • start (integer) – start position in range
  • start – number of triggers
  • filter_ok (boolean) – use triggers set in bad state
  • filter_tags (list of strings) – use tag triggers set
Return type:

json

getMetricRetention(self, metric)

Returns metric retention in seconds from key moira-metric-retention:<metric> for given metric

Parameters:metric (string) – metric of graphite
Return type:integer
getMetricsValues(self, metrics, startTime, endTime)

Read multiple metric values from sorted set moira-metric-data:<metric> from startTime

Parameters:
  • metrics (list of string) – list of graphite metric path
  • startTime (long) – unix epoch time
  • endTime (long) – unix epoch time
Return type:

list of list of tuple (‘value timestamp’, long)

getNotifications(self, start, end)

Read all planning notifications from sorted set moira-notifier-notifications

Parameters:
  • start (integer) – range start
  • end (integer) – range end
getPatternMetrics(self, pattern)

Read all metrics from set moira-pattern-metrics:<pattern> for given pattern

Parameters:pattern (string) – pattern of graphite that match multiple metric
Return type:set of strings
getPatternTriggers(self, pattern)

Returns all trigger identifiers from set moira-pattern-triggers:<pattern>

Parameters:pattern (string) – pattern of graphite that match multiple metric
Return type:set of strings
getPatterns(self)

Returns all patterns from SET moira-pattern-list

Return type:set of strings
getSubscription(self, sub_id)

Returns subscription by given id from key moira-subscription:subscription_id

Parameters:sub_id (string) – subscription id
Return type:json dict
getTag(self, tag)

Returns tag data from key moira-tag:{0}

Return type:json dict
getTagSubscriptions(self, tag)

Returns all subscriptions by given tag from set moira-tag-subscriptions:<tag>

Return type:list of strings
getTagTriggers(self, tag)

Returns all trigger is for given tag from set moira-tag-triggers:<tag>

Return type:set of strings
getTags(self)

Returns all tags from set moira-tags with tag data

Return type:dict
getTrigger(self, trigger_id)
  • Read trigger by key moira-trigger:<trigger_id>
  • Unpack trigger json
Parameters:
  • tags (boolean) – get with tags
  • trigger_id (string) – trigger identity
Return type:

tuple(json, trigger)

getTriggerLastCheck(self, trigger_id)

Returns last trigger check from key moira-metric-last-check:<trigger_id>

Parameters:trigger_id (string) – trigger identity
Return type:json dict
getTriggerThrottling(self, trigger_id)

Returns planning trigger notification timestamp in future or 0 from key moira-notifier-next:<trigger_id>

Parameters:trigger_id (string) – trigger identity
Return type:long
getTriggerToCheck(self)

Pop trigger id from set moira-triggers-tocheck

Return type:string
getTriggers(self)

Returns all triggers id from set moira-triggers-list

Return type:set of strings
getTriggersChecks(self)
  • Returns all triggers with it check
Return type:json
getTriggersChecksPage(self, start, size)
  • Returns triggers range from sorted set moira-triggers-checks
Parameters:
  • start (integer) – start position in range
  • start – number of triggers
Return type:

json

getUserContacts(self, login)

Returns contacts ids by given login from set moira-user-contacts:<login>

Parameters:login (string) – user login
Return type:set of strings
getUserSubscriptions(self, login)

Returns subscriptions ids by given login from set moira-user-subscriptions:<login>

Parameters:login (string) – user login
Return type:set of strings
pushEvent(self, event)
Creates redis transaction for:
  • Add event to beginning of list moira-trigger-events as json string
  • Trim list to 100 events
Parameters:event (dict) – trigger state changing event
removeNotification(self, json)

Remove planning notification by given json from sorted set moira-notifier-notifications

Parameters:json (string) – notification json
removePattern(self, pattern)

Remove pattern from set moira-pattern-list

Parameters:pattern (string) – pattern of graphite that match multiple metric
removePatternTriggers(self, pattern)

Delete all trigger identifiers from set moira-pattern-triggers:<pattern>

Parameters:pattern (string) – pattern of graphite that match multiple metric
removeTag(self, tag)
Creates redis transaction for:
  • Remove tag from set moira-tags
  • Delete key moira-tag-subscriptions:<tag>
  • Delete key moira-tag-triggers:<tag>
  • Delete key moira-tag:<tag>
removeTrigger(self, trigger_id)
Creates redis transaction for:
  • Delete key moira-trigger:<trigger_id>
  • Remove trigger_id from set moira-triggers-list
  • Remove trigger_id from set moira-pattern-triggers:<pattern>
Parameters:trigger_id (string) – trigger identity
removeTriggerLastCheck(self, trigger_id)

Delete trigger last check from key moira-metric-last-check:<trigger_id>

Parameters:trigger_id (string) – trigger identity
removeTriggerTag(self, trigger_id, tag)
Creates redis transaction for:
  • Remove tag from set moira-trigger-tags:<trigger_id>
  • Remove trigger_id from set moira-tag-triggers:<tag>
Parameters:trigger_id (string) – trigger identity
removeUserSubscription(self, login, sub_id)
Creates redis transaction for:
  • delete key moira-subscription:subscription_id
  • remove sub_id from set moira-user-subscriptions:login
Parameters:
  • login (string) – user login
  • sub_id (string) – subscription id
saveTrigger(self, trigger_id, trigger)
Creates redis transaction for:
  • Saving trigger_json to key moira-trigger:<trigger_id>
  • Add trigger_id to set moira-triggers-list
  • Update patterns set moira-pattern-list
  • Update trigger patterns set moira-pattern-triggers:<pattern>
Parameters:
  • trigger (dict) – trigger json object
  • trigger_id (string) – trigger identity
saveUserContact(self, login, contact)
Creates redis transaction for:
  • save contact json to key moira-contact:<contact_id>
  • add contact_id to set moira-user-contacts:login
Parameters:
  • login (string) – user login
  • contact (json dict) – contact data
Return type:

json dict

saveUserSubscription(self, login, sub)
Creates redis transaction for:
  • save sub json to key moira-subscription:<sub_id>
  • add sub_id to set moira-user-subscriptions:<login>
Parameters:
  • login (string) – user login
  • sub (json dict) – subscription data
Return type:

json dict

setTag(self, tag, data)

Save tag data to key moira-tag:{0}

Return type:json dict
setTriggerCheckLock(self, trigger_id)

Try to accuire lock for trigger check moira-metric-check-lock:<trigger_id>

Parameters:trigger_id (string) – trigger identity
setTriggerLastCheck(self, trigger_id, check)

Save trigger last check to key moira-metric-last-check:<trigger_id>

Parameters:
  • trigger_id (string) – trigger identity
  • check (json dict) – trigger checking result
setTriggerMetricsMaintenance(self, trigger_id, metrics)

Atomic change of trigger last check and set metric maintenance

Parameters:
  • trigger_id (string) – trigger identity
  • metrics (dict) – metrics maintenance flags
startService(self)

Creates redis connection pool

stopService(self)

Disconnect from redis connection pool

moira.db.audit(f)

Write json object changes to audit.log