Skip to content

Commit

Permalink
fix(trigger, subscription): Timezone work (#22)
Browse files Browse the repository at this point in the history
fix(trigger, subscription): Fix missed disabled_days
fix(build): Push only tags create
feat(build): Set 2.6.1 version
  • Loading branch information
kissken authored Jan 9, 2023
1 parent 7f2b7cc commit 68d10c1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on: push
on:
create:
tags:
- v*

jobs:
build-n-publish:
Expand Down
3 changes: 2 additions & 1 deletion moira_client/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MINUTES_IN_HOUR = 60


def get_schedule(start_hour, start_minute, end_hour, end_minute, disabled_days):
def get_schedule(start_hour, start_minute, end_hour, end_minute, disabled_days, timezone_offset):
days = []
for day in DAYS_OF_WEEK:
day_info = {
Expand All @@ -15,4 +15,5 @@ def get_schedule(start_hour, start_minute, end_hour, end_minute, disabled_days):
'days': days,
'startOffset': start_hour * MINUTES_IN_HOUR + start_minute,
'endOffset': end_hour * MINUTES_IN_HOUR + end_minute,
'tzOffset': timezone_offset,
}
6 changes: 4 additions & 2 deletions moira_client/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def __init__(self, client, tags, contacts=None, enabled=None, throttling=None, s
'endOffset': 1439,
'tzOffset': 0
}
self.disabled_days = set()

if not sched:
sched = default_sched
self.disabled_days = set()
else:
if 'days' in sched and sched['days'] is not None:
self.disabled_days = {day['name'] for day in sched['days'] if not day['enabled']}
Expand All @@ -49,6 +50,7 @@ def __init__(self, client, tags, contacts=None, enabled=None, throttling=None, s
self._start_minute = self.sched['startOffset'] - self._start_hour * MINUTES_IN_HOUR
self._end_hour = self.sched['endOffset'] // MINUTES_IN_HOUR
self._end_minute = self.sched['endOffset'] - self._end_hour * MINUTES_IN_HOUR
self._timezone_offset = self.sched['tzOffset']

self.ignore_warnings = ignore_warnings
self.ignore_recoverings = ignore_recoverings
Expand All @@ -74,7 +76,7 @@ def _send_request(self, subscription_id=None):
data['id'] = subscription_id

data['sched'] = get_schedule(self._start_hour, self._start_minute, self._end_hour, self._end_minute,
self.disabled_days)
self.disabled_days, self._timezone_offset)

if subscription_id:
result = self._client.put('subscription/{id}'.format(id=subscription_id), json=data)
Expand Down
20 changes: 11 additions & 9 deletions moira_client/models/trigger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..client import ResponseStructureError
from ..client import InvalidJSONError
from .base import Base
from .common import MINUTES_IN_HOUR, get_schedule
from .common import MINUTES_IN_HOUR, DAYS_OF_WEEK, get_schedule

STATE_OK = 'OK'
STATE_WARN = 'WARN'
Expand Down Expand Up @@ -64,17 +64,18 @@ def __init__(
self.desc = desc
self.ttl = ttl
self.ttl_state = ttl_state

default_sched = {
'startOffset': 0,
'endOffset': 1439,
'tzOffset': 0
}
self.disabled_days = set()

if not sched:
sched = default_sched
self.disabled_days = set()
else:
if 'days' in sched:
if 'days' in sched and sched['days'] is not None:
self.disabled_days = {day['name'] for day in sched['days'] if not day['enabled']}
self.sched = sched
self.expression = expression
Expand All @@ -85,6 +86,7 @@ def __init__(
self._start_minute = self.sched['startOffset'] - self._start_hour * MINUTES_IN_HOUR
self._end_hour = self.sched['endOffset'] // MINUTES_IN_HOUR
self._end_minute = self.sched['endOffset'] - self._end_hour * MINUTES_IN_HOUR
self._timezone_offset = self.sched['tzOffset']

self.is_remote = is_remote
self.mute_new_metrics = mute_new_metrics
Expand Down Expand Up @@ -169,7 +171,7 @@ def _send_request(self, trigger_id=None):
self._client).fetch_by_id(trigger_id)

data['sched'] = get_schedule(self._start_hour, self._start_minute, self._end_hour, self._end_minute,
self.disabled_days)
self.disabled_days, self._timezone_offset)

if trigger_id and api_response:
res = self._client.put('trigger/{id}'.format(id=trigger_id), json=data)
Expand Down Expand Up @@ -250,7 +252,7 @@ def check_exists(self):
trigger_manager = TriggerManager(self._client)
for trigger in trigger_manager.fetch_all():
if self.name == trigger.name and \
set(self.targets) == set(trigger.targets) and \
set(self.targets) == set(trigger.targets) and \
set(self.tags) == set(trigger.tags):
return trigger

Expand Down Expand Up @@ -477,7 +479,7 @@ def is_exist(self, trigger):
"""
for moira_trigger in self.fetch_all():
if trigger.name == moira_trigger.name and \
set(trigger.targets) == set(moira_trigger.targets) and \
set(trigger.targets) == set(moira_trigger.targets) and \
set(trigger.tags) == set(moira_trigger.tags):
return True
return False
Expand All @@ -495,8 +497,8 @@ def get_non_existent(self, triggers):
exist = False
for moira_trigger in moira_triggers:
if trigger.name == moira_trigger.name and \
set(trigger.targets) == set(moira_trigger.targets) and \
set(trigger.tags) == set(moira_trigger.tags):
set(trigger.targets) == set(moira_trigger.targets) and \
set(trigger.tags) == set(moira_trigger.tags):
exist = True
break
if not exist:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='moira-python-client',
version='2.6.0',
version='2.6.1',
description='Client for Moira - Alerting system based on Graphite data',
keywords='moira monitoring client metrics alerting',
long_description="""
Expand Down

0 comments on commit 68d10c1

Please sign in to comment.