Skip to content

Commit ca4be9f

Browse files
author
Matt Pryor
committed
Add support for benchmark started time
1 parent 568e56e commit ca4be9f

File tree

6 files changed

+49
-62
lines changed

6 files changed

+49
-62
lines changed

python/perftest/models/v1alpha1/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class BenchmarkStatus(schema.BaseModel):
127127
default_factory = list,
128128
description = "List of references to the managed resources for this benchmark."
129129
)
130+
started_at: t.Optional[datetime.datetime] = Field(
131+
None,
132+
description = "The time at which the benchmark started."
133+
)
130134
finished_at: t.Optional[datetime.datetime] = Field(
131135
None,
132136
description = "The time at which the benchmark finished."

python/perftest/models/v1alpha1/iperf.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ class IPerfSpec(schema.BaseModel):
4040
None,
4141
description = "The resources to use for benchmark containers."
4242
)
43-
server_service: bool = Field(
44-
False,
45-
description = "Indicates whether to access the server via a service or not."
46-
)
4743
duration: schema.conint(gt = 0) = Field(
4844
...,
4945
description = "The duration of the benchmark."
@@ -122,11 +118,6 @@ class IPerf(
122118
"type": "string",
123119
"jsonPath": ".spec.networkName",
124120
},
125-
{
126-
"name": "Server Service",
127-
"type": "string",
128-
"jsonPath": ".spec.serverService",
129-
},
130121
{
131122
"name": "Duration",
132123
"type": "integer",
@@ -142,6 +133,11 @@ class IPerf(
142133
"type": "string",
143134
"jsonPath": ".status.phase",
144135
},
136+
{
137+
"name": "Started",
138+
"type": "date",
139+
"jsonPath": ".status.startedAt",
140+
},
145141
{
146142
"name": "Finished",
147143
"type": "date",

python/perftest/models/v1alpha1/openfoam.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ class OpenFOAM(
140140
"type": "string",
141141
"jsonPath": ".status.phase",
142142
},
143+
{
144+
"name": "Started",
145+
"type": "date",
146+
"jsonPath": ".status.startedAt",
147+
},
143148
{
144149
"name": "Finished",
145150
"type": "date",

python/perftest/models/v1alpha1/pingpong.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ class MPIPingPong(
123123
"type": "string",
124124
"jsonPath": ".status.phase",
125125
},
126+
{
127+
"name": "Started",
128+
"type": "date",
129+
"jsonPath": ".status.startedAt",
130+
},
126131
{
127132
"name": "Finished",
128133
"type": "date",

python/perftest/operator.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -266,32 +266,33 @@ async def handle_benchmark_status_changed(benchmark, **kwargs):
266266
succeeded = benchmark.status.phase == api.BenchmarkPhase.COMPLETED
267267
benchmark_set.status.completed[benchmark.metadata.name] = succeeded
268268
_ = await save_benchmark_status(benchmark_set)
269-
return
270-
# The only other phase we want to act on is summarising
271-
if benchmark.status.phase != api.BenchmarkPhase.SUMMARISING:
272-
return
273-
# Allow the benchmark to summarise itself and save
274-
try:
275-
benchmark.summarise()
276-
except errors.PodResultsIncompleteError as exc:
277-
# Convert this into a temporary error with a short delay, as it is likely
278-
# to be resolved quickly
279-
raise kopf.TemporaryError(str(exc), delay = 1)
280-
else:
281-
benchmark = await save_benchmark_status(benchmark)
282-
# Once the benchmark summary has been saved successfully, we can delete the managed resources
283-
for ref in benchmark.status.managed_resources:
284-
ekapi = EK_CLIENT.api(ref.api_version)
285-
resource = await ekapi.resource(ref.kind)
286-
await resource.delete(ref.name, namespace = benchmark.metadata.namespace)
287-
# Make sure to delete the priority class
288-
ekapi = EK_CLIENT.api("scheduling.k8s.io/v1")
289-
resource = await ekapi.resource("priorityclasses")
290-
_ = await resource.delete(benchmark.status.priority_class_name)
291-
# Once the resources are deleted, we can mark the benchmark as completed
292-
benchmark.status.phase = api.BenchmarkPhase.COMPLETED
293-
benchmark.status.managed_resources = []
294-
_ = await save_benchmark_status(benchmark)
269+
elif benchmark.status.phase == api.BenchmarkPhase.RUNNING:
270+
if not benchmark.status.started_at:
271+
benchmark.status.started_at = datetime.datetime.now()
272+
_ = await save_benchmark_status(benchmark)
273+
elif benchmark.status.phase == api.BenchmarkPhase.SUMMARISING:
274+
# Allow the benchmark to summarise itself and save
275+
try:
276+
benchmark.summarise()
277+
except errors.PodResultsIncompleteError as exc:
278+
# Convert this into a temporary error with a short delay, as it is likely
279+
# to be resolved quickly
280+
raise kopf.TemporaryError(str(exc), delay = 1)
281+
else:
282+
benchmark = await save_benchmark_status(benchmark)
283+
# Once the benchmark summary has been saved successfully, we can delete the managed resources
284+
for ref in benchmark.status.managed_resources:
285+
ekapi = EK_CLIENT.api(ref.api_version)
286+
resource = await ekapi.resource(ref.kind)
287+
await resource.delete(ref.name, namespace = benchmark.metadata.namespace)
288+
# Make sure to delete the priority class
289+
ekapi = EK_CLIENT.api("scheduling.k8s.io/v1")
290+
resource = await ekapi.resource("priorityclasses")
291+
_ = await resource.delete(benchmark.status.priority_class_name)
292+
# Once the resources are deleted, we can mark the benchmark as completed
293+
benchmark.status.phase = api.BenchmarkPhase.COMPLETED
294+
benchmark.status.managed_resources = []
295+
_ = await save_benchmark_status(benchmark)
295296

296297

297298
@benchmark_handler(kopf.on.delete)
@@ -349,6 +350,8 @@ async def handle_job_event(benchmark, body, **kwargs):
349350
"""
350351
Executes whenever an event occurs for a Volcano job that is part of a benchmark.
351352
"""
353+
if type == "DELETED":
354+
return
352355
# If the benchmark is completed, there is nothing to do
353356
if benchmark.status.phase == api.BenchmarkPhase.COMPLETED:
354357
return
@@ -422,7 +425,7 @@ async def handle_endpoints_event(type, benchmark, body, name, namespace, **kwarg
422425
},
423426
"data": {
424427
"hosts": hosts,
425-
}
428+
},
426429
},
427430
namespace = configmap.metadata.namespace
428431
)

python/perftest/templates/iperf.yaml.j2

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
{%- if benchmark.spec.server_service %}
2-
---
3-
apiVersion: v1
4-
kind: Service
5-
metadata:
6-
name: {{ benchmark.metadata.name }}-server
7-
labels:
8-
{{ settings.kind_label }}: {{ benchmark.kind }}
9-
{{ settings.namespace_label }}: {{ benchmark.metadata.namespace }}
10-
{{ settings.name_label }}: {{ benchmark.metadata.name }}
11-
{{ settings.component_label }}: server
12-
spec:
13-
ports:
14-
- port: 5001
15-
targetPort: iperf-server
16-
protocol: TCP
17-
selector:
18-
{{ settings.kind_label }}: {{ benchmark.kind }}
19-
{{ settings.namespace_label }}: {{ benchmark.metadata.namespace }}
20-
{{ settings.name_label }}: {{ benchmark.metadata.name }}
21-
{{ settings.component_label }}: server
22-
{%- endif %}
231
---
242
apiVersion: v1
253
kind: Service
@@ -151,11 +129,7 @@ spec:
151129
imagePullPolicy: {{ benchmark.spec.image_pull_policy }}
152130
args:
153131
- --client
154-
{%- if benchmark.spec.server_service %}
155-
- "{{ benchmark.metadata.name }}-server"
156-
{%- else %}
157132
- "{{ benchmark.metadata.name }}-server-0.{{ benchmark.metadata.name }}"
158-
{%- endif %}
159133
- --time
160134
- "{{ benchmark.spec.duration }}"
161135
- --parallel

0 commit comments

Comments
 (0)