Skip to content

Commit

Permalink
Make subconfigs weighted (#4456)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmetzman authored Nov 27, 2024
1 parent f4da72b commit 7740010
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
28 changes: 21 additions & 7 deletions configs/test/batch/batch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ mapping:
disk_type: pd-standard
service_account_email: test-clusterfuzz-service-account-email
subconfigs:
- central1-network1
- central1-network2
-
name: central1-network1
weight: .5
-
name: central1-network2
weight: .5
preemptible: false
machine_type: n1-standard-1
LINUX-NONPREEMPTIBLE-UNPRIVILEGED:
Expand All @@ -35,9 +39,15 @@ mapping:
preemptible: false
machine_type: n1-standard-1
subconfigs:
- central1-network1
- central1-network2
- east4-network2
-
name: central1-network1
weight: .2
-
name: central1-network2
weight: .3
-
name: east4-network2
weight: .5
LINUX-PREEMPTIBLE:
clusterfuzz_release: 'prod'
docker_image: 'gcr.io/clusterfuzz-images/base:a2f4dd6-202202070654'
Expand All @@ -48,7 +58,9 @@ mapping:
preemptible: true
machine_type: n1-standard-1
subconfigs:
- east4-network2
-
name: east4-network2
weight: 1
LINUX-PREEMPTIBLE-UNPRIVILEGED:
clusterfuzz_release: 'prod'
docker_image: 'gcr.io/clusterfuzz-images/base:a2f4dd6-202202070654'
Expand All @@ -59,7 +71,9 @@ mapping:
preemptible: true
machine_type: n1-standard-1
subconfigs:
- east4-network2
-
name: east4-network2
weight: 1
project: 'test-clusterfuzz'
subconfigs:
central1-network1:
Expand Down
14 changes: 11 additions & 3 deletions src/clusterfuzz/_internal/google_cloud_utils/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
"""Cloud Batch helpers."""
import collections
import random
import threading
from typing import List
import uuid
Expand Down Expand Up @@ -270,11 +269,20 @@ def _get_task_duration(command):
tasks.TASK_LEASE_SECONDS)


WeightedSubconfig = collections.namedtuple('WeightedSubconfig',
['name', 'weight'])


def _get_subconfig(batch_config, instance_spec):
# TODO(metzman): Make this pick one at random or based on conditions.
all_subconfigs = batch_config.get('subconfigs', {})
subconfig_name = random.choice(instance_spec['subconfigs'])
return all_subconfigs[subconfig_name]
instance_subconfigs = instance_spec['subconfigs']
weighted_subconfigs = [
WeightedSubconfig(subconfig['name'], subconfig['weight'])
for subconfig in instance_subconfigs
]
weighted_subconfig = utils.random_weighted_choice(weighted_subconfigs)
return all_subconfigs[weighted_subconfig.name]


def _get_spec_from_config(command, job_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ def setUp(self):
self.job = data_types.Job(name='libfuzzer_chrome_asan', platform='LINUX')
self.job.put()
helpers.patch(self, [
'random.choice',
'clusterfuzz._internal.base.utils.random_weighted_choice',
])
self.mock.choice.return_value = 'east4-network2'
self.mock.random_weighted_choice.return_value = batch.WeightedSubconfig(
name='east4-network2',
weight=1,
)

def test_nonpreemptible(self):
"""Tests that get_spec_from_config works for non-preemptibles as
Expand Down

0 comments on commit 7740010

Please sign in to comment.