Skip to content

Commit

Permalink
[metadata] Remove metadata from empty enriched items
Browse files Browse the repository at this point in the history
This commit updates the enricher for
github and gitlab to prevent addition of
metadata fields to empty enriched items

Signed-off-by: Animesh Kumar <[email protected]>
  • Loading branch information
animeshk08 committed Apr 15, 2020
1 parent c6a65f3 commit 5e5a03c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions grimoire_elk/enriched/enrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def metadata(func):
@functools.wraps(func)
def decorator(self, *args, **kwargs):
eitem = func(self, *args, **kwargs)

if not eitem:
return eitem

metadata = {
'metadata__gelk_version': self.gelk_version,
'metadata__gelk_backend_name': self.__class__.__name__,
Expand Down Expand Up @@ -388,6 +392,8 @@ def enrich_items(self, ocean_backend, events=False):

if not events:
rich_item = self.get_rich_item(item)
if not rich_item:
continue
data_json = json.dumps(rich_item)
bulk_json += '{"index" : {"_id" : "%s" } }\n' % \
(item[self.get_field_unique_id()])
Expand Down
1 change: 1 addition & 0 deletions grimoire_elk/enriched/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def get_rich_item(self, item):
else:
logger.error("[github] rich item not defined for GitHub category {}".format(
item['category']))
return rich_item

self.add_repository_labels(rich_item)
self.add_metadata_filter_raw(rich_item)
Expand Down
3 changes: 3 additions & 0 deletions grimoire_elk/enriched/github2.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def get_rich_item(self, item):
else:
logger.error("[github] rich item not defined for GitHub category {}".format(
item['category']))
return rich_item

self.add_repository_labels(rich_item)
self.add_metadata_filter_raw(rich_item)
Expand Down Expand Up @@ -386,6 +387,8 @@ def enrich_items(self, ocean_backend):
eitems = []

eitem = self.get_rich_item(item)
if not eitem:
continue
items_to_enrich.append(eitem)
if item['category'] == ISSUE_TYPE:
eitems = self.enrich_issue(item, eitem)
Expand Down
3 changes: 2 additions & 1 deletion grimoire_elk/enriched/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def get_rich_item(self, item):
elif item['category'] == 'merge_request':
rich_item = self.__get_rich_merge(item)
else:
logger.error("[gerrit] rich item not defined for GitLab category {}".format(item['category']))
logger.error("[gitlab] rich item not defined for GitLab category {}".format(item['category']))
return rich_item

self.add_repository_labels(rich_item)
self.add_metadata_filter_raw(rich_item)
Expand Down

0 comments on commit 5e5a03c

Please sign in to comment.