Aman Swarnkar
Aman Swarnkar

Reputation: 68

AttributeError: module 'google.cloud.monitoring_v3.types' has no attribute 'MetricDescriptor'

I am running a script to create gpu metrics on gcp and getting the following errors:

AttributeError: 'MetricServiceClient' object has no attribute 'project_path'

AttributeError: module 'google.cloud.monitoring_v3.types' has no attribute 'MetricDescriptor'

Upvotes: 3

Views: 2279

Answers (1)

justind
justind

Reputation: 1258

project_path

The 2.0 release of the google-cloud-monitoring library included a breaking change that wasn't documented in the change log, but it is covered in the upgrading guide. The project_path function was renamed to common_project_path.

Versions < 2.0.0

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()
project_path = client.project_path("project_id")

Versions >= 2.0.0

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()
project_path = client.common_project_path("project_id")

MetricDescriptor

The MetricDescriptor type looks to have moved around in the 2.0.0 release as well. It's also covered in the upgrading guide (with an incomplete snippet).

Versions < 2.0.0

from google.cloud import monitoring_v3

descriptor = monitoring_v3.types.MetricDescriptor()

Versions >= 2.0.0

from google.api import metric_pb2 as ga_metric

descriptor = ga_metric.MetricDescriptor()

Upvotes: 6

Related Questions