Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/nf-google/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {
api 'com.google.cloud:google-cloud-logging:3.23.5'
api 'com.google.cloud:google-cloud-nio:0.128.5'
api 'com.google.cloud:google-cloud-storage:2.58.0'

api 'io.seqera:lib-cloudinfo:1.0.0'
Comment thread
pditommaso marked this conversation as resolved.
// Force patched version to address CVE-2025-55163 (MadeYouReset HTTP/2 DDoS vulnerability)
runtimeOnly 'io.grpc:grpc-netty-shaded:1.75.0'
// Force patched version to address GHSA-72hv-8253-57qq (jackson-core Number Length Constraint Bypass DoS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package nextflow.cloud.google.batch

import io.seqera.cloudinfo.api.CloudPrice
import io.seqera.cloudinfo.client.CloudInfoClient

import java.math.RoundingMode

import groovy.json.JsonSlurper
import groovy.transform.CompileStatic
import groovy.transform.Immutable
import groovy.transform.Memoized
Expand All @@ -42,8 +44,6 @@ class GoogleBatchMachineTypeSelector {

static GoogleBatchMachineTypeSelector INSTANCE = new GoogleBatchMachineTypeSelector()

private static final CLOUD_INFO_API = "https://cloudinfo.seqera.io/api/v1"

/*
* Some families CPUs are faster so this is a cost correction factor
* for processes that request more than 2 CPUs or 2GB, smaller processes
Expand Down Expand Up @@ -101,6 +101,12 @@ class GoogleBatchMachineTypeSelector {
*/
private static final List<String> PARTIAL_LOCAL_SSD_SUPPORT_FAMILIES = ['c3-*', 'c3a-*', 'c3d-*', 'c4-*', 'c4a-*', 'c4d-*', 'h4d-*', 'z3-*']

private CloudInfoClient cloudInfo

GoogleBatchMachineTypeSelector(){
cloudInfo = CloudInfoClient.create()
}

@Immutable
static class MachineType {
String type
Expand Down Expand Up @@ -170,16 +176,14 @@ class GoogleBatchMachineTypeSelector {
@Memoized
protected List<MachineType> getAvailableMachineTypes(String region, boolean spot) {
final priceModel = spot ? PriceModel.spot : PriceModel.standard
final json = "${CLOUD_INFO_API}/providers/google/services/compute/regions/${region}/products".toURL().text
final data = new JsonSlurper().parseText(json)
final products = data['products'] as List<Map>
final averageSpotPrice = (List<Map> prices) -> prices ? prices.collect{it.price as float}.average() as float : 0.0f
final products = cloudInfo.getProducts('google', region)
final averageSpotPrice = (List<CloudPrice> prices) -> prices ? prices.collect{it.price as float}.average() as float : 0.0f

products.collect {
new MachineType(
type: it.type,
family: it.type.toString().split('-')[0],
spotPrice: averageSpotPrice(it.spotPrice as List<Map>),
spotPrice: averageSpotPrice(it.spotPrice as List<CloudPrice>),
onDemandPrice: it.onDemandPrice as float,
cpusPerVm: it.cpusPerVm as int,
memPerVm: it.memPerVm as int,
Expand Down
Loading