Skip to content

Commit

Permalink
fix: resolve PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
astsiapanay committed Sep 19, 2024
1 parent 3e8cc6b commit 705c4ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
31 changes: 15 additions & 16 deletions src/main/java/com/epam/aidial/core/controller/LimitController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,34 @@ public LimitController(Proxy proxy, ProxyContext context) {
}

public Future<?> getLimits(String deploymentId) {

Deployment deployment = context.getConfig().selectDeployment(deploymentId);

Future<Deployment> deploymentFuture;
if (deployment != null) {
if (!DeploymentController.hasAccess(context, deployment)) {
log.error("LimitController. Forbidden deployment {}. Key: {}. User sub: {}", deploymentId, context.getProject(), context.getUserSub());
return context.respond(HttpStatus.FORBIDDEN, "Forbidden deployment: " + deploymentId);
if (DeploymentController.hasAccess(context, deployment)) {
deploymentFuture = Future.succeededFuture(deployment);
} else {
deploymentFuture = Future.failedFuture(new PermissionDeniedException("Forbidden deployment: " + deploymentId));
}
deploymentFuture = Future.succeededFuture(deployment);
} else {
deploymentFuture = proxy.getVertx().executeBlocking(() ->
proxy.getCustomApplicationService().getCustomApplication(deploymentId, context), false);
}

deploymentFuture.compose(dep -> {
if (dep == null) {
String error = String.format("LimitController. Deployment not found %s", deploymentId);
log.error(error);
context.respond(HttpStatus.NOT_FOUND, error);
return Future.succeededFuture();
throw new ResourceNotFoundException("Deployment " + deploymentId + " not found");
}
return proxy.getRateLimiter().getLimitStats(dep, context);
}).onSuccess(limitStats -> {
if (limitStats == null) {
context.respond(HttpStatus.NOT_FOUND);
} else {
context.respond(HttpStatus.OK, limitStats);
}

return proxy.getRateLimiter().getLimitStats(dep, context).onSuccess(limitStats -> {
if (limitStats == null) {
context.respond(HttpStatus.NOT_FOUND);
} else {
context.respond(HttpStatus.OK, limitStats);
}
});
}).onFailure(error -> handleRequestError(deploymentId, error));

return Future.succeededFuture();
}

Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/epam/aidial/core/limiter/RateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.epam.aidial.core.ProxyContext;
import com.epam.aidial.core.config.Deployment;
import com.epam.aidial.core.config.Key;
import com.epam.aidial.core.config.Limit;
import com.epam.aidial.core.config.Role;
import com.epam.aidial.core.data.ItemLimitStats;
Expand Down Expand Up @@ -85,14 +84,7 @@ public Future<LimitStats> getLimitStats(Deployment deployment, ProxyContext cont
if (resourceService == null) {
return Future.succeededFuture();
}
Key key = context.getKey();
Limit limit = getLimitByUser(context, deployment);
if (limit == null) {
log.warn("Limit is not found. Trace: {}. Span: {}. Key: {}. User sub: {}. Deployment: {}",
context.getTraceId(), context.getSpanId(), key == null ? null : key.getProject(),
context.getUserSub(), deployment.getName());
return Future.succeededFuture();
}
return vertx.executeBlocking(() -> getLimitStats(context, limit, deployment.getName()), false);
} catch (Throwable e) {
return Future.failedFuture(e);
Expand Down

0 comments on commit 705c4ce

Please sign in to comment.