Skip to content

Commit c15847c

Browse files
authored
fix: Use value of cluster-location in GKE for tagging location (#830)
1 parent 870c940 commit c15847c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

google/cloud/logging_v2/handlers/_monitored_resources.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
_GKE_CLUSTER_NAME = "instance/attributes/cluster-name"
6262
"""Attribute in metadata server when in GKE environment."""
6363

64+
_GKE_CLUSTER_LOCATION = "instance/attributes/cluster-location"
65+
"""Attribute in metadata server when in GKE environment."""
66+
6467
_PROJECT_NAME = "project/project-id"
6568
"""Attribute in metadata server when in GKE environment."""
6669

@@ -94,15 +97,15 @@ def _create_kubernetes_resource():
9497
Returns:
9598
google.cloud.logging.Resource
9699
"""
97-
zone = retrieve_metadata_server(_ZONE_ID)
100+
location = retrieve_metadata_server(_GKE_CLUSTER_LOCATION)
98101
cluster_name = retrieve_metadata_server(_GKE_CLUSTER_NAME)
99102
project = retrieve_metadata_server(_PROJECT_NAME)
100103

101104
resource = Resource(
102105
type="k8s_container",
103106
labels={
104107
"project_id": project if project else "",
105-
"location": zone if zone else "",
108+
"location": location if location else "",
106109
"cluster_name": cluster_name if cluster_name else "",
107110
},
108111
)

tests/unit/handlers/test__monitored_resources.py

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _mock_metadata(self, endpoint):
5656
if (
5757
endpoint == _monitored_resources._ZONE_ID
5858
or endpoint == _monitored_resources._REGION_ID
59+
or endpoint == _monitored_resources._GKE_CLUSTER_LOCATION
5960
):
6061
return self.LOCATION
6162
elif (

0 commit comments

Comments
 (0)