Skip to content

Commit

Permalink
Add logging for throttling and guardrail in connector (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#2725)

Signed-off-by: b4sjoo <sicheng.song@outlook.com>
  • Loading branch information
b4sjoo authored Jul 24, 2024
1 parent cf9ed90 commit 8f16080
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,20 @@ default void preparePayloadAndInvoke(
.getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
User user = User.parse(userStr);
if (getRateLimiter() != null && !getRateLimiter().request()) {
getLogger().error("Request is throttled at model level.");
throw new OpenSearchStatusException("Request is throttled at model level.", RestStatus.TOO_MANY_REQUESTS);
} else if (user != null
&& getUserRateLimiterMap() != null
&& getUserRateLimiterMap().get(user.getName()) != null
&& !getUserRateLimiterMap().get(user.getName()).request()) {
getLogger().error("Request is throttled at user level.");
throw new OpenSearchStatusException(
"Request is throttled at user level. If you think there's an issue, please contact your cluster admin.",
RestStatus.TOO_MANY_REQUESTS
);
} else {
if (getMlGuard() != null && !getMlGuard().validate(payload, MLGuard.Type.INPUT, parameters)) {
getLogger().error("guardrails triggered for user input");
throw new IllegalArgumentException("guardrails triggered for user input");
}
if (getConnectorClientConfig().getMaxRetryTimes() != 0) {
Expand Down

0 comments on commit 8f16080

Please sign in to comment.