Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enrich] Avoid "-- UNDEFINED --" values #1165

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions grimoire_elk/enriched/enrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,16 @@ def get_sh_item_from_identity_cache(self, identity_tuple, backend_name):
email=iden['email'],
name=iden['name'],
username=iden['username'])
iden['uuid'] = identity_id
iden['id'] = identity_id
iden['enrollments'] = []

try:
individual = self.get_entity(identity_id)
if not individual:
msg = "Individual not found given the following identity: {}".format(identity_id)
logger.debug(msg)
return sh_item
return iden

for indv_identity in individual['identities']:
if indv_identity['uuid'] == identity_id:
Expand All @@ -842,10 +845,10 @@ def get_sh_item_from_identity_cache(self, identity_tuple, backend_name):
msg = "Identity {} not found in individual returned by SortingHat.".format(identity)
logger.error(msg)
return sh_item
except SortingHatClientError:
except SortingHatClientError as e:
msg = "None Identity found {}, identity: {}".format(backend_name, identity)
logger.debug(msg)
return sh_item
logger.error(msg)
raise SortingHatClientError(e)
except UnicodeEncodeError:
msg = "UnicodeEncodeError {}, identity: {}".format(backend_name, identity)
logger.error(msg)
Expand Down Expand Up @@ -1054,7 +1057,6 @@ def get_item_sh(self, item, roles=None, date_field=None):
sh_fields = self.get_item_sh_fields(identity, item_date, rol=rol)
else:
sh_fields = self.get_item_no_sh_fields(identity, rol)

eitem_sh.update(sh_fields)

if not eitem_sh[rol + '_org_name']:
Expand Down
4 changes: 4 additions & 0 deletions grimoire_elk/enriched/sortinghat_gelk.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ def add_identities(cls, db, identities, backend):
except SortingHatClientError as ex:
for error in ex.errors:
msg = error['message']
status = error.get('status', None)
if 'already exists' in msg:
logger.debug("[sortinghat] {}".format(msg))
elif status and status == 502:
raise SortingHatClientError(ex)
else:
logger.warning("[sortinghat] {}".format(msg))

Expand Down Expand Up @@ -361,6 +364,7 @@ def get_entity(cls, db, id):
entity = result['data']['individuals']['entities'][0]
except SortingHatClientError as e:
logger.error("[sortinghat] Error get entities {}: {}".format(id, e.errors[0]['message']))
raise SortingHatClientError(e)
return entity

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions releases/unreleased/avoid-undefined-values-in-author-fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Avoid UNDEFINED values in author fields
category: fixed
author: Quan Zhou <[email protected]>
issue: null
notes: >
Avoid `-- UNDEFINED --` values for all SortingHat fields when
Mordred loses connection to the SortingHat server during the
enrichment or autorefresh execution. It will keep the values
of the `name`, `email`, `id` and `uuid` fields.
2 changes: 1 addition & 1 deletion tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def test_onion_study(self):
url = self.es_con + "/test_git_onion/_search?size=50"
response = requests.get(url, verify=False).json()
hits = response['hits']['hits']
self.assertEqual(len(hits), 16)
self.assertEqual(len(hits), 28)
for hit in hits:
source = hit['_source']
self.assertIn('timeframe', source)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test_onion_study(self):
url = self.es_con + "/test_github_issues_onion/_search?size=20"
response = requests.get(url, verify=False).json()
hits = response['hits']['hits']
self.assertEqual(len(hits), 10)
self.assertEqual(len(hits), 12)
for hit in hits:
source = hit['_source']
self.assertIn('timeframe', source)
Expand All @@ -426,7 +426,7 @@ def test_onion_study(self):
url = self.es_con + "/test_github_prs_onion/_search?size=20"
response = requests.get(url, verify=False).json()
hits = response['hits']['hits']
self.assertEqual(len(hits), 10)
self.assertEqual(len(hits), 12)
for hit in hits:
source = hit['_source']
self.assertIn('timeframe', source)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_onion_study(self):
url = self.es_con + "/test_gitlab_onion/_search?size=50"
response = requests.get(url, verify=False).json()
hits = response['hits']['hits']
self.assertEqual(len(hits), 10)
self.assertEqual(len(hits), 22)
for hit in hits:
source = hit['_source']
self.assertIn('timeframe', source)
Expand Down