Skip to content

Commit

Permalink
Add logging for throttling and guardrail in connector (#2725) (#2727) (
Browse files Browse the repository at this point in the history
…#3047)

Signed-off-by: b4sjoo <[email protected]>
(cherry picked from commit 8f16080)

Co-authored-by: Sicheng Song <[email protected]>
(cherry picked from commit ce6b36c)

Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] authored Oct 2, 2024
1 parent 1771ac6 commit dddb218
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 dddb218

Please sign in to comment.