Skip to content

Commit f32f45b

Browse files
jnguertincopybara-github
authored andcommitted
Improved metadata retrieval interface.
PiperOrigin-RevId: 823664128
1 parent 89b2d6a commit f32f45b

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

perfkitbenchmarker/edw_service.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Any, Dict, List
2121

2222
from absl import flags
23+
from absl import logging
2324
from perfkitbenchmarker import resource
2425

2526
flags.DEFINE_integer(
@@ -598,11 +599,39 @@ def GetIterationAuxiliaryMetrics(self, iter_run_key: str) -> Dict[str, Any]:
598599
599600
Returns:
600601
A dictionary of the following format:
601-
{ 'metric_1': { 'value': 1, 'unit': 'imperial femtoseconds' },
602-
'metric_2': { 'value': 2, 'unit': 'metric dollars' }
602+
{ 'metric_1': { 'value': 1, 'unit': 'imperial femtoseconds'},
603+
'metric_2': { 'value': 2, 'unit': 'metric dollars'}
603604
...}
604605
"""
605-
raise NotImplementedError
606+
logging.info(
607+
'Per-iteration auxiliary metrics are not supported for this service.'
608+
)
609+
del iter_run_key
610+
return {}
611+
612+
def GetTimeBoundAuxiliaryMetrics(
613+
self, start_timestamp: float, end_timestamp: float
614+
) -> List[Dict[str, Any]]:
615+
"""Returns service-specific metrics from a set time range.
616+
617+
Whenever possible, the service should return metrics only from the compute
618+
cluster used for the current benchmark run.
619+
620+
Args:
621+
start_timestamp: Start of the time range to retrieve metrics for.
622+
end_timestamp: End of the time range to retrieve metrics for.
623+
624+
Returns:
625+
A list of the following format:
626+
[{'metric_1': 'value': 1, 'unit': 'imperial nanoseconds', metadata: {}},
627+
{'metric_2': 'value': 2, 'unit': 'metric dollars', metadata: {}}
628+
...]
629+
"""
630+
logging.info(
631+
'Time-bound auxiliary metrics are not supported for this service.'
632+
)
633+
del start_timestamp, end_timestamp
634+
return []
606635

607636
def CreateSearchIndex(
608637
self, table_path: str, index_name: str
@@ -758,3 +787,18 @@ def TextSearchQuery(
758787
A tuple of execution time in seconds and a dictionary of metadata.
759788
"""
760789
raise NotImplementedError
790+
791+
@staticmethod
792+
def ColsToRows(col_res: dict[str, list[Any]]) -> list[dict[str, Any]]:
793+
"""Converts a dictionary of columns to a list of rows.
794+
795+
Args:
796+
col_res: A dictionary of columns to convert to a list of rows.
797+
798+
Returns:
799+
A list of dictionaries, where each dictionary represents a row.
800+
801+
e.g. {'col1': [1, 2, 3], 'col2': [4, 5, 6]} -> [{'col1': 1, 'col2': 4},
802+
{'col1': 2, 'col2': 5}, {'col1': 3, 'col2': 6}].
803+
"""
804+
return [dict(zip(col_res.keys(), row)) for row in zip(*col_res.values())]

perfkitbenchmarker/providers/gcp/bigquery.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import os
2121
import random
2222
import re
23-
from typing import Any
23+
from typing import Any, override
2424

2525
from absl import flags
2626
from perfkitbenchmarker import data
@@ -769,6 +769,7 @@ def GetAutoscaleSlotSeconds(self, run_iter_id: str) -> int:
769769
run_cost = output['details']['query_results']['billed_slot_seconds'][0]
770770
return run_cost
771771

772+
@override
772773
def GetIterationAuxiliaryMetrics(self, iter_run_key: str) -> dict[str, Any]:
773774
service_auxiliary_metrics = {}
774775
try:

tests/edw_service_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import copy
1717
import unittest
1818
from absl import flags
19+
from absl.testing import parameterized
1920
from perfkitbenchmarker import edw_service
2021
from perfkitbenchmarker.configs import benchmark_config_spec
2122
from tests import pkb_common_test_case
@@ -110,6 +111,44 @@ def testPkbManagedGetClusterIdentifier(self):
110111
)
111112
self.assertEqual('pkb-' + FLAGS.run_uri, edw_local.cluster_identifier)
112113

114+
@parameterized.named_parameters(
115+
dict(
116+
testcase_name='_empty_dict',
117+
cols={},
118+
expected=[],
119+
),
120+
dict(
121+
testcase_name='_single_column',
122+
cols={'col1': ['val1', 'val2']},
123+
expected=[{'col1': 'val1'}, {'col1': 'val2'}],
124+
),
125+
dict(
126+
testcase_name='_multiple_columns',
127+
cols={'col1': ['val1', 'val2'], 'col2': ['val3', 'val4']},
128+
expected=[
129+
{'col1': 'val1', 'col2': 'val3'},
130+
{'col1': 'val2', 'col2': 'val4'},
131+
],
132+
),
133+
dict(
134+
testcase_name='_uneven_columns',
135+
cols={'col1': ['val1', 'val2'], 'col2': ['val3', 'val4', 'val5']},
136+
expected=[
137+
{'col1': 'val1', 'col2': 'val3'},
138+
{'col1': 'val2', 'col2': 'val4'},
139+
],
140+
),
141+
)
142+
def testColsToRows(self, cols=None, expected=None):
143+
self.assertEqual(
144+
expected,
145+
edw_service.EdwService.ColsToRows(cols),
146+
msg=(
147+
f'Expected {expected} but got'
148+
f' {edw_service.EdwService.ColsToRows(cols)}'
149+
),
150+
)
151+
113152

114153
if __name__ == '__main__':
115154
unittest.main()

0 commit comments

Comments
 (0)