Skip to content

Commit f6d530e

Browse files
p3rf Teamcopybara-github
authored andcommitted
Include locustpath in metadata of all metrics
PiperOrigin-RevId: 716372555
1 parent 63dc9ea commit f6d530e

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

perfkitbenchmarker/linux_packages/locust.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def GetPath(self):
2929
_LOCUST_FILE = flags.DEFINE_string(
3030
'locust_path',
3131
None,
32-
'Path to the locust file to use. If not specified, a default locust file'
33-
' passed in by the benchmark will be used. Can also use enum values rather'
34-
' than paths.',
32+
'Path to the locust file to use, e.g. `locust/simple.py`. Required.',
3533
)
3634

3735

@@ -56,7 +54,6 @@ def Install(vm: 'linux_virtual_machine.BaseLinuxVirtualMachine') -> None:
5654

5755
def Prep(
5856
vm: 'linux_virtual_machine.BaseLinuxVirtualMachine',
59-
locustfile_path: str | Locustfile | None = None,
6057
) -> None:
6158
"""Prepares a locustfile to run on the given VM.
6259
@@ -68,25 +65,13 @@ def Prep(
6865
6966
Args:
7067
vm: Already running VM where locust should be installed.
71-
locustfile_path: Path of the locustfile; see
72-
https://docs.locust.io/en/stable/writing-a-locustfile.html. NB: Two
73-
pre-defined locust files exist in this module that you can use:
74-
Locustfile.SIMPLE, Locustfile.RAMPUP.
7568
7669
Raises:
7770
errors.VirtualMachine.RemoteCommandError: If an error occurred on the VM.
7871
"""
79-
if locustfile_path is None and _LOCUST_FILE.value is not None:
80-
locustfile_path = _LOCUST_FILE.value
81-
try:
82-
locustfile_path = Locustfile(locustfile_path)
83-
except ValueError:
84-
# Not a predefined locustfile enum, rather a path. This is fine.
85-
pass
86-
if locustfile_path is None:
87-
raise ValueError('Locustfile path must be specified via argument or flag.')
88-
if isinstance(locustfile_path, Locustfile):
89-
locustfile_path = locustfile_path.GetPath()
72+
if _LOCUST_FILE.value is None:
73+
raise ValueError('Locustfile path must be specified via flag.')
74+
locustfile_path = data.ResourcePath(_LOCUST_FILE.value)
9075
vm.RemoteCopy(locustfile_path, 'locustfile.py')
9176

9277

@@ -168,7 +153,7 @@ def _ConvertLocustResultsToSamples(
168153
metric=metric_namespace + '/' + _SanitizeFieldName(field),
169154
value=float(row[field]),
170155
unit='',
171-
metadata={},
156+
metadata={'locustfile_path': _LOCUST_FILE.value},
172157
timestamp=int(row['Timestamp']),
173158
)
174159

tests/linux_packages/locust_test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import unittest
2+
3+
from absl import flags
24
from perfkitbenchmarker import sample
35
from perfkitbenchmarker.linux_packages import locust
46

57

68
class LocustTest(unittest.TestCase):
79

10+
def setUp(self):
11+
super().setUp()
12+
self.maxDiff = None
13+
814
def test_convert_locust_to_samples(self):
15+
flags.FLAGS["locust_path"].value = "path/to/locust.py"
16+
flags.FLAGS.mark_as_parsed()
17+
metadata = {"locustfile_path": "path/to/locust.py"}
18+
919
locust_output = """Timestamp,Type,Name,field1,field2
1020
12345678,ignored,also ignored,1,10
1121
12345679,ignored,also ignored,2,20
@@ -14,11 +24,11 @@ def test_convert_locust_to_samples(self):
1424
samples = locust._ConvertLocustResultsToSamples(locust_output)
1525
self.assertCountEqual(
1626
[
17-
sample.Sample("locust/field1", 1, "", {}, 12345678),
18-
sample.Sample("locust/field2", 10, "", {}, 12345678),
19-
sample.Sample("locust/field1", 2, "", {}, 12345679),
20-
sample.Sample("locust/field2", 20, "", {}, 12345679),
21-
sample.Sample("locust/field2", 30, "", {}, 12345680),
27+
sample.Sample("locust/field1", 1, "", metadata, 12345678),
28+
sample.Sample("locust/field2", 10, "", metadata, 12345678),
29+
sample.Sample("locust/field1", 2, "", metadata, 12345679),
30+
sample.Sample("locust/field2", 20, "", metadata, 12345679),
31+
sample.Sample("locust/field2", 30, "", metadata, 12345680),
2232
],
2333
samples,
2434
)

0 commit comments

Comments
 (0)