3030
3131from absl import flags
3232from google .cloud import monitoring_v3
33+ from google .cloud .monitoring_v3 import types
3334from perfkitbenchmarker import data
3435from perfkitbenchmarker import log_util
3536from perfkitbenchmarker import mysql_iaas_relational_db
@@ -650,6 +651,7 @@ def _CollectTimeSeries(
650651 metric_basename = _GetMetricBasename (metric_type )
651652 unit = _GetMetricUnit (metric_type )
652653 samples = []
654+ client = monitoring_v3 .MetricServiceClient ()
653655 is_delta = metric_type .endswith ('_ops_count' ) or metric_type .endswith (
654656 '_bytes_count'
655657 )
@@ -658,29 +660,29 @@ def _CollectTimeSeries(
658660 if is_delta
659661 else monitoring_v3 .Aggregation .Aligner .ALIGN_MEAN
660662 )
661-
662- client = monitoring_v3 .MetricServiceClient ()
663663 results = client .list_time_series (
664- request = {
665- ' name' : f'projects/{ self .project } ' ,
666- ' filter' : (
664+ types . ListTimeSeriesRequest (
665+ name = f'projects/{ self .project } ' ,
666+ filter = (
667667 'resource.type="cloudsql_database" AND'
668668 f' resource.labels.database_id="{ self .project } :{ self .instance_id } "'
669669 f' AND metric.type="{ metric_type } "'
670670 ),
671- ' interval' : {
672- ' start_time' : start_time .isoformat () + 'Z' ,
673- ' end_time' : end_time .isoformat () + 'Z' ,
674- } ,
675- ' aggregation' : {
676- ' alignment_period' : {'seconds' : 60 },
677- ' per_series_aligner' : aligner ,
678- } ,
679- }
671+ interval = types . TimeInterval (
672+ start_time = start_time .astimezone ( datetime . timezone . utc ) ,
673+ end_time = end_time .astimezone ( datetime . timezone . utc ) ,
674+ ) ,
675+ aggregation = monitoring_v3 . Aggregation (
676+ alignment_period = {'seconds' : 60 },
677+ per_series_aligner = aligner ,
678+ ) ,
679+ )
680680 )
681681 time_series = list (results )
682682 if not time_series or not time_series [0 ].points :
683- logging .warning ('No points in time series for %s.' , metric_type )
683+ logging .warning (
684+ 'No points in time series for %s. Results: %s' , metric_type , results
685+ )
684686 return []
685687
686688 points = time_series [0 ].points
0 commit comments