Skip to content

Commit

Permalink
some log updates from comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt committed Dec 20, 2023
1 parent a9521eb commit 0d0d4d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ protected void doExecute(Task task, CreateInteractionRequest request, ActionList
ActionListener<CreateInteractionResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
ActionListener<String> al = ActionListener.wrap(iid -> {
cmHandler.updateConversation(cid, new HashMap<>(), getUpdateResponseListener(cid, iid, internalListener));
// internalListener.onResponse(new CreateInteractionResponse(iid));
}, e -> { internalListener.onFailure(e); });
if (parintIid == null || traceNumber == null) {
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al);
Expand All @@ -119,14 +118,14 @@ private ActionListener<UpdateResponse> getUpdateResponseListener(
return ActionListener.wrap(updateResponse -> {
if (updateResponse != null && updateResponse.getResult() == DocWriteResponse.Result.UPDATED) {
log
.info(
.debug(
"Successfully updated the Conversation with ID: {} after interaction {} is created",
conversationId,
interactionId
);
actionListener.onResponse(new CreateInteractionResponse(interactionId));
} else {
log.info("Failed to update the Conversation with ID: {} after interaction {} is created", conversationId, interactionId);
log.error("Failed to update the Conversation with ID: {} after interaction {} is created", conversationId, interactionId);
actionListener.onResponse(new CreateInteractionResponse(interactionId));
}
}, exception -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.opensearch.client.Requests;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.commons.ConfigConstants;
import org.opensearch.commons.authuser.User;
import org.opensearch.core.action.ActionListener;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.ExistsQueryBuilder;
Expand Down Expand Up @@ -144,11 +146,17 @@ public void getFinalInteractions(String conversationId, int lastNInteraction, Ac
if (access) {
innerGetFinalInteractions(conversationId, lastNInteraction, actionListener);
} else {
throw new OpenSearchSecurityException("User does not have access to conversation " + conversationId);
String userstr = client
.threadPool()
.getThreadContext()
.getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
String user = User.parse(userstr) == null ? "" : User.parse(userstr).getName();
throw new OpenSearchSecurityException("User [" + user + "] does not have access to conversation " + conversationId);
}
}, e -> { actionListener.onFailure(e); });
conversationMetaIndex.checkAccess(conversationId, accessListener);
} catch (Exception e) {
log.error("Failed to get final interactions for conversation " + conversationId, e);
actionListener.onFailure(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ public void testGetInteractions_NoAccessNoUser_ThenFail() {
mlMemoryManager.getFinalInteractions("cid", 10, interactionListActionListener);
ArgumentCaptor<Exception> argCaptor = ArgumentCaptor.forClass(Exception.class);
verify(interactionListActionListener, times(1)).onFailure(argCaptor.capture());
assert (argCaptor.getValue().getMessage().equals("User does not have access to conversation cid"));
System.out.println(argCaptor.getValue().getMessage());
assert (argCaptor.getValue().getMessage().equals("User [] does not have access to conversation cid"));
}

@Test
Expand Down

0 comments on commit 0d0d4d7

Please sign in to comment.