Skip to content

Commit f820f6d

Browse files
Upgrading the metrics query to the latest version (#1674)
* Upgrading the metrics query to the latest version * fix lint issues * Importing module not class
1 parent cf643c8 commit f820f6d

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

bigtable/metricscaler/metricscaler.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
programmatically scale a Google Cloud Bigtable cluster."""
1717

1818
import argparse
19+
import os
1920
import time
2021

2122
from google.cloud import bigtable
22-
from google.cloud import monitoring
23+
from google.cloud import monitoring_v3
24+
from google.cloud.monitoring_v3 import query
25+
26+
PROJECT = os.environ['GCLOUD_PROJECT']
2327

2428

2529
def get_cpu_load():
@@ -29,11 +33,15 @@ def get_cpu_load():
2933
float: The most recent Cloud Bigtable CPU usage metric
3034
"""
3135
# [START bigtable_cpu]
32-
client = monitoring.Client()
33-
query = client.query('bigtable.googleapis.com/cluster/cpu_load', minutes=5)
34-
time_series = list(query)
36+
client = monitoring_v3.MetricServiceClient()
37+
cpu_query = query.Query(client,
38+
project=PROJECT,
39+
metric_type='bigtable.googleapis.com/'
40+
'cluster/cpu_load',
41+
minutes=5)
42+
time_series = list(cpu_query)
3543
recent_time_series = time_series[0]
36-
return recent_time_series.points[0].value
44+
return recent_time_series.points[0].value.double_value
3745
# [END bigtable_cpu]
3846

3947

bigtable/metricscaler/metricscaler_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
def test_get_cpu_load():
35-
assert get_cpu_load() > 0.0
35+
assert float(get_cpu_load()) > 0.0
3636

3737

3838
def test_scale_bigtable():
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
google-cloud-bigtable==0.29.0
2-
google-cloud-monitoring==0.28.1
2+
google-cloud-monitoring==0.30.1

0 commit comments

Comments
 (0)