From 5ba1f0f2f59b943884ae61f7ca6c074b6d1717a3 Mon Sep 17 00:00:00 2001 From: Mayco Lacerda Date: Thu, 27 Jul 2023 13:17:26 -0300 Subject: [PATCH 1/5] fix: fixing bug related to reading enviroment viriables --- services/rulles.go | 1 - 1 file changed, 1 deletion(-) diff --git a/services/rulles.go b/services/rulles.go index 417e53e..568a4e5 100644 --- a/services/rulles.go +++ b/services/rulles.go @@ -217,7 +217,6 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour) } - existing.ExpirationDate = time.Now().Add(time.Minute * 5) return existing.KnowledgeBase, nil } From 1228c6657a40596a595f88229ce1765ba2a2f516 Mon Sep 17 00:00:00 2001 From: Mayco Lacerda Date: Thu, 3 Aug 2023 10:43:49 -0300 Subject: [PATCH 2/5] Fix: added logs for troubleshooting purposes --- .gitignore | 1 + config/config.go | 2 +- services/rulles.go | 26 +++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b6ef7c2..437ea1f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ example.json *.out vendor api.http +listChangedFilesPathFromGit.sh \ No newline at end of file diff --git a/config/config.go b/config/config.go index 8e3fe4a..4088ec5 100644 --- a/config/config.go +++ b/config/config.go @@ -79,6 +79,7 @@ func LoadConfig() (err error) { if err2, ok := err.(*os.PathError); !ok { err = err2 log.Errorf("Error on Load Config: %v", err) + return } } @@ -102,7 +103,6 @@ func LoadConfig() (err error) { config.ResolverBridgeHeaders.Set(entries[0], entries[1]) } } - return } diff --git a/services/rulles.go b/services/rulles.go index 568a4e5..2e2bc69 100644 --- a/services/rulles.go +++ b/services/rulles.go @@ -175,19 +175,34 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K existing := s.knowledgeBaseCache[info] if existing == nil { - + var ExpirationDate time.Time + + switch s.expirationType { + case "seconds": + log.Printf("setting expiration time to %v seconds...", s.expirationMultiplier) + ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Second) + case "minutes": + log.Printf("setting expiration time to %v minutes...", s.expirationMultiplier) + ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Minute) + case "hours": + log.Printf("setting expiration time to %v hours...", s.expirationMultiplier) + ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour) + } existing = &knowledgeBaseCache{ KnowledgeBase: s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version), - ExpirationDate: time.Now().Add(time.Minute * 5), + ExpirationDate: ExpirationDate, } s.knowledgeBaseCache[info] = existing } if existing.KnowledgeBase.Version != "latest" && len(existing.KnowledgeBase.RuleEntries) > 0 { + log.Printf("KnowledgeBase found. Version not set as latest.KnoledgeBase is not empty. Returning...") + log.Printf("Version: %v", existing.KnowledgeBase.Version) return existing.KnowledgeBase, nil } if existing.ExpirationDate.After(time.Now()) && len(existing.KnowledgeBase.RuleEntries) > 0 { + log.Printf("KnowledgeBase found. Expiration date not reached.KnoledgeBase not empty. Returning...") return existing.KnowledgeBase, nil } @@ -206,14 +221,19 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K } loadMutex.Unlock() - + log.Printf("KnowledgeBase loaded, updating cache, please wait...") + log.Printf("expirationType: %v", s.expirationType) + log.Printf("expirationMultiplier: %v", s.expirationMultiplier) existing.KnowledgeBase = s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version) switch s.expirationType { case "seconds": + log.Printf("setting expiration time to %v seconds...", s.expirationMultiplier) existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Second) case "minutes": + log.Printf("setting expiration time to %v minutes...", s.expirationMultiplier) existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Minute) case "hours": + log.Printf("setting expiration time to %v hours...", s.expirationMultiplier) existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour) } From 03c8b3ced22b233812ea22589ce33a8cc20eb07f Mon Sep 17 00:00:00 2001 From: Mayco Lacerda Date: Thu, 3 Aug 2023 11:41:21 -0300 Subject: [PATCH 3/5] fix: solved a problem related to a request made wih the version defined as 'latest' --- services/rulles.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/rulles.go b/services/rulles.go index 2e2bc69..9a3ee1f 100644 --- a/services/rulles.go +++ b/services/rulles.go @@ -193,7 +193,7 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K ExpirationDate: ExpirationDate, } s.knowledgeBaseCache[info] = existing - + return existing.KnowledgeBase, nil } if existing.KnowledgeBase.Version != "latest" && len(existing.KnowledgeBase.RuleEntries) > 0 { log.Printf("KnowledgeBase found. Version not set as latest.KnoledgeBase is not empty. Returning...") @@ -206,8 +206,16 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K return existing.KnowledgeBase, nil } + log.Printf("KnowledgeBase found but expired.") + loadMutex.Lock() - s.knowledgeLibrary.RemoveRuleEntry(existing.KnowledgeBase.Name, knowledgeBaseName, version) + + for key, element := range existing.KnowledgeBase.RuleEntries { + + log.Printf("Removing rule %v %v", key, element) + s.knowledgeLibrary.RemoveRuleEntry(key, knowledgeBaseName, version) + } + err := s.LoadRemoteGRL(knowledgeBaseName, version) if err != nil { log.Errorf("Erro on load: %v", err) @@ -224,6 +232,7 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K log.Printf("KnowledgeBase loaded, updating cache, please wait...") log.Printf("expirationType: %v", s.expirationType) log.Printf("expirationMultiplier: %v", s.expirationMultiplier) + existing.KnowledgeBase = s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version) switch s.expirationType { case "seconds": From 731e517e4b48be5b823822a19379aa31da22b69e Mon Sep 17 00:00:00 2001 From: Mayco Lacerda Date: Thu, 3 Aug 2023 14:30:19 -0300 Subject: [PATCH 4/5] fix: deleting comments used for troubleshooting purposes --- .gitignore | 2 -- api.http | 6 ++++++ services/rulles.go | 11 ----------- 3 files changed, 6 insertions(+), 13 deletions(-) create mode 100644 api.http diff --git a/.gitignore b/.gitignore index 437ea1f..05bd204 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,3 @@ example.json *.env *.out vendor -api.http -listChangedFilesPathFromGit.sh \ No newline at end of file diff --git a/api.http b/api.http new file mode 100644 index 0000000..59b93ef --- /dev/null +++ b/api.http @@ -0,0 +1,6 @@ +POST http://localhost:8000/api/v1/eval/jamie-menu-64623317-d00c-4508-8db3-613d1ed24638/ +Content-Type: application/json + +{ + "idade":13 +} \ No newline at end of file diff --git a/services/rulles.go b/services/rulles.go index 9a3ee1f..516e939 100644 --- a/services/rulles.go +++ b/services/rulles.go @@ -179,13 +179,10 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K switch s.expirationType { case "seconds": - log.Printf("setting expiration time to %v seconds...", s.expirationMultiplier) ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Second) case "minutes": - log.Printf("setting expiration time to %v minutes...", s.expirationMultiplier) ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Minute) case "hours": - log.Printf("setting expiration time to %v hours...", s.expirationMultiplier) ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour) } existing = &knowledgeBaseCache{ @@ -196,18 +193,13 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K return existing.KnowledgeBase, nil } if existing.KnowledgeBase.Version != "latest" && len(existing.KnowledgeBase.RuleEntries) > 0 { - log.Printf("KnowledgeBase found. Version not set as latest.KnoledgeBase is not empty. Returning...") - log.Printf("Version: %v", existing.KnowledgeBase.Version) return existing.KnowledgeBase, nil } if existing.ExpirationDate.After(time.Now()) && len(existing.KnowledgeBase.RuleEntries) > 0 { - log.Printf("KnowledgeBase found. Expiration date not reached.KnoledgeBase not empty. Returning...") return existing.KnowledgeBase, nil } - log.Printf("KnowledgeBase found but expired.") - loadMutex.Lock() for key, element := range existing.KnowledgeBase.RuleEntries { @@ -236,13 +228,10 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K existing.KnowledgeBase = s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version) switch s.expirationType { case "seconds": - log.Printf("setting expiration time to %v seconds...", s.expirationMultiplier) existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Second) case "minutes": - log.Printf("setting expiration time to %v minutes...", s.expirationMultiplier) existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Minute) case "hours": - log.Printf("setting expiration time to %v hours...", s.expirationMultiplier) existing.ExpirationDate = time.Now().Add(time.Duration(s.expirationMultiplier) * time.Hour) } From 7d477da34d1e89bf5a2cc6d4d6803fbda842dba0 Mon Sep 17 00:00:00 2001 From: Mayco Lacerda Date: Thu, 3 Aug 2023 16:18:41 -0300 Subject: [PATCH 5/5] fix: deleting comments used for troubleshooting purposes --- services/rulles.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/rulles.go b/services/rulles.go index 516e939..45bcfb1 100644 --- a/services/rulles.go +++ b/services/rulles.go @@ -202,9 +202,8 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K loadMutex.Lock() - for key, element := range existing.KnowledgeBase.RuleEntries { + for key := range existing.KnowledgeBase.RuleEntries { - log.Printf("Removing rule %v %v", key, element) s.knowledgeLibrary.RemoveRuleEntry(key, knowledgeBaseName, version) } @@ -221,9 +220,6 @@ func (s Eval) GetKnowledgeBase(knowledgeBaseName string, version string) (*ast.K } loadMutex.Unlock() - log.Printf("KnowledgeBase loaded, updating cache, please wait...") - log.Printf("expirationType: %v", s.expirationType) - log.Printf("expirationMultiplier: %v", s.expirationMultiplier) existing.KnowledgeBase = s.GetKnowledgeLibrary().GetKnowledgeBase(knowledgeBaseName, version) switch s.expirationType {