From 403d1e24716b3225d4bc7785606a89b3e327dbd1 Mon Sep 17 00:00:00 2001 From: ermisw Date: Tue, 9 May 2023 14:32:36 +0200 Subject: [PATCH] added simplified pattern --- KRParser/krparser.py | 9 +++++---- KRParser/patterns.py | 8 ++++---- tests/{TestStringMethods.py => test.py} | 24 +++--------------------- 3 files changed, 12 insertions(+), 29 deletions(-) rename tests/{TestStringMethods.py => test.py} (63%) diff --git a/KRParser/krparser.py b/KRParser/krparser.py index b634a6d..c708c9e 100644 --- a/KRParser/krparser.py +++ b/KRParser/krparser.py @@ -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): @@ -191,7 +191,7 @@ 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, + 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"]: @@ -258,8 +258,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 diff --git a/KRParser/patterns.py b/KRParser/patterns.py index ebd280b..3a9443c 100644 --- a/KRParser/patterns.py +++ b/KRParser/patterns.py @@ -81,16 +81,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 \ No newline at end of file diff --git a/tests/TestStringMethods.py b/tests/test.py similarity index 63% rename from tests/TestStringMethods.py rename to tests/test.py index 6fbfeac..88968a5 100644 --- a/tests/TestStringMethods.py +++ b/tests/test.py @@ -25,18 +25,11 @@ class TestStringMethods(unittest.TestCase): self.env_doc = yaml.safe_load(file) - def test_upper(self): - self.assertEqual('foo'.upper(), 'FOO') - - def test_isupper(self): - self.assertTrue('FOO'.isupper()) - self.assertFalse('Foo'.isupper()) - def test_simplifySLOs(self): 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/15c29ec3-71a7-3298-9e99-aad2e5bf347c" + api_url = DTURL+"/api/v2/slo/b2a300b5-5b1c-3ff8-8ee6-84e0ba071a90" headers = { 'Content-Type': 'application/json', @@ -45,22 +38,11 @@ class TestStringMethods(unittest.TestCase): result=get_request(api_url, headers, {}) + slo=result.json() krp = KRParser(options=KROption.RESOLVEKEYREQUETS | KROption.VALIDATE_HASDATA | KROption.RESOLVESERVICES, config={"threads":10,"serviceLookupParams":{"fields":"tags"},"extendResultObjects":{"env":"emea"}}, DTAPIURL=DTURL, DTAPIToken=DTTOKEN) - #df = pd.DataFrame.from_dict(result.json().items()) - #for index, row in pd.DataFrame(result.json().items()).iterrows(): - slo=result.json() - slo["env"]="emea" - - listSlo=[slo, slo] - krp.parse(listSlo) - - #krp.parseBySLO(0,slo) - #krp.parseBySLO_Threaded(0, ) - - #self.assertEqual(s.split(), ['hello', 'world']) - # check that s.split fails when the separator is not a strin + krp.parse(slo) if __name__ == '__main__': unittest.main() \ No newline at end of file