Skip to content

Commit 18f8ae8

Browse files
committed
Add DiskProvisionedIops and DiskProvisionedThroughputMibps pipeline options for python java and go sdks
1 parent 84b467b commit 18f8ae8

10 files changed

Lines changed: 116 additions & 0 deletions

File tree

runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowPipelineTranslator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ public Job translate(List<DataflowPackage> packages) {
405405
if (options.getDiskSizeGb() > 0) {
406406
workerPool.setDiskSizeGb(options.getDiskSizeGb());
407407
}
408+
if (options.getDiskProvisionedIops() != null) {
409+
workerPool.setDiskProvisionedIops(options.getDiskProvisionedIops());
410+
}
411+
if (options.getDiskProvisionedThroughputMibps() != null) {
412+
workerPool.setDiskProvisionedThroughputMibps(options.getDiskProvisionedThroughputMibps());
413+
}
408414
AutoscalingSettings settings = new AutoscalingSettings();
409415
if (options.getAutoscalingAlgorithm() != null) {
410416
settings.setAlgorithm(options.getAutoscalingAlgorithm().getAlgorithm());

runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/options/DataflowPipelineWorkerPoolOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ public String getAlgorithm() {
193193

194194
void setWorkerDiskType(String value);
195195

196+
@Description("IOPS provisioned for the root disk for VMs. If zero or " +
197+
"unspecified, the service will attempt to choose a reasonable default.")
198+
Long getDiskProvisionedIops();
199+
void setDiskProvisionedIops(Long diskProvisionedIops);
200+
201+
@Description("Throughput provisioned in MiB/s for the root disk for VMs. If zero or " +
202+
"unspecified, the service will attempt to choose a reasonable default.")
203+
Long getDiskProvisionedThroughputMibps();
204+
void setDiskProvisionedThroughputMibps(Long diskProvisionedThroughputMibps);
205+
206+
196207
/**
197208
* Specifies whether worker pools should be started with public IP addresses.
198209
*

runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/DataflowPipelineTranslatorTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,30 @@ public void testDiskSizeGbConfig() throws IOException {
619619
assertEquals(diskSizeGb, job.getEnvironment().getWorkerPools().get(0).getDiskSizeGb());
620620
}
621621

622+
@Test
623+
public void testDiskProvisioningTranslation() {
624+
DataflowPipelineOptions options = PipelineOptionsFactory.create().as(DataflowPipelineOptions.class);
625+
options.setDiskProvisionedIops(Long.valueOf(7000));
626+
options.setDiskProvisionedThroughputMibps(Long.valueOf(250));
627+
options.setProject("test-project"); // Required for translator
628+
629+
WorkerPool pool = translateWorkerPool(options);
630+
631+
assertEquals(Long.valueOf(7000), pool.getDiskProvisionedIops());
632+
assertEquals(Long.valueOf(250), pool.getDiskProvisionedThroughputMibps());
633+
}
634+
635+
@Test
636+
public void testDiskProvisioningTranslationDefaults() {
637+
DataflowPipelineOptions options = PipelineOptionsFactory.create().as(DataflowPipelineOptions.class);
638+
options.setProject("test-project"); // Required for translator
639+
640+
WorkerPool pool = translateWorkerPool(options);
641+
642+
assertNull(pool.getDiskProvisionedIops());
643+
assertNull(pool.getDiskProvisionedThroughputMibps());
644+
}
645+
622646
/** A composite transform that returns an output that is unrelated to the input. */
623647
private static class UnrelatedOutputCreator
624648
extends PTransform<PCollection<Integer>, PCollection<Integer>> {

sdks/go/pkg/beam/runners/dataflow/dataflow.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ var (
6363
maxNumWorkers = flag.Int64("max_num_workers", 0, "Maximum number of workers during scaling (optional).")
6464
diskSizeGb = flag.Int64("disk_size_gb", 0, "Size of root disk for VMs, in GB (optional).")
6565
diskType = flag.String("disk_type", "", "Type of root disk for VMs (optional).")
66+
diskProvisionedIOPS = flag.Int64("disk_provisioned_iops", 0, "Provisioned IOPS for the root disk for VMs (optional).")
67+
diskProvisionedThroughputMibps = flag.Int64("disk_provisioned_throughput_mibps", 0, "Provisioned throughput for the root disk for VMs (optional).")
6668
autoscalingAlgorithm = flag.String("autoscaling_algorithm", "", "Autoscaling mode to use (optional).")
6769
zone = flag.String("zone", "", "GCP zone (optional)")
6870
kmsKey = flag.String("dataflow_kms_key", "", "The Cloud KMS key identifier used to encrypt data at rest (optional).")
@@ -115,6 +117,8 @@ var flagFilter = map[string]bool{
115117
"max_num_workers": true,
116118
"disk_size_gb": true,
117119
"disk_type": true,
120+
"disk_provisioned_iops": true,
121+
"disk_provisioned_throughput_mibps": true,
118122
"autoscaling_algorithm": true,
119123
"zone": true,
120124
"network": true,
@@ -396,6 +400,8 @@ func getJobOptions(ctx context.Context, streaming bool) (*dataflowlib.JobOptions
396400
WorkerHarnessThreads: *workerHarnessThreads,
397401
DiskSizeGb: *diskSizeGb,
398402
DiskType: *diskType,
403+
DiskProvisionedIOPS: *diskProvisionedIOPS,
404+
DiskProvisionedThroughputMibps: *diskProvisionedThroughputMibps,
399405
Algorithm: *autoscalingAlgorithm,
400406
FlexRSGoal: *flexRSGoal,
401407
MachineType: *firstNonEmpty(workerMachineType, machineType),

sdks/go/pkg/beam/runners/dataflow/dataflowlib/job.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type JobOptions struct {
5858
NumWorkers int64
5959
DiskSizeGb int64
6060
DiskType string
61+
DiskProvisionedIOPS int64
62+
DiskProvisionedThroughputMibps int64
6163
MachineType string
6264
Labels map[string]string
6365
ServiceAccountEmail string
@@ -191,6 +193,8 @@ func Translate(ctx context.Context, p *pipepb.Pipeline, opts *JobOptions, worker
191193
},
192194
DiskSizeGb: opts.DiskSizeGb,
193195
DiskType: opts.DiskType,
196+
DiskProvisionedIops: opts.DiskProvisionedIOPS,
197+
DiskProvisionedThroughputMibps: opts.DiskProvisionedThroughputMibps,
194198
IpConfiguration: ipConfiguration,
195199
Kind: "harness",
196200
Packages: packages,

sdks/python/apache_beam/options/pipeline_options.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,26 @@ def _add_argparse_args(cls, parser):
13861386
dest='disk_type',
13871387
default=None,
13881388
help=('Specifies what type of persistent disk should be used.'))
1389+
parser.add_argument(
1390+
'--disk_provisioned_iops',
1391+
type=int,
1392+
default=None,
1393+
dest='disk_provisioned_iops',
1394+
help=(
1395+
'The provisioned IOPS of the disk. If not set, the Dataflow service'
1396+
' will choose a reasonable default.'
1397+
),
1398+
)
1399+
parser.add_argument(
1400+
'--disk_provisioned_throughput_mibps',
1401+
type=int,
1402+
default=None,
1403+
dest='disk_provisioned_throughput_mibps',
1404+
help=(
1405+
'The provisioned throughput of the disk in MiB/s. If not set, the'
1406+
' Dataflow service will choose a reasonable default.'
1407+
),
1408+
)
13891409
parser.add_argument(
13901410
'--worker_region',
13911411
default=None,

sdks/python/apache_beam/options/pipeline_options_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,18 @@ def test_worker_options(self):
444444
'abc',
445445
'--disk_type',
446446
'def',
447+
'--disk_provisioned_iops',
448+
'4000',
449+
'--disk_provisioned_throughput_mibps',
450+
'200',
447451
'--element_processing_timeout_minutes',
448452
'10',
449453
])
450454
worker_options = options.view_as(WorkerOptions)
451455
self.assertEqual(worker_options.machine_type, 'abc')
452456
self.assertEqual(worker_options.disk_type, 'def')
457+
self.assertEqual(worker_options.disk_provisioned_iops, 4000)
458+
self.assertEqual(worker_options.disk_provisioned_throughput_mibps, 200)
453459
self.assertEqual(worker_options.element_processing_timeout_minutes, 10)
454460

455461
options = PipelineOptions(

sdks/python/apache_beam/runners/dataflow/internal/apiclient.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ def __init__(
205205
pool.diskSizeGb = self.worker_options.disk_size_gb
206206
if self.worker_options.disk_type:
207207
pool.diskType = self.worker_options.disk_type
208+
if self.worker_options.disk_provisioned_iops:
209+
pool.diskProvisionedIops = self.worker_options.disk_provisioned_iops
210+
if self.worker_options.disk_provisioned_throughput_mibps:
211+
pool.diskProvisionedThroughputMibps = (
212+
self.worker_options.disk_provisioned_throughput_mibps
213+
)
208214
if self.worker_options.zone:
209215
pool.zone = self.worker_options.zone
210216
if self.worker_options.network:

sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ def test_set_subnetwork(self):
128128
env.proto.workerPools[0].subnetwork,
129129
'/regions/MY/subnetworks/SUBNETWORK')
130130

131+
def test_set_disk_provisioning_options(self):
132+
pipeline_options = PipelineOptions([
133+
'--disk_provisioned_iops',
134+
'4000',
135+
'--disk_provisioned_throughput_mibps',
136+
'200',
137+
'--temp_location',
138+
'gs://any-location/temp',
139+
])
140+
env = apiclient.Environment(
141+
[], # packages
142+
pipeline_options,
143+
'2.0.0', # any environment version
144+
FAKE_PIPELINE_URL,
145+
)
146+
self.assertEqual(env.proto.workerPools[0].diskProvisionedIops, 4000)
147+
self.assertEqual(
148+
env.proto.workerPools[0].diskProvisionedThroughputMibps, 200
149+
)
150+
131151
def test_flexrs_blank(self):
132152
pipeline_options = PipelineOptions(
133153
['--temp_location', 'gs://any-location/temp'])

sdks/python/apache_beam/runners/dataflow/internal/clients/dataflow/dataflow_v1b3_messages.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,11 @@ class FlexTemplateRuntimeEnvironment(_messages.Message):
25832583
zone](https://cloud.google.com/compute/docs/regions-zones/regions-zones)
25842584
for launching worker instances to run your pipeline. In the future,
25852585
worker_zone will take precedence.
2586+
diskProvisionedIops: Provisioned IOPS for the root disk for VMs. If zero or
2587+
unspecified, the service will attempt to choose a reasonable default.
2588+
diskProvisionedThroughputMibps: Provisioned throughput for the root disk
2589+
for VMs. If zero or unspecified, the service will attempt to choose a
2590+
reasonable default.
25862591
"""
25872592
class AutoscalingAlgorithmValueValuesEnum(_messages.Enum):
25882593
r"""The algorithm to use for autoscaling
@@ -2701,6 +2706,10 @@ class AdditionalProperty(_messages.Message):
27012706
workerRegion = _messages.StringField(23)
27022707
workerZone = _messages.StringField(24)
27032708
zone = _messages.StringField(25)
2709+
diskProvisionedIops = _messages.IntegerField(
2710+
26, variant=_messages.Variant.INT64)
2711+
diskProvisionedThroughputMibps = _messages.IntegerField(
2712+
27, variant=_messages.Variant.INT64)
27042713

27052714

27062715
class FloatingPointList(_messages.Message):
@@ -7720,6 +7729,10 @@ class AdditionalProperty(_messages.Message):
77207729
teardownPolicy = _messages.EnumField('TeardownPolicyValueValuesEnum', 20)
77217730
workerHarnessContainerImage = _messages.StringField(21)
77227731
zone = _messages.StringField(22)
7732+
diskProvisionedIops = _messages.IntegerField(
7733+
23, variant=_messages.Variant.INT64)
7734+
diskProvisionedThroughputMibps = _messages.IntegerField(
7735+
24, variant=_messages.Variant.INT64)
77237736

77247737

77257738
class WorkerSettings(_messages.Message):

0 commit comments

Comments
 (0)