Skip to content
Snippets Groups Projects
Commit c5f10c39 authored by bravof's avatar bravof Committed by garciadeblas
Browse files

bugfix: prometheus config loop to avoid crashes during jobs collection changes listening


Change-Id: Ieb4e4caec3fe7f89f6bf0b4fc400ff0db88f3c4c
Signed-off-by: default avatarbravof <fbravo@whitestack.com>
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent 672bdb07
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ import aiohttp ...@@ -29,6 +29,7 @@ import aiohttp
import asyncio import asyncio
import copy import copy
import json import json
import time
from bson.json_util import dumps from bson.json_util import dumps
from bson import ObjectId from bson import ObjectId
...@@ -138,21 +139,32 @@ async def main(): ...@@ -138,21 +139,32 @@ async def main():
client = pymongo.MongoClient(mongodb_url) client = pymongo.MongoClient(mongodb_url)
print('Connected to MongoDB!') print('Connected to MongoDB!')
print('Refreshing prometheus config file for first time') try:
await main_task(client) print('Refreshing prometheus config file for first time')
#Needs mongodb in replica mode as this feature relies in OpLog
change_stream = client[target_database].prometheus_jobs.watch([{
'$match': {
#If you want to modify a particular job, delete and insert it again
'operationType': { '$in': ['insert', 'delete'] }
}
}])
#Single thread, no race conditions and ops are queued up in order
for change in change_stream:
print("Change detected, updating prometheus config")
await main_task(client) await main_task(client)
print() except Exception as error:
print("Error in first configuration attempt!")
print(error)
while(True):
try:
#Needs mongodb in replica mode as this feature relies in OpLog
change_stream = client[target_database].prometheus_jobs.watch([{
'$match': {
#If you want to modify a particular job, delete and insert it again
'operationType': { '$in': ['insert', 'delete'] }
}
}])
#Single thread, no race conditions and ops are queued up in order
print("Listening to changes in prometheus jobs collection")
for change in change_stream:
print("Change detected, updating prometheus config")
await main_task(client)
print()
except Exception as error:
print(error)
print("Detected failure while listening to prometheus jobs collection, retrying...")
time.sleep(5)
asyncio.run(main()) asyncio.run(main())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment