Skip to content

Commit

Permalink
[source-google-analytics-data-api] - Migrate to CDK v5 (#47013)
Browse files Browse the repository at this point in the history
  • Loading branch information
pnilan authored Oct 28, 2024
1 parent 0dc4efe commit 5fda600
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 3cc2eafd-84aa-4dca-93af-322d9dfeec1a
dockerImageTag: 2.5.13
dockerImageTag: 2.6.0
dockerRepository: airbyte/source-google-analytics-data-api
documentationUrl: https://docs.airbyte.com/integrations/sources/google-analytics-data-api
githubIssueLabel: source-google-analytics-data-api
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "2.5.13"
version = "2.6.0"
name = "source-google-analytics-data-api"
description = "Source implementation for Google Analytics Data Api."
authors = [ "Airbyte <[email protected]>",]
Expand All @@ -16,12 +16,12 @@ repository = "https://github.com/airbytehq/airbyte"
include = "source_google_analytics_data_api"

[tool.poetry.dependencies]
python = "^3.9,<3.12"
python = "^3.10,<3.12"
cryptography = "==42.0.5"
requests = "==2.31.0"
airbyte-cdk = "^3"
airbyte-cdk = "^5.0.0"
PyJWT = "==2.8.0"
pandas = "==2.2.0"
pandas = "^2.2.0"

[tool.poetry.scripts]
source-google-analytics-data-api = "source_google_analytics_data_api.run:run"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from typing import Any, List, Mapping

import dpath.util
import orjson
from airbyte_cdk.config_observation import create_connector_config_control_message
from airbyte_cdk.entrypoint import AirbyteEntrypoint
from airbyte_cdk.models import AirbyteMessageSerializer
from airbyte_cdk.sources.message import InMemoryMessageRepository, MessageRepository

from .source import SourceGoogleAnalyticsDataApi
Expand Down Expand Up @@ -67,7 +69,7 @@ def _emit_control_message(cls, migrated_config: Mapping[str, Any]) -> None:
cls.message_repository.emit_message(create_connector_config_control_message(migrated_config))
# emit the Airbyte Control Message from message queue to stdout
for message in cls.message_repository.consume_queue():
print(message.json(exclude_unset=True))
print(orjson.dumps(AirbyteMessageSerializer.dump(message)).decode())

@classmethod
def migrate(cls, args: List[str], source: SourceGoogleAnalyticsDataApi) -> None:
Expand Down Expand Up @@ -145,7 +147,7 @@ def _emit_control_message(cls, migrated_config: Mapping[str, Any]) -> None:
cls.message_repository.emit_message(create_connector_config_control_message(migrated_config))
# emit the Airbyte Control Message from message queue to stdout
for message in cls.message_repository.consume_queue():
print(message.json(exclude_unset=True))
print(orjson.dumps(AirbyteMessageSerializer.dump(message)).decode())

@classmethod
def migrate(cls, args: List[str], source: SourceGoogleAnalyticsDataApi) -> None:
Expand Down Expand Up @@ -215,7 +217,7 @@ def _emit_control_message(cls, migrated_config: Mapping[str, Any]) -> None:
cls.message_repository.emit_message(create_connector_config_control_message(migrated_config))
# emit the Airbyte Control Message from message queue to stdout
for message in cls.message_repository.consume_queue():
print(message.json(exclude_unset=True))
print(orjson.dumps(AirbyteMessageSerializer.dump(message)).decode())

@classmethod
def migrate(cls, args: List[str], source: SourceGoogleAnalyticsDataApi) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

import copy
import datetime
import json
import logging
Expand Down Expand Up @@ -354,10 +355,14 @@ def request_body_json(
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
) -> Optional[Mapping]:
if stream_slice and "startDate" in stream_slice and "endDate" in stream_slice:
date_range = {"startDate": stream_slice["startDate"], "endDate": stream_slice["endDate"]}
else:
date_range = stream_slice
payload = {
"metrics": [{"name": m} for m in self.config["metrics"]],
"dimensions": [{"name": d} for d in self.config["dimensions"]],
"dateRanges": [stream_slice],
"dateRanges": [date_range],
"returnPropertyQuota": True,
"offset": str(0),
"limit": str(self.page_size),
Expand Down Expand Up @@ -414,7 +419,6 @@ def request_body_json(
next_page_token: Mapping[str, Any] = None,
) -> Optional[Mapping]:
payload = super().request_body_json(stream_state, stream_slice, next_page_token)

# remove offset and limit fields according to their absence in
# https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runPivotReport
payload.pop("offset", None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from unittest.mock import MagicMock, patch

import pytest
from airbyte_cdk.models import AirbyteConnectionStatus, FailureType
from airbyte_cdk.models import AirbyteConnectionStatus, FailureType, Status
from airbyte_cdk.sources.streams.http.http import HttpStatusErrorHandler
from airbyte_cdk.utils import AirbyteTracedException
from airbyte_protocol.models import Status
from source_google_analytics_data_api import SourceGoogleAnalyticsDataApi
from source_google_analytics_data_api.api_quota import GoogleAnalyticsApiQuotaBase
from source_google_analytics_data_api.source import GoogleAnalyticsDatApiErrorHandler, MetadataDescriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test_request_params(patch_base_class):


def test_request_body_json(patch_base_class):
request_body_params = {"stream_state": MagicMock(), "stream_slice": MagicMock(), "next_page_token": None}
stream_slice = {"startDate": "2024-01-01", "endDate": "2024-01-31"}
request_body_params = {"stream_state": MagicMock(), "stream_slice": stream_slice, "next_page_token": None}

expected_body_json = {
"metrics": [
Expand All @@ -84,7 +85,10 @@ def test_request_body_json(patch_base_class):
{"name": "browser"},
],
"keepEmptyRows": True,
"dateRanges": [request_body_params["stream_slice"]],
"dateRanges": [{
"startDate": request_body_params["stream_slice"]["startDate"],
"endDate": request_body_params["stream_slice"]["endDate"]
}],
"returnPropertyQuota": True,
"offset": str(0),
"limit": "100000",
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/google-analytics-data-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ The Google Analytics connector is subject to Google Analytics Data API quotas. P

| Version | Date | Pull Request | Subject |
|:--------|:-----------| :------------------------------------------------------- |:---------------------------------------------------------------------------------------|
| 2.6.0 | 2024-10-28 | [47013](https://github.com/airbytehq/airbyte/pull/47013) | Migrate to CDK v5 |
| 2.5.13 | 2024-10-28 | [47061](https://github.com/airbytehq/airbyte/pull/47061) | Update dependencies |
| 2.5.12 | 2024-10-12 | [46819](https://github.com/airbytehq/airbyte/pull/46819) | Update dependencies |
| 2.5.11 | 2024-10-05 | [46475](https://github.com/airbytehq/airbyte/pull/46475) | Update dependencies |
Expand Down

0 comments on commit 5fda600

Please sign in to comment.