Skip to content

Commit

Permalink
Merge branch 'master' into 721-conda-lock-file-may-not-be-rendered-co…
Browse files Browse the repository at this point in the history
…rrectly
  • Loading branch information
munishchouhan authored Dec 13, 2024
2 parents d0237cb + eddc9ee commit 435e277
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ContainerController {
final ip = addressResolver.resolve(httpRequest)
// check the rate limit before continuing
if( rateLimiterService )
rateLimiterService.acquirePull(new AcquireRequest(identity.userId as String, ip))
rateLimiterService.acquirePull(new AcquireRequest(identity.userEmail, ip))
// create request data
final data = makeRequestData(req, identity, ip)
final token = containerService.computeToken(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class RegistryProxyController {

if( route.manifest && route.digest ){
String ip = addressResolver.resolve(httpRequest)
rateLimiterService?.acquirePull( new AcquireRequest(route.identity.userId as String, ip) )
rateLimiterService?.acquirePull( new AcquireRequest(route.identity.userEmail, ip) )
}

// check if it's a container under build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AcquireRequest {
/**
* Principal key to use in the search. Can be null
*/
String userId
String user

/**
* Secondary key to use if principal is not present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ class SpillwayRateLimiter implements RateLimiterService {

@Override
void acquireBuild(AcquireRequest request) throws SlowDownException {
Spillway<String> resource = request.userId ? authsBuilds : anonymousBuilds
String key = request.userId ?: request.ip
Spillway<String> resource = request.user ? authsBuilds : anonymousBuilds
String key = request.user ?: request.ip
if (!resource.tryCall(key)) {
final prefix = request.userId ? 'user' : 'IP'
final prefix = request.user ? 'user' : 'IP'
throw new SlowDownException("Request exceeded build rate limit for $prefix $key")
}
}

@Override
void acquirePull(AcquireRequest request) throws SlowDownException {
Spillway<String> resource = request.userId ? authsPulls : anonymousPulls
String key = request.userId ?: request.ip
Spillway<String> resource = request.user ? authsPulls : anonymousPulls
String key = request.user ?: request.ip
if (!resource.tryCall(key)) {
final prefix = request.userId ? 'user' : 'IP'
final prefix = request.user ? 'user' : 'IP'
throw new SlowDownException("Request exceeded pull rate limit for $prefix $key")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ContainerBuildServiceImpl implements ContainerBuildService, JobHandler<Bui
// check the build rate limit
try {
if( rateLimiterService )
rateLimiterService.acquireBuild(new AcquireRequest(request.identity.userId as String, request.ip))
rateLimiterService.acquireBuild(new AcquireRequest(request.identity.userEmail, request.ip))
}
catch (Exception e) {
buildStore.removeBuild(request.targetImage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RedisFutureHash implements FutureHash<String> {
@Override
void put(String key, String value, Duration expiration) {
try (Jedis conn = pool.getResource()) {
final params = new SetParams().ex(expiration.toSeconds())
final params = new SetParams().px(expiration.toMillis())
conn.set(key, value, params)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PairingWebSocket {
// Register the client and the sender callback that it's needed to deliver
// the message to the remote client
channel.registerClient(service, endpoint, session.id,(pairingMessage) -> {
log.trace "Websocket send message id=$pairingMessage.msgId"
log.trace "Sendind message=${pairingMessage} - endpoint: ${endpoint} [sessionId: $session.id]"
session .sendAsync(pairingMessage)
})

Expand Down
4 changes: 4 additions & 0 deletions src/main/groovy/io/seqera/wave/tower/PlatformId.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class PlatformId {
return user?.id
}

String getUserEmail() {
return user?.email
}

static PlatformId of(User user, SubmitContainerTokenRequest request) {
new PlatformId(
user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ abstract class TowerConnector {
final exec0 = this.ioExecutor
return sendAsync1(endpoint, uri, auth, msgId, true)
.thenCompose { resp ->
log.trace "Tower response for request GET '${uri}' => ${resp.status}"
if( resp.status==200 )
log.trace "Tower response for request GET '${uri}' => ${resp}"
else
log.debug "Tower response for request GET '${uri}' => ${resp}"
switch (resp.status) {
case 200:
return CompletableFuture.completedFuture(JacksonHelper.fromJson(resp.body, type))
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ContainerHelper {
return null
}
catch (Exception e) {
log.warn "Unable to infer conda recipe name - cause: ${e.message}", e
log.warn "Unable to infer conda recipe name - offending content:\n---\n${condaFileContent}", e
return null
}
}
Expand Down
31 changes: 27 additions & 4 deletions src/main/groovy/io/seqera/wave/util/NameVersionPair.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,28 @@ class NameVersionPair {
private static final String SUFFIX = 'pruned'
private static final int MAX = 5

Collection<String> names
Collection<String> versions
private Collection<String> names

private Collection<String> versions

protected NameVersionPair() { }

NameVersionPair(Collection<String> names) {
this.names = names
if( names==null )
throw new IllegalArgumentException("Argument 'names' cannot be null")
if( !names )
throw new IllegalArgumentException("Argument 'names' cannot be empty")
}

NameVersionPair(Collection<String> names, Collection<String> versions) {
this(names)
this.versions = versions
}

Collection<String> getNames() { names }

Collection<String> getVersions() { versions }

private List<String> both() {
final result = new ArrayList()
Expand All @@ -46,8 +66,7 @@ class NameVersionPair {
}

String friendlyNames(String sep='_') {
if( !names )
return null
assert names
if( names.size()<=MAX )
return names.join(sep)
else
Expand All @@ -63,4 +82,8 @@ class NameVersionPair {
else
return new ArrayList<>(ret)[0..MAX-2].join(sep) + sep + SUFFIX
}

boolean asBoolean() {
return names
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,22 @@ class RedisFutureHashTest extends Specification implements RedisTestContainer {
and:
queue.take('xyz') == null
}

def 'should validate expiration' () {
given:
def uid = UUID.randomUUID().toString()
def queue = context.getBean(RedisFutureHash)

when:
queue.put(uid, 'foo', Duration.ofMillis(500))
then:
queue.take(uid) == 'foo'

when:
queue.put(uid, 'bar', Duration.ofMillis(100))
and:
sleep 500
then:
queue.take(uid) == null
}
}
3 changes: 2 additions & 1 deletion src/test/groovy/io/seqera/wave/tower/PlatformIdTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PlatformIdTest extends Specification {

def 'should create form a container request' () {
when:
def id = PlatformId.of(new User(id:1), new SubmitContainerTokenRequest(
def id = PlatformId.of(new User(id:1, email: '[email protected]'), new SubmitContainerTokenRequest(
towerWorkspaceId: 100,
towerEndpoint: 'http://foo.com',
towerAccessToken: 'token-123',
Expand All @@ -53,6 +53,7 @@ class PlatformIdTest extends Specification {
id.workspaceId == 100
id.towerEndpoint == 'http://foo.com'
id.accessToken == 'token-123'
id.userEmail == '[email protected]'
}

def 'should create form a inspect request' () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ class NameVersionPairTest extends Specification {
['a','b','c','d','e','f'] | ['1','2','3','4','5'] | 'a_b_c_d_pruned'
}

def 'should validate truth' () {
expect:
new NameVersionPair(names:['foo'])
and:
!new NameVersionPair(names:null)
!new NameVersionPair(names:[])
}

}

0 comments on commit 435e277

Please sign in to comment.