Skip to content

Commit 3dacdf2

Browse files
bvliucopybara-github
authored andcommitted
Fix CloudSQL metric collection time zone.
PiperOrigin-RevId: 832333784
1 parent 6c9b469 commit 3dacdf2

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

perfkitbenchmarker/providers/gcp/gcp_relational_db.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from absl import flags
3232
from google.cloud import monitoring_v3
33+
from google.cloud.monitoring_v3 import types
3334
from perfkitbenchmarker import data
3435
from perfkitbenchmarker import log_util
3536
from 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

Comments
 (0)