projects
/
osm
/
LCM.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix(sapd): sapd used to specify exposed connections at NS level. Fixes Bug 1321
[osm/LCM.git]
/
osm_lcm
/
prometheus.py
diff --git
a/osm_lcm/prometheus.py
b/osm_lcm/prometheus.py
index
1a4793f
..
5afa496
100644
(file)
--- a/
osm_lcm/prometheus.py
+++ b/
osm_lcm/prometheus.py
@@
-24,6
+24,7
@@
import yaml
import os
from osm_lcm.lcm_utils import LcmException
from osm_common.dbbase import DbException
import os
from osm_lcm.lcm_utils import LcmException
from osm_common.dbbase import DbException
+from osm_lcm.data_utils.database.database import Database
from jinja2 import Template, TemplateError, TemplateNotFound, TemplateSyntaxError
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
from jinja2 import Template, TemplateError, TemplateNotFound, TemplateSyntaxError
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
@@
-53,9
+54,9
@@
class Prometheus:
PROMETHEUS_LOCKED_TIME = 120
PROMETHEUS_LOCKED_TIME = 120
- def __init__(self, config, worker_id,
db,
loop, logger=None):
+ def __init__(self, config, worker_id, loop, logger=None):
self.worker_id = worker_id
self.worker_id = worker_id
- self.db = db
+ self.db =
Database().instance.
db
self.loop = loop
self.logger = logger or logging.getLogger("lcm.prometheus")
self.server = config["uri"]
self.loop = loop
self.logger = logger or logging.getLogger("lcm.prometheus")
self.server = config["uri"]
@@
-101,10
+102,10
@@
class Prometheus:
:param remove_jobs: list with jobs to remove [job_id_1, job_id_2]
:return: result. If false prometheus denies this configuration. Exception on error
"""
:param remove_jobs: list with jobs to remove [job_id_1, job_id_2]
:return: result. If false prometheus denies this configuration. Exception on error
"""
- for retry in range(
4
):
+ for retry in range(
20
):
result = True
if retry: # first time do not wait
result = True
if retry: # first time do not wait
- await asyncio.sleep(
self.PROMETHEUS_LOCKED_TIME / 2
, loop=self.loop)
+ await asyncio.sleep(
4 + retry
, loop=self.loop)
# lock database
now = time()
# lock database
now = time()
@@
-132,9
+133,10
@@
class Prometheus:
for job_id in remove_jobs:
prometheus_data["scrape_configs"].pop(job_id, None)
pull_dict = {"scrape_configs." + job_id: None for job_id in remove_jobs}
for job_id in remove_jobs:
prometheus_data["scrape_configs"].pop(job_id, None)
pull_dict = {"scrape_configs." + job_id: None for job_id in remove_jobs}
- self.logger.debug(". ".join(log_text_list))
+ self.logger.debug("
Updating. " + "
. ".join(log_text_list))
if not await self.send_data(prometheus_data):
if not await self.send_data(prometheus_data):
+ self.logger.error("Cannot update add_jobs: {}. remove_jobs: {}".format(add_jobs, remove_jobs))
push_dict = pull_dict = None
result = False
push_dict = pull_dict = None
result = False
@@
-190,7
+192,7
@@
class Prometheus:
restore_backup = False
return True
except Exception as e:
restore_backup = False
return True
except Exception as e:
- self.logger.error("Error updating
prometheus
configuration url={}: {}".format(self.server, e))
+ self.logger.error("Error updating configuration url={}: {}".format(self.server, e))
return False
finally:
if restore_backup:
return False
finally:
if restore_backup:
@@
-206,9
+208,14
@@
class Prometheus:
current_config_yaml = yaml.safe_load(current_config['data']['yaml'])
current_jobs = [j["job_name"] for j in current_config_yaml["scrape_configs"]]
expected_jobs = [j["job_name"] for j in expected_config["scrape_configs"]]
current_config_yaml = yaml.safe_load(current_config['data']['yaml'])
current_jobs = [j["job_name"] for j in current_config_yaml["scrape_configs"]]
expected_jobs = [j["job_name"] for j in expected_config["scrape_configs"]]
- return current_jobs == expected_jobs
+ if current_jobs == expected_jobs:
+ return True
+ else:
+ self.logger.error("Not all jobs have been loaded. Target jobs: {} Loaded jobs: {}".format(
+ expected_jobs, current_jobs))
+ return False
except Exception as e:
except Exception as e:
- self.logger.error("Invalid obtained
prometheus status
. Error: '{}'. Obtained data: '{}'".format(
+ self.logger.error("Invalid obtained
status from server
. Error: '{}'. Obtained data: '{}'".format(
e, current_config))
# if format is not understood, cannot be compared, assume it is ok
return True
e, current_config))
# if format is not understood, cannot be compared, assume it is ok
return True