Skip to content

Commit 6be1f6a

Browse files
authored
Merge pull request #115 from Helene/adhoc_reresh
Trigger adhoc metadata refresh
2 parents 6952bc9 + 365e66b commit 6be1f6a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

source/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@
6161
'StartWatchingFiles': 'Start watching file changes in the path {}.',
6262
'StopWatchingFiles': 'Stop watching file changes in the path {}.',
6363
'PathNoCfgFiles': 'The path does not contain any configuration files.',
64+
'NewKeyDetected': 'Detected not known single ts identifiers {}.',
65+
'NewKeyAlreadyReported': 'Single ts identifiers {} already reported as not known.',
6466
'UnhandledError': 'Unhandled error: {}'
6567
}

source/watcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def start_watch(self):
4646
""" Function to start watch in a thread"""
4747
self.running = True
4848
if not self.thread:
49-
self.thread = Thread(name='ConfigWatchThread', target=self.watch)
49+
self.thread = Thread(name='ConfigWatcher', target=self.watch)
5050
self.thread.start()
5151
cherrypy.engine.log('Started custom thread %r.' % self.thread.name)
5252
self.logger.debug(MSG['StartWatchingFiles'].format(self.paths))

source/zimonGrafanaIntf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
from collections import defaultdict
4242
from timeit import default_timer as timer
4343
from time import sleep
44+
from threading import Thread
45+
46+
47+
local_cache = []
4448

4549

4650
class MetadataHandler(metaclass=Singleton):
@@ -153,6 +157,7 @@ def __getSuggest(self, params):
153157

154158
if params.get('q'):
155159
searchStr = params['q'].strip()
160+
self.logger.trace(f'Suggest for {searchStr} called')
156161
# if '*' and tagv, then it denotes a grouping key value: do not process
157162
if not (searchStr == '*' and params['type'] == 'tagv'):
158163
# Since grafana sends the candidate string quickly, one character at a time, it
@@ -194,6 +199,7 @@ def __getLookup(self, params):
194199
res = LookupResultObj(searchMetric)
195200
res.parseResultTags(identifiersMap)
196201
res.parseRequestTags(filterBy)
202+
self.logger.trace(f'lookUp result {res}')
197203
resp = res.__dict__
198204

199205
except Exception as e:
@@ -545,6 +551,7 @@ def parseTags(self, logger, filtersMap, columnInfo):
545551
ident = [key.parent]
546552
ident.extend(key.identifier)
547553
logger.debug(MSG['ReceivAttrValues'].format('Single ts identifiers', ', '.join(ident)))
554+
found = False
548555
for filtersDict in filtersMap:
549556
if all((value in filtersDict.values()) for value in ident):
550557
logger.debug(MSG['ReceivAttrValues'].format('filtersKeys', ', '.join(filtersDict.keys())))
@@ -553,7 +560,20 @@ def parseTags(self, logger, filtersMap, columnInfo):
553560
else:
554561
for _key, _value in filtersDict.items():
555562
tagsDict[_key].add(_value)
563+
found = True
556564
break
565+
# detected zimon key, do we need refresh local TOPO?
566+
if not found:
567+
already_reported = False
568+
for cache_item in local_cache:
569+
if set(cache_item) == set(ident):
570+
logger.trace(MSG['NewKeyAlreadyReported'].format(ident))
571+
already_reported = True
572+
break
573+
if not already_reported:
574+
logger.debug(MSG['NewKeyDetected'].format(ident))
575+
local_cache.append(ident)
576+
Thread(name='AdHocMetaDataUpdate', target=refresh_metadata).start()
557577

558578
for _key, _values in tagsDict.items():
559579
if len(_values) > 1:

0 commit comments

Comments
 (0)