Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
Fix resetting oauth2 tokens (#386)
Browse files Browse the repository at this point in the history
* Fix resetting oauth2 tokens

Signed-off-by: Mohab Usama <[email protected]>

* Fix sampling update rate

Signed-off-by: Mohab Usama <[email protected]>
  • Loading branch information
mohabusama authored Dec 13, 2018
1 parent a9d5935 commit e5b6d72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ plugin.openam.url: 'https://auth.zalando.com/z'


# sampling
zmon.sampling.update.rate: 120
zmon.sampling.rate: 100
zmon.critical.checks: []
11 changes: 7 additions & 4 deletions zmon_worker_monitor/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
__config = None


# We manage uid tokens once when we import
tokens.manage('uid', ['uid'])


def get_sampling_rate_config(config, current_span):
"""
Get sampling rate config from a ZMON entity or config vars.
Expand Down Expand Up @@ -81,9 +85,6 @@ def get_sampling_rate_config(config, current_span):
current_span.set_tag('sampling_entity_used', True)

try:
tokens.configure()
tokens.manage('uid', ['uid'])

url = '{}/api/v1/entities/{}'.format(zmon_url, SAMPLING_RATE_ENTITY_ID)
headers = {'Authorization': 'Bearer {}'.format(tokens.get('uid'))}
resp = requests.get(url, headers=headers, timeout=2)
Expand Down Expand Up @@ -176,6 +177,7 @@ def flow_simple_queue_processor(queue='', **execution_context):

sampling_rate_last_updated = datetime.utcnow()
sampling_config = None
sampling_update_rate = int(config.get('zmon.sampling.update.rate', SAMPLING_RATE_UPDATE_DURATION))

while True:
try:
Expand Down Expand Up @@ -204,8 +206,9 @@ def flow_simple_queue_processor(queue='', **execution_context):

# Get sampling rates. We update every minute.
if sampling_config is None or (
(datetime.utcnow() - sampling_rate_last_updated).seconds > SAMPLING_RATE_UPDATE_DURATION):
(datetime.utcnow() - sampling_rate_last_updated).seconds > sampling_update_rate):
try:
sampling_rate_last_updated = datetime.utcnow()
sampling_config = get_sampling_rate_config(config, span)
span.log_kv({'sampling_config': sampling_config})
span.set_tag('sampling_rate_updated', True)
Expand Down

0 comments on commit e5b6d72

Please sign in to comment.