Skip to content

Commit

Permalink
MRG: Merge pull request #5 from octue/add-logging-and-adjust-event-st…
Browse files Browse the repository at this point in the history
…orage-format

Configure logging and avoid duplicated data storage
  • Loading branch information
cortadocodes authored Apr 10, 2024
2 parents bbaae17 + c1d91c8 commit ba85635
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
19 changes: 10 additions & 9 deletions functions/event_handler/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import base64
import logging
import os
import sys

import functions_framework
from google.cloud.bigquery import Client


logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -33,16 +35,15 @@ def store_pub_sub_event_in_bigquery(cloud_event):

row = {
"event": event,
"attributes": attributes,
"other_attributes": attributes,
# Pull out some attributes into columns for querying.
"uuid": attributes["uuid"],
"originator": attributes["originator"],
"sender": attributes["sender"],
"sender_type": attributes["sender_type"],
"sender_sdk_version": attributes["sender_sdk_version"],
"recipient": attributes["recipient"],
"question_uuid": attributes["question_uuid"],
"order": attributes["order"],
"originator": attributes.pop("originator"),
"sender": attributes.pop("sender"),
"sender_type": attributes.pop("sender_type"),
"sender_sdk_version": attributes.pop("sender_sdk_version"),
"recipient": attributes.pop("recipient"),
"question_uuid": attributes.pop("question_uuid"),
"order": attributes.pop("order"),
# Backend-specific metadata.
"backend": BACKEND,
"backend_metadata": backend_metadata,
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

setup(
name="twined-gcp",
version="0.2.0",
version="0.3.0",
author="Marcus Lugg <marcus@octue.com>",
install_requires=[
"setuptools",
# Requirements duplicated from cloud functions.
"functions-framework==3.*",
"google-cloud-bigquery>=3.18.0,<=4",
],
packages=["functions"],
)
10 changes: 1 addition & 9 deletions tests/test_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,9 @@ def test_store_pub_sub_event_in_bigquery(self):
mock_big_query_client.inserted_rows[0][0],
{
"event": "some-data",
"attributes": {
"other_attributes": {
"uuid": "c8bda9fa-f072-4330-92b1-96920d06b28d",
"originator": "octue/test-service:5.6.3",
"sender": "octue/test-service:5.6.3",
"sender_type": "PARENT",
"sender_sdk_version": "1.0.3",
"recipient": "octue/another-service:1.0.0",
"question_uuid": "ca534cdd-24cb-4ed2-af57-e36757192acb",
"order": "0",
},
"uuid": "c8bda9fa-f072-4330-92b1-96920d06b28d",
"originator": "octue/test-service:5.6.3",
"sender": "octue/test-service:5.6.3",
"sender_type": "PARENT",
Expand Down

0 comments on commit ba85635

Please sign in to comment.