Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Sonarqube #105

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add execution info in some log messages
diogoaihara committed Sep 1, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2e5d834e0dadf614e7281ae0d32d38c96b164f51
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ def write_transactional_info(self, rows, execution: Execution):

for results in partial_results:
for result in results:
logging.get_logger(_LOGGER_NAME).error(result['errors'])
logging.get_logger(_LOGGER_NAME).error(result['errors'], execution=execution)

def _get_now(self):
return datetime.now().timestamp()
1 change: 0 additions & 1 deletion megalista_dataflow/models/execution.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@

from enum import Enum
from typing import Dict, List, Union, Any
from config import logging
from apache_beam.typehints.decorators import with_output_types

class DestinationType(Enum):
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ def process(self, batch: Batch, **kwargs):
if delta_sec < min_duration_sec:
time.sleep(min_duration_sec - delta_sec)
logging.get_logger(LOGGER_NAME).info(
f"Successfully uploaded {len(success_elements)}/{len(batch.elements)} events.")
f"Successfully uploaded {len(success_elements)}/{len(batch.elements)} events.", execution=execution)

execution.successful_records = execution.successful_records + len(success_elements)
execution.unsuccessful_records = execution.unsuccessful_records + (len(batch.elements) - len(success_elements))
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ def _do_upload_data(
'conversions': conversions,
}

logger.info(f'Conversions: \n{conversions}')
logger.info(f'Conversions: \n{conversions}', execution=execution)

request = service.conversions().batchinsert(
profileId=campaign_manager_profile_id, body=request_body)
@@ -108,7 +108,7 @@ def _do_upload_data(
amount_of_failures = 0

if response['hasFailures']:
logger.error(f'Error(s) inserting conversions:\n{response}')
logger.error(f'Error(s) inserting conversions:\n{response}', execution=execution)
conversions_status = response['status']
error_messages = []

@@ -121,7 +121,7 @@ def _do_upload_data(
amount_of_success = amount_of_success + 1

final_error_message = 'Errors from API:\n{}'.format('\n'.join(error_messages))
logger.error(final_error_message)
logger.error(final_error_message, execution=execution)
self._add_error(execution, final_error_message)
else:
amount_of_success = len(rows)
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ def process(self, batch: Batch, **kwargs):
return [batch_with_successful_gclids]

def _do_upload(self, oc_service: Any, execution: Execution, conversion_resource_name: str, customer_id: str, rows: List[Dict[str, Union[str, Dict[str, str]]]]):
logging.get_logger(_DEFAULT_LOGGER).info(f'Uploading {len(rows)} offline conversions (calls) on {conversion_resource_name} to Google Ads.')
logging.get_logger(_DEFAULT_LOGGER).info(f'Uploading {len(rows)} offline conversions (calls) on {conversion_resource_name} to Google Ads.', execution=execution)
conversions = [{
'conversion_action': conversion_resource_name,
'caller_id': conversion['caller_id'],
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ def process(self, batch: Batch, **kwargs):
return [batch_with_successful_gclids]

def _do_upload(self, oc_service, execution, conversion_resource_name, customer_id, rows):
logging.get_logger(_DEFAULT_LOGGER).info(f'Uploading {len(rows)} offline conversions on {conversion_resource_name} to Google Ads.')
logging.get_logger(_DEFAULT_LOGGER).info(f'Uploading {len(rows)} offline conversions on {conversion_resource_name} to Google Ads.', execution=execution)
conversions = [{
'conversion_action': conversion_resource_name,
'conversion_date_time': utils.format_date(conversion['time']),
Original file line number Diff line number Diff line change
@@ -81,13 +81,13 @@ def do_process(self, batch: Batch):
response = requests.post(url,data=json.dumps(payload))
if response.status_code != 204:
error_message = f'Error calling GA4 MP {response.status_code}: {str(response.content)}'
logging.get_logger(LOGGER_NAME).error(error_message)
logging.get_logger(LOGGER_NAME).error(error_message, execution=execution)
self._add_error(execution, error_message)
else:
accepted_elements.append(row)

logging.get_logger(LOGGER_NAME).info(
f'Successfully uploaded {len(accepted_elements)}/{len(batch.elements)} events.')
f'Successfully uploaded {len(accepted_elements)}/{len(batch.elements)} events.', execution=execution)

execution.successful_records = execution.successful_records + len(accepted_elements)
execution.unsuccessful_records = execution.unsuccessful_records + (len(batch.elements) - len(accepted_elements))
Original file line number Diff line number Diff line change
@@ -84,11 +84,11 @@ def process(self, batch: Batch, **kwargs):
return [batch]
except Exception as e:
error_message = f'Error while delete GA Data Import files: {e}'
logging.get_logger(LOGGER_NAME).error(error_message)
logging.get_logger(LOGGER_NAME).error(error_message, execution=execution)
self._add_error(execution, error_message)
else:
error_message = f"{data_import_name} - data import not found, please configure it in Google Analytics"
logging.get_logger(LOGGER_NAME).error(error_message)
logging.get_logger(LOGGER_NAME).error(error_message, execution=execution)
self._add_error(execution, error_message)

@staticmethod
Original file line number Diff line number Diff line change
@@ -104,14 +104,14 @@ def _do_upload_data(self, execution, web_property_id, data_import_name, ga_accou
data_source_id, rows, web_property_id)
except Exception as e:
error_message = f'Error while uploading GA Data: {e}'
logging.get_logger(LOGGER_NAME).error(error_message)
logging.get_logger(LOGGER_NAME).error(error_message, execution=execution)
self._add_error(execution, error_message)
execution.unsuccessful_records = execution.unsuccessful_records + len(rows)
else:
execution.successful_records = execution.successful_records + len(rows)
else:
error_message = f'{data_import_name} - data import not found, please configure it in Google Analytics'
logging.get_logger(LOGGER_NAME).error(error_message)
logging.get_logger(LOGGER_NAME).error(error_message, execution=execution)
self._add_error(execution, error_message)
execution.unsuccessful_records = execution.unsuccessful_records + len(rows)

Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ def build_hit(self, batch: Batch, row: Dict[str, Any]) -> Dict[str, Any]:
payload["cu"] = row.get('currency_code') # Currency code.
else:
error_message = f"Hit type {hit_type} is not supported."
logging.get_logger("megalista.GoogleAnalyticsMeasurementProtocolUploader").error(error_message)
logging.get_logger("megalista.GoogleAnalyticsMeasurementProtocolUploader").error(error_message, execution=batch.execution)
self._add_error(batch.execution, error_message)

return payload
@@ -107,7 +107,7 @@ def process(self, batch: Batch, **kwargs):
response = requests.post(url=self.API_URL, data=payload)
if response.status_code != 200:
error_message = f"Error uploading to Analytics HTTP {response.status_code}: {response.raw}"
logging.get_logger("megalista.GoogleAnalyticsMeasurementProtocolUploader").error(error_message)
logging.get_logger("megalista.GoogleAnalyticsMeasurementProtocolUploader").error(error_message, execution=batch.execution)
self._add_error(batch.execution, error_message)
batch.execution.unsuccessful_records = batch.execution.unsuccessful_records + len(rows)
else:
Original file line number Diff line number Diff line change
@@ -163,15 +163,15 @@ def _do_upload_data(self, execution, web_property_id, view_id, data_import_name,
media_body=media).execute()
except Exception as e:
error_message = f'Error while uploading GA Data: {e}'
logging.get_logger().error(error_message)
logging.get_logger().error(error_message, execution=execution)
self._add_error(execution, error_message)
execution.unsuccessful_records = execution.unsuccessful_records + len(rows)
else:
execution.successful_records = execution.successful_records + len(rows)

else:
error_message = f"{data_import_name} - data import not found, please configure it in Google Analytics"
logging.get_logger().error(error_message)
logging.get_logger().error(error_message, execution=execution)
self._add_error(execution, error_message)
execution.unsuccessful_records = execution.unsuccessful_records + len(rows)

8 changes: 4 additions & 4 deletions megalista_dataflow/uploaders/utils.py
Original file line number Diff line number Diff line change
@@ -72,14 +72,14 @@ def inner(*args, **kwargs):
if not batch:
logger.warning('Skipping upload, received no elements.')
return
logger.info(f'Uploading {len(batch.elements)} rows...')
logger.info(f'Uploading {len(batch.elements)} rows...', execution=batch.execution)
try:
return func(*args, **kwargs)
except Exception as e:
self_._add_error(batch.execution, f'Error uploading data: {e}')
logger.error(f'Error uploading data for :{batch.elements}')
logger.error(e, exc_info=True)
logger.exception('Error uploading data.')
logger.error(f'Error uploading data for :{batch.elements}', execution=batch.execution)
logger.error(e, exc_info=True, execution=batch.execution)
logger.exception('Error uploading data.', execution=batch.execution)

return inner