Skip to content

Commit 081a91a

Browse files
authored
chore: Add user agents for GCP/AWS services (feast-dev#3087)
* chore: Add BigQuery user agent Signed-off-by: Danny Chiao <[email protected]> * add other agents Signed-off-by: Danny Chiao <[email protected]> * fix Signed-off-by: Danny Chiao <[email protected]> Signed-off-by: Danny Chiao <[email protected]>
1 parent 0d2d951 commit 081a91a

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

sdk/python/feast/infra/offline_stores/bigquery.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@
4444
from feast.repo_config import FeastConfigBaseModel, RepoConfig
4545

4646
from ...saved_dataset import SavedDatasetStorage
47-
from ...usage import log_exceptions_and_usage
47+
from ...usage import get_user_agent, log_exceptions_and_usage
4848
from .bigquery_source import (
4949
BigQueryLoggingDestination,
5050
BigQuerySource,
5151
SavedDatasetBigQueryStorage,
5252
)
5353

5454
try:
55+
from google.api_core import client_info as http_client_info
5556
from google.api_core.exceptions import NotFound
5657
from google.auth.exceptions import DefaultCredentialsError
5758
from google.cloud import bigquery
@@ -65,6 +66,10 @@
6566
raise FeastExtrasDependencyImportError("gcp", str(e))
6667

6768

69+
def get_http_client_info():
70+
return http_client_info.ClientInfo(user_agent=get_user_agent())
71+
72+
6873
class BigQueryOfflineStoreConfig(FeastConfigBaseModel):
6974
"""Offline store config for GCP BigQuery"""
7075

@@ -688,7 +693,9 @@ def _get_bigquery_client(
688693
project: Optional[str] = None, location: Optional[str] = None
689694
) -> bigquery.Client:
690695
try:
691-
client = bigquery.Client(project=project, location=location)
696+
client = bigquery.Client(
697+
project=project, location=location, client_info=get_http_client_info()
698+
)
692699
except DefaultCredentialsError as e:
693700
raise FeastProviderLoginError(
694701
str(e)

sdk/python/feast/infra/online_stores/datastore.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
3636
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
3737
from feast.repo_config import FeastConfigBaseModel, RepoConfig
38-
from feast.usage import log_exceptions_and_usage, tracing_span
38+
from feast.usage import get_user_agent, log_exceptions_and_usage, tracing_span
3939

4040
LOGGER = logging.getLogger(__name__)
4141

4242
try:
43+
from google.api_core import client_info as http_client_info
4344
from google.auth.exceptions import DefaultCredentialsError
4445
from google.cloud import datastore
4546
from google.cloud.datastore.client import Key
@@ -49,6 +50,10 @@
4950
raise FeastExtrasDependencyImportError("gcp", str(e))
5051

5152

53+
def get_http_client_info():
54+
return http_client_info.ClientInfo(user_agent=get_user_agent())
55+
56+
5257
ProtoBatch = Sequence[
5358
Tuple[EntityKeyProto, Dict[str, ValueProto], datetime, Optional[datetime]]
5459
]
@@ -331,8 +336,7 @@ def _initialize_client(
331336
) -> datastore.Client:
332337
try:
333338
client = datastore.Client(
334-
project=project_id,
335-
namespace=namespace,
339+
project=project_id, namespace=namespace, client_info=get_http_client_info()
336340
)
337341
return client
338342
except DefaultCredentialsError as e:

sdk/python/feast/infra/online_stores/dynamodb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto
3131
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
3232
from feast.repo_config import FeastConfigBaseModel, RepoConfig
33-
from feast.usage import log_exceptions_and_usage, tracing_span
33+
from feast.usage import get_user_agent, log_exceptions_and_usage, tracing_span
3434

3535
try:
3636
import boto3
37+
from botocore.config import Config
3738
from botocore.exceptions import ClientError
3839
except ImportError as e:
3940
from feast.errors import FeastExtrasDependencyImportError
@@ -330,7 +331,12 @@ def _write_batch_non_duplicates(
330331

331332

332333
def _initialize_dynamodb_client(region: str, endpoint_url: Optional[str] = None):
333-
return boto3.client("dynamodb", region_name=region, endpoint_url=endpoint_url)
334+
return boto3.client(
335+
"dynamodb",
336+
region_name=region,
337+
endpoint_url=endpoint_url,
338+
config=Config(user_agent=get_user_agent()),
339+
)
334340

335341

336342
def _initialize_dynamodb_resource(region: str, endpoint_url: Optional[str] = None):

sdk/python/feast/infra/utils/aws_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
RedshiftTableNameTooLong,
2323
)
2424
from feast.type_map import pa_to_athena_value_type, pa_to_redshift_value_type
25+
from feast.usage import get_user_agent
2526

2627
try:
2728
import boto3
@@ -39,7 +40,10 @@ def get_redshift_data_client(aws_region: str):
3940
"""
4041
Get the Redshift Data API Service client for the given AWS region.
4142
"""
42-
return boto3.client("redshift-data", config=Config(region_name=aws_region))
43+
return boto3.client(
44+
"redshift-data",
45+
config=Config(region_name=aws_region, user_agent=get_user_agent()),
46+
)
4347

4448

4549
def get_s3_resource(aws_region: str):
@@ -680,7 +684,9 @@ def get_athena_data_client(aws_region: str):
680684
"""
681685
Get the athena Data API Service client for the given AWS region.
682686
"""
683-
return boto3.client("athena", config=Config(region_name=aws_region))
687+
return boto3.client(
688+
"athena", config=Config(region_name=aws_region, user_agent=get_user_agent())
689+
)
684690

685691

686692
@retry(

sdk/python/feast/usage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
).hexdigest(),
5555
}
5656

57+
APPLICATION_NAME = "feast-dev/feast"
58+
USER_AGENT = "{}/{}".format(APPLICATION_NAME, get_version())
59+
60+
61+
def get_user_agent():
62+
return USER_AGENT
63+
5764

5865
def set_current_project_uuid(project_uuid: str):
5966
_constant_attributes["project_id"] = project_uuid

0 commit comments

Comments
 (0)