fixed patterns & all KEyrequests for slos
parent
403d1e2471
commit
6e39e26582
|
|
@ -131,8 +131,6 @@ class KR:
|
|||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
def checkKeyRequestsHasData(self):
|
||||
|
|
@ -144,6 +142,12 @@ class KR:
|
|||
for s in listServices:
|
||||
if s["entityId"] not in listOfServiceIds:
|
||||
self.services.append(s)
|
||||
|
||||
# def addKeyRequest(self, data):
|
||||
# if type(data) == list:
|
||||
# for m in data:
|
||||
# self.keyRequests.append({"displayName":m["["displayName"]"], "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""})
|
||||
|
||||
|
||||
def __init__(self,
|
||||
metadata,
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@ class KRParser:
|
|||
|
||||
if len(entities)>0:
|
||||
services[gid]=entities[0]
|
||||
|
||||
|
||||
|
||||
|
||||
def resolveKeyRequests(self,kr, DTAPIURL, DTAPIToken, options):
|
||||
DTAPIURL = DTAPIURL + "/api/v2/entities"
|
||||
|
||||
|
|
@ -120,46 +122,148 @@ class KRParser:
|
|||
'Authorization': 'Api-Token ' + DTAPIToken
|
||||
}
|
||||
|
||||
|
||||
for gid, k in enumerate(kr.keyRequests):
|
||||
try:
|
||||
query="type(service_method)"
|
||||
group=kr.matchedGroups[k["groupId"]]
|
||||
|
||||
if len(group["services"])> 0:
|
||||
if group["services"][0].startswith("SERVICE-"):
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
else:
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
if k["comparer"]=="entityId":
|
||||
query+=",entityId("+k["entityId"]+")"
|
||||
else:
|
||||
query+=",entityName.in(\""+k["displayName"]+"\")"
|
||||
tmp_KR=[]
|
||||
for gid, group in enumerate(kr.matchedGroups):
|
||||
#try:
|
||||
for k in group["methods"]:
|
||||
|
||||
|
||||
#tmp_kr={"displayName":None, "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}
|
||||
|
||||
params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
response = helper.get_request(DTAPIURL, headers, params)
|
||||
entities = (response.json())['entities']
|
||||
|
||||
|
||||
if len(entities)> 0:
|
||||
kr.keyRequests[gid]["found"]=True
|
||||
kr.keyRequests[gid]['foundCount']=len(entities)
|
||||
kr.keyRequests[gid]["displayName"]=entities[0]["displayName"]
|
||||
kr.keyRequests[gid]["entityId"]=entities[0]["entityId"]
|
||||
query="type(service_method)"
|
||||
|
||||
if "isServiceMethodOfService" in entities[0]["fromRelationships"]:
|
||||
kr.keyRequests[gid]["services"]=entities[0]["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
if options and KROption.RESOLVESERVICES in options and len( kr.keyRequests[gid]["services"])>0:
|
||||
self.resolveServices(kr.keyRequests[gid]["services"], DTAPIURL, DTAPIToken)
|
||||
if len(group["services"])> 0:
|
||||
|
||||
if group["services"][0].startswith("SERVICE-"):
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
else:
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
except Exception as err:
|
||||
kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
if k.startswith("SERVICE_METHOD-"):
|
||||
query+=",entityId("+k+")"
|
||||
else:
|
||||
query+=",entityName.in(\""+k+"\")"
|
||||
|
||||
params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
response = helper.get_request(DTAPIURL, headers, params)
|
||||
entities = (response.json())['entities']
|
||||
|
||||
if len(entities)> 0:
|
||||
for ent in entities:
|
||||
|
||||
tmp_kr={"displayName":ent["displayName"], "entityId":ent["entityId"], "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}
|
||||
|
||||
if "isServiceMethodOfService" in ent["fromRelationships"]:
|
||||
tmp_kr["services"]=ent["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
if options and KROption.RESOLVESERVICES in options and len(tmp_kr["services"])>0:
|
||||
self.resolveServices(tmp_kr["services"], DTAPIURL, DTAPIToken)
|
||||
|
||||
tmp_KR.append(tmp_kr)
|
||||
|
||||
else:
|
||||
if k.startswith('SERVICE_METHOD-'):
|
||||
tmp_kr=merge({"displayName": None,"comparer": "entityId", "entityId":k, "groupId":gid, "hasData":{},"count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
else:
|
||||
tmp_kr=merge({"displayName":k,"comparer": "displayName", "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
|
||||
tmp_KR.append(tmp_kr)
|
||||
|
||||
|
||||
return tmp_KR
|
||||
# except Exception as err:
|
||||
# kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
|
||||
# for gid, k in enumerate(kr.keyRequests):
|
||||
# try:
|
||||
# query="type(service_method)"
|
||||
# group=kr.matchedGroups[k["groupId"]]
|
||||
|
||||
# if len(group["services"])> 0:
|
||||
# if group["services"][0].startswith("SERVICE-"):
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
# else:
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
# if k["comparer"]=="entityId":
|
||||
# query+=",entityId("+k["entityId"]+")"
|
||||
# else:
|
||||
# query+=",entityName.in(\""+k["displayName"]+"\")"
|
||||
|
||||
# params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
# response = helper.get_request(DTAPIURL, headers, params)
|
||||
# entities = (response.json())['entities']
|
||||
|
||||
|
||||
# if len(entities)> 0:
|
||||
|
||||
# kr.keyRequests[gid]["found"]=True
|
||||
# kr.keyRequests[gid]['foundCount']=len(entities)
|
||||
# kr.keyRequests[gid]["displayName"]=entities[0]["displayName"]
|
||||
# kr.keyRequests[gid]["entityId"]=entities[0]["entityId"]
|
||||
|
||||
# if "isServiceMethodOfService" in entities[0]["fromRelationships"]:
|
||||
# kr.keyRequests[gid]["services"]=entities[0]["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
# if options and KROption.RESOLVESERVICES in options and len( kr.keyRequests[gid]["services"])>0:
|
||||
# self.resolveServices(kr.keyRequests[gid]["services"], DTAPIURL, DTAPIToken)
|
||||
|
||||
# except Exception as err:
|
||||
# kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
|
||||
|
||||
|
||||
#kr.mergeServices(entities)
|
||||
#kr.mergeServices(entities)
|
||||
|
||||
# def resolveKeyRequests(self,kr, DTAPIURL, DTAPIToken, options):
|
||||
# DTAPIURL = DTAPIURL + "/api/v2/entities"
|
||||
|
||||
# headers = {
|
||||
# 'Content-Type': 'application/json',
|
||||
# 'Authorization': 'Api-Token ' + DTAPIToken
|
||||
# }
|
||||
|
||||
|
||||
# for gid, k in enumerate(kr.keyRequests):
|
||||
# try:
|
||||
# query="type(service_method)"
|
||||
# group=kr.matchedGroups[k["groupId"]]
|
||||
|
||||
# if len(group["services"])> 0:
|
||||
# if group["services"][0].startswith("SERVICE-"):
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
# else:
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
# if k["comparer"]=="entityId":
|
||||
# query+=",entityId("+k["entityId"]+")"
|
||||
# else:
|
||||
# query+=",entityName.in(\""+k["displayName"]+"\")"
|
||||
|
||||
# params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
# response = helper.get_request(DTAPIURL, headers, params)
|
||||
# entities = (response.json())['entities']
|
||||
|
||||
|
||||
# if len(entities)> 0:
|
||||
|
||||
# kr.keyRequests[gid]["found"]=True
|
||||
# kr.keyRequests[gid]['foundCount']=len(entities)
|
||||
# kr.keyRequests[gid]["displayName"]=entities[0]["displayName"]
|
||||
# kr.keyRequests[gid]["entityId"]=entities[0]["entityId"]
|
||||
|
||||
# if "isServiceMethodOfService" in entities[0]["fromRelationships"]:
|
||||
# kr.keyRequests[gid]["services"]=entities[0]["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
# if options and KROption.RESOLVESERVICES in options and len( kr.keyRequests[gid]["services"])>0:
|
||||
# self.resolveServices(kr.keyRequests[gid]["services"], DTAPIURL, DTAPIToken)
|
||||
|
||||
# except Exception as err:
|
||||
# kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
|
||||
|
||||
|
||||
# #kr.mergeServices(entities)
|
||||
|
||||
|
||||
def getKeyRequestsByServices(self, services):
|
||||
|
|
@ -176,7 +280,7 @@ class KRParser:
|
|||
else:
|
||||
query="type(service_method),fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(services)+"\"))"
|
||||
|
||||
params={"entitySelector": query}
|
||||
params={"entitySelector": query,"from":"now-1y"}
|
||||
response = helper.get_request(DTAPIURL, headers, params)
|
||||
entities = (response.json())['entities']
|
||||
|
||||
|
|
@ -191,20 +295,21 @@ class KRParser:
|
|||
tmp_methods=self.getKeyRequestsByServices(group["services"])
|
||||
|
||||
for m in tmp_methods:
|
||||
tmp=merge({"displayName": None,"comparer": "entityId", "entityId":m["entityId"], "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""},self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
kr.keyRequests.append(tmp)
|
||||
group["methods"].append(m["entityId"])
|
||||
# tmp=merge({"displayName": None,"comparer": "entityId", "entityId":m["entityId"], "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""},self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
# kr.keyRequests.append(tmp)
|
||||
|
||||
for method in group["methods"]:
|
||||
if method.startswith('SERVICE_METHOD-'):
|
||||
tmp=merge({"displayName": None,"comparer": "entityId", "entityId":method, "groupId":gid, "hasData":{},"count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
else:
|
||||
tmp=merge({"displayName":method,"comparer": "displayName", "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
# for method in group["methods"]:
|
||||
# if method.startswith('SERVICE_METHOD-'):
|
||||
# tmp=merge({"displayName": None,"comparer": "entityId", "entityId":method, "groupId":gid, "hasData":{},"count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
# else:
|
||||
# tmp=merge({"displayName":method,"comparer": "displayName", "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
|
||||
kr.keyRequests.append(tmp)
|
||||
# kr.keyRequests.append(tmp)
|
||||
|
||||
|
||||
|
||||
self.resolveKeyRequests(kr,self.DTAPIURL, self.DTAPIToken, self.options)
|
||||
kr.keyRequests=self.resolveKeyRequests(kr,self.DTAPIURL, self.DTAPIToken, self.options)
|
||||
|
||||
if self.options:
|
||||
|
||||
|
|
|
|||
|
|
@ -63,12 +63,13 @@ class Pattern4:
|
|||
|
||||
def parseServicesAndMethods(self, metricExpression):
|
||||
metricExpression=re.sub(r'~([A-Z0-9\:\<\>\_\$\.\s\-\,\(\),\[\]\\\\/*]*)~', lambda m: str(urllib.parse.quote_plus(m.group(1))), metricExpression, flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
result = re.findall(r"type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*[entityName|entityId].*[equals|in]*\(([^\)]*)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
|
||||
#result = re.findall(r"type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*[entityName|entityId].*[equals|in]*\(([^\)]*)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
result = re.findall(r"type\(\"?service\"?\),[entityName|entityId]*[\.]*[equals|in|contains]*\(([^\)]*)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
|
||||
groups=[]
|
||||
if result:
|
||||
for r in result:
|
||||
if not r:
|
||||
#if not r:
|
||||
#methods=[s.strip() for s in r.split(",")]
|
||||
services=[s.strip() for s in urllib.parse.unquote_plus(r).split(",")]
|
||||
groups.append({"services":services, "methods":[]})
|
||||
|
|
|
|||
|
|
@ -131,8 +131,6 @@ class KR:
|
|||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
def checkKeyRequestsHasData(self):
|
||||
|
|
@ -144,6 +142,12 @@ class KR:
|
|||
for s in listServices:
|
||||
if s["entityId"] not in listOfServiceIds:
|
||||
self.services.append(s)
|
||||
|
||||
# def addKeyRequest(self, data):
|
||||
# if type(data) == list:
|
||||
# for m in data:
|
||||
# self.keyRequests.append({"displayName":m["["displayName"]"], "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""})
|
||||
|
||||
|
||||
def __init__(self,
|
||||
metadata,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class KROption(Flag):
|
|||
RESOLVESERVICES = auto()
|
||||
|
||||
class KRParser:
|
||||
patterns=[patterns.Pattern1(), patterns.Pattern2(), patterns.Pattern3(), patterns.Pattern5(), patterns.Pattern4() ]
|
||||
patterns=[patterns.Pattern1(), patterns.Pattern2(), patterns.Pattern3(), patterns.Pattern5(), patterns.Pattern4(), patterns.Pattern5()]
|
||||
lock = threading.Lock()
|
||||
|
||||
def normalize(self,x):
|
||||
|
|
@ -111,7 +111,9 @@ class KRParser:
|
|||
|
||||
if len(entities)>0:
|
||||
services[gid]=entities[0]
|
||||
|
||||
|
||||
|
||||
|
||||
def resolveKeyRequests(self,kr, DTAPIURL, DTAPIToken, options):
|
||||
DTAPIURL = DTAPIURL + "/api/v2/entities"
|
||||
|
||||
|
|
@ -120,46 +122,148 @@ class KRParser:
|
|||
'Authorization': 'Api-Token ' + DTAPIToken
|
||||
}
|
||||
|
||||
|
||||
for gid, k in enumerate(kr.keyRequests):
|
||||
try:
|
||||
query="type(service_method)"
|
||||
group=kr.matchedGroups[k["groupId"]]
|
||||
|
||||
if len(group["services"])> 0:
|
||||
if group["services"][0].startswith("SERVICE-"):
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
else:
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
if k["comparer"]=="entityId":
|
||||
query+=",entityId("+k["entityId"]+")"
|
||||
else:
|
||||
query+=",entityName.in(\""+k["displayName"]+"\")"
|
||||
tmp_KR=[]
|
||||
for gid, group in enumerate(kr.matchedGroups):
|
||||
#try:
|
||||
for k in group["methods"]:
|
||||
|
||||
|
||||
#tmp_kr={"displayName":None, "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}
|
||||
|
||||
params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
response = helper.get_request(DTAPIURL, headers, params)
|
||||
entities = (response.json())['entities']
|
||||
|
||||
|
||||
if len(entities)> 0:
|
||||
kr.keyRequests[gid]["found"]=True
|
||||
kr.keyRequests[gid]['foundCount']=len(entities)
|
||||
kr.keyRequests[gid]["displayName"]=entities[0]["displayName"]
|
||||
kr.keyRequests[gid]["entityId"]=entities[0]["entityId"]
|
||||
query="type(service_method)"
|
||||
|
||||
if "isServiceMethodOfService" in entities[0]["fromRelationships"]:
|
||||
kr.keyRequests[gid]["services"]=entities[0]["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
if options and KROption.RESOLVESERVICES in options and len( kr.keyRequests[gid]["services"])>0:
|
||||
self.resolveServices(kr.keyRequests[gid]["services"], DTAPIURL, DTAPIToken)
|
||||
if len(group["services"])> 0:
|
||||
|
||||
if group["services"][0].startswith("SERVICE-"):
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
else:
|
||||
query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
except Exception as err:
|
||||
kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
if k.startswith("SERVICE_METHOD-"):
|
||||
query+=",entityId("+k+")"
|
||||
else:
|
||||
query+=",entityName.in(\""+k+"\")"
|
||||
|
||||
params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
response = helper.get_request(DTAPIURL, headers, params)
|
||||
entities = (response.json())['entities']
|
||||
|
||||
if len(entities)> 0:
|
||||
for ent in entities:
|
||||
|
||||
tmp_kr={"displayName":ent["displayName"], "entityId":ent["entityId"], "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}
|
||||
|
||||
if "isServiceMethodOfService" in ent["fromRelationships"]:
|
||||
tmp_kr["services"]=ent["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
if options and KROption.RESOLVESERVICES in options and len(tmp_kr["services"])>0:
|
||||
self.resolveServices(tmp_kr["services"], DTAPIURL, DTAPIToken)
|
||||
|
||||
tmp_KR.append(tmp_kr)
|
||||
|
||||
else:
|
||||
if k.startswith('SERVICE_METHOD-'):
|
||||
tmp_kr=merge({"displayName": None,"comparer": "entityId", "entityId":k, "groupId":gid, "hasData":{},"count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
else:
|
||||
tmp_kr=merge({"displayName":k,"comparer": "displayName", "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
|
||||
tmp_KR.append(tmp_kr)
|
||||
|
||||
|
||||
return tmp_KR
|
||||
# except Exception as err:
|
||||
# kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
|
||||
# for gid, k in enumerate(kr.keyRequests):
|
||||
# try:
|
||||
# query="type(service_method)"
|
||||
# group=kr.matchedGroups[k["groupId"]]
|
||||
|
||||
# if len(group["services"])> 0:
|
||||
# if group["services"][0].startswith("SERVICE-"):
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
# else:
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
# if k["comparer"]=="entityId":
|
||||
# query+=",entityId("+k["entityId"]+")"
|
||||
# else:
|
||||
# query+=",entityName.in(\""+k["displayName"]+"\")"
|
||||
|
||||
# params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
# response = helper.get_request(DTAPIURL, headers, params)
|
||||
# entities = (response.json())['entities']
|
||||
|
||||
|
||||
# if len(entities)> 0:
|
||||
|
||||
# kr.keyRequests[gid]["found"]=True
|
||||
# kr.keyRequests[gid]['foundCount']=len(entities)
|
||||
# kr.keyRequests[gid]["displayName"]=entities[0]["displayName"]
|
||||
# kr.keyRequests[gid]["entityId"]=entities[0]["entityId"]
|
||||
|
||||
# if "isServiceMethodOfService" in entities[0]["fromRelationships"]:
|
||||
# kr.keyRequests[gid]["services"]=entities[0]["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
# if options and KROption.RESOLVESERVICES in options and len( kr.keyRequests[gid]["services"])>0:
|
||||
# self.resolveServices(kr.keyRequests[gid]["services"], DTAPIURL, DTAPIToken)
|
||||
|
||||
# except Exception as err:
|
||||
# kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
|
||||
|
||||
|
||||
#kr.mergeServices(entities)
|
||||
#kr.mergeServices(entities)
|
||||
|
||||
# def resolveKeyRequests(self,kr, DTAPIURL, DTAPIToken, options):
|
||||
# DTAPIURL = DTAPIURL + "/api/v2/entities"
|
||||
|
||||
# headers = {
|
||||
# 'Content-Type': 'application/json',
|
||||
# 'Authorization': 'Api-Token ' + DTAPIToken
|
||||
# }
|
||||
|
||||
|
||||
# for gid, k in enumerate(kr.keyRequests):
|
||||
# try:
|
||||
# query="type(service_method)"
|
||||
# group=kr.matchedGroups[k["groupId"]]
|
||||
|
||||
# if len(group["services"])> 0:
|
||||
# if group["services"][0].startswith("SERVICE-"):
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityId(\""+'","'.join(group["services"])+"\"))"
|
||||
# else:
|
||||
# query+=",fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(group["services"])+"\"))"
|
||||
|
||||
# if k["comparer"]=="entityId":
|
||||
# query+=",entityId("+k["entityId"]+")"
|
||||
# else:
|
||||
# query+=",entityName.in(\""+k["displayName"]+"\")"
|
||||
|
||||
# params={"entitySelector": query, "from":"now-1y","fields": "fromRelationships"}
|
||||
# response = helper.get_request(DTAPIURL, headers, params)
|
||||
# entities = (response.json())['entities']
|
||||
|
||||
|
||||
# if len(entities)> 0:
|
||||
|
||||
# kr.keyRequests[gid]["found"]=True
|
||||
# kr.keyRequests[gid]['foundCount']=len(entities)
|
||||
# kr.keyRequests[gid]["displayName"]=entities[0]["displayName"]
|
||||
# kr.keyRequests[gid]["entityId"]=entities[0]["entityId"]
|
||||
|
||||
# if "isServiceMethodOfService" in entities[0]["fromRelationships"]:
|
||||
# kr.keyRequests[gid]["services"]=entities[0]["fromRelationships"]["isServiceMethodOfService"]
|
||||
|
||||
# if options and KROption.RESOLVESERVICES in options and len( kr.keyRequests[gid]["services"])>0:
|
||||
# self.resolveServices(kr.keyRequests[gid]["services"], DTAPIURL, DTAPIToken)
|
||||
|
||||
# except Exception as err:
|
||||
# kr.keyRequests[gid]["exception"]="resolveKeyRequests failed: "+repr(err)
|
||||
|
||||
|
||||
|
||||
# #kr.mergeServices(entities)
|
||||
|
||||
|
||||
def getKeyRequestsByServices(self, services):
|
||||
|
|
@ -176,7 +280,7 @@ class KRParser:
|
|||
else:
|
||||
query="type(service_method),fromRelationship.isServiceMethodOfService(type(\"SERVICE\"),entityName.in(\""+'","'.join(services)+"\"))"
|
||||
|
||||
params={"entitySelector": query}
|
||||
params={"entitySelector": query,"from":"now-1y"}
|
||||
response = helper.get_request(DTAPIURL, headers, params)
|
||||
entities = (response.json())['entities']
|
||||
|
||||
|
|
@ -191,20 +295,21 @@ class KRParser:
|
|||
tmp_methods=self.getKeyRequestsByServices(group["services"])
|
||||
|
||||
for m in tmp_methods:
|
||||
tmp=merge({"displayName": None,"comparer": "entityId", "entityId":m["entityId"], "groupId":gid, "hasData":{}, "services":[], "found":False, "foundCount":0, "exception":""},self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
kr.keyRequests.append(tmp)
|
||||
group["methods"].append(m["entityId"])
|
||||
# tmp=merge({"displayName": None,"comparer": "entityId", "entityId":m["entityId"], "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""},self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
# kr.keyRequests.append(tmp)
|
||||
|
||||
for method in group["methods"]:
|
||||
if method.startswith('SERVICE_METHOD-'):
|
||||
tmp=merge({"displayName": None,"comparer": "entityId", "entityId":method, "groupId":gid, "hasData":{},"count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
else:
|
||||
tmp=merge({"displayName":method,"comparer": "displayName", "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
# for method in group["methods"]:
|
||||
# if method.startswith('SERVICE_METHOD-'):
|
||||
# tmp=merge({"displayName": None,"comparer": "entityId", "entityId":method, "groupId":gid, "hasData":{},"count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
# else:
|
||||
# tmp=merge({"displayName":method,"comparer": "displayName", "entityId":None, "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""}, self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||
|
||||
kr.keyRequests.append(tmp)
|
||||
# kr.keyRequests.append(tmp)
|
||||
|
||||
|
||||
|
||||
self.resolveKeyRequests(kr,self.DTAPIURL, self.DTAPIToken, self.options)
|
||||
kr.keyRequests=self.resolveKeyRequests(kr,self.DTAPIURL, self.DTAPIToken, self.options)
|
||||
|
||||
if self.options:
|
||||
|
||||
|
|
@ -258,8 +363,9 @@ class KRParser:
|
|||
executor.submit(self.parseBySLO, slo)
|
||||
|
||||
elif type(input) == dict:
|
||||
self.pbar = tqdm(total=1, desc=self.name)
|
||||
executor.submit(self.parseBySLO, row)
|
||||
#self.pbar = tqdm(total=1, desc=self.name)
|
||||
#executor.submit(self.parseBySLO, slo)
|
||||
self.parseBySLO(input)
|
||||
|
||||
|
||||
return self.krs
|
||||
|
|
|
|||
|
|
@ -63,12 +63,13 @@ class Pattern4:
|
|||
|
||||
def parseServicesAndMethods(self, metricExpression):
|
||||
metricExpression=re.sub(r'~([A-Z0-9\:\<\>\_\$\.\s\-\,\(\),\[\]\\\\/*]*)~', lambda m: str(urllib.parse.quote_plus(m.group(1))), metricExpression, flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
result = re.findall(r"type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*[entityName|entityId].*[equals|in]*\(([^\)]*)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
|
||||
#result = re.findall(r"type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*[entityName|entityId].*[equals|in]*\(([^\)]*)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
result = re.findall(r"type\(\"?service\"?\),[entityName|entityId]*[\.]*[equals|in|contains]*\(([^\)]*)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
|
||||
groups=[]
|
||||
if result:
|
||||
for r in result:
|
||||
if not r:
|
||||
#if not r:
|
||||
#methods=[s.strip() for s in r.split(",")]
|
||||
services=[s.strip() for s in urllib.parse.unquote_plus(r).split(",")]
|
||||
groups.append({"services":services, "methods":[]})
|
||||
|
|
@ -81,16 +82,16 @@ class Pattern5:
|
|||
|
||||
#Endoce
|
||||
metricExpression=re.sub(r'~([A-Z0-9\:\<\>\_\$\.\s\-\,\(\),\[\]\\\\/*]*)~', lambda m: str(urllib.parse.quote_plus(m.group(1))), metricExpression, flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
result = re.findall(r"type\(\"?service_method\"?\),fromRelationship\.isServiceMethodOfService\(type\(\"?service\"?\),entityName[\.]*[in]*\(([^\)]*)\)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
result = re.findall(r"type\(\"?service_method\"?\),fromRelationship\.isServiceMethodOfService\(type\(\"?service\"?\),entityName[\.]*[in]*\(([^\)]*)\)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
#type\(\"?service_method\"?\),fromRelationship\.isServiceMethodOfService\(type\(\"?service\"?\),entityName[\.]*[in]*\(([^\)]*)\)
|
||||
#result = re.findall(r"type\(\"?service_method\"?\)[\s\n\r]*,[\s\n\r]*fromRelationship[\s\n\r]*\.[\s\n\r]*isServiceMethodOfService[\s\n\r]*\([\s\n\r]*type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*entityName[\s\n\r]*[\.]*[\s\n\r]*[in]*[\s\n\r]*\([\s\n\r]*([^\)]*)\)[\s\n\r]*\)[\s\n\r]*\,[\s\n\r]*entityName[\s\n\r]*[\.]*[\s\n\r]*[in]*\([\s\n\r]*([^\)]*)[\s\n\r]*\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||
#services=[]
|
||||
#methods=[]
|
||||
groups=[]
|
||||
if result:
|
||||
for r in result:
|
||||
if not r:
|
||||
services=[s.strip() for s in urllib.parse.unquote_plus(r).split(",")]
|
||||
services=[s.strip() for s in urllib.parse.unquote_plus(r).split(",")]
|
||||
#methods=[s.strip() for s in urllib.parse.unquote_plus(r[1]).split(",")]
|
||||
groups.append({"services":services, "methods":[]})
|
||||
groups.append({"services":services, "methods":[]})
|
||||
#return services, methods
|
||||
return groups
|
||||
|
|
@ -29,7 +29,7 @@ class TestStringMethods(unittest.TestCase):
|
|||
DTURL=self.env_doc['euprod'][1]["env-url"]
|
||||
DTTOKEN = config(self.env_doc['euprod'][2].get('env-token-name'))
|
||||
|
||||
api_url = DTURL+"/api/v2/slo/b2a300b5-5b1c-3ff8-8ee6-84e0ba071a90"
|
||||
api_url = DTURL+"/api/v2/slo/cf5ba6e9-a56e-3ba8-99a9-b193dc68f410" #34bb71cf-30bc-3d2e-913f-389517699751"
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
|
|||
Loading…
Reference in New Issue