Skip to content

Commit 99f3fb5

Browse files
committed
add adhoc_meta_update
Signed-off-by: hwassman <[email protected]>
1 parent d75c737 commit 99f3fb5

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@
4141
from collections import defaultdict
4242
from timeit import default_timer as timer
4343
from time import sleep
44+
from threading import Thread
4445

4546

47+
local_cache = []
48+
4649
class MetadataHandler(metaclass=Singleton):
4750

4851
def __init__(self, **kwargs):
@@ -153,6 +156,7 @@ def __getSuggest(self, params):
153156

154157
if params.get('q'):
155158
searchStr = params['q'].strip()
159+
self.logger.trace(f'Suggest for {searchStr} called')
156160
# if '*' and tagv, then it denotes a grouping key value: do not process
157161
if not (searchStr == '*' and params['type'] == 'tagv'):
158162
# Since grafana sends the candidate string quickly, one character at a time, it
@@ -194,6 +198,7 @@ def __getLookup(self, params):
194198
res = LookupResultObj(searchMetric)
195199
res.parseResultTags(identifiersMap)
196200
res.parseRequestTags(filterBy)
201+
self.logger.trace(f'lookUp result {res}')
197202
resp = res.__dict__
198203

199204
except Exception as e:
@@ -545,6 +550,7 @@ def parseTags(self, logger, filtersMap, columnInfo):
545550
ident = [key.parent]
546551
ident.extend(key.identifier)
547552
logger.debug(MSG['ReceivAttrValues'].format('Single ts identifiers', ', '.join(ident)))
553+
found = False
548554
for filtersDict in filtersMap:
549555
if all((value in filtersDict.values()) for value in ident):
550556
logger.debug(MSG['ReceivAttrValues'].format('filtersKeys', ', '.join(filtersDict.keys())))
@@ -553,7 +559,20 @@ def parseTags(self, logger, filtersMap, columnInfo):
553559
else:
554560
for _key, _value in filtersDict.items():
555561
tagsDict[_key].add(_value)
562+
found = True
556563
break
564+
# detected zimon key, do we need refresh local TOPO?
565+
if not found:
566+
already_reported = False
567+
for cache_item in local_cache:
568+
if set(cache) == set(ident):
569+
logger.trace(MSG['NewKeyAlreadyReported'].format(ident))
570+
already_reported = True
571+
break
572+
if not already_reported:
573+
logger.debug(MSG['NewKeyDetected'].format(ident))
574+
local_cache.append(ident)
575+
Thread(name='AdHocMetaDataUpdate', target=refresh_metadata).start()
557576

558577
for _key, _values in tagsDict.items():
559578
if len(_values) > 1:

0 commit comments

Comments
 (0)