Skip to content

Comments

Added support for async create state in instrumentmentations#3302

Merged
bbakerman merged 1 commit intomasterfrom
async-create-state
Aug 27, 2023
Merged

Added support for async create state in instrumentmentations#3302
bbakerman merged 1 commit intomasterfrom
async-create-state

Conversation

@bbakerman
Copy link
Member

createState() today is a sync call. but if you had to call some remote system to get state setup then you need a CF to represent this

This PR changes create state to be a async call

@bbakerman bbakerman added this to the 2023 October milestone Aug 25, 2023
logNotSafe.debug("Executing request. operation name: '{}'. query: '{}'. variables '{}'", executionInput.getOperationName(), executionInput.getQuery(), executionInput.getVariables());
}
executionInput = ensureInputHasId(executionInput);
ExecutionInput executionInputWithId = ensureInputHasId(executionInput);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not effectivly final so we use new variable names

CompletableFuture<ExecutionResult> beginExecutionCF = new CompletableFuture<>();
InstrumentationExecutionParameters instrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState);
InstrumentationContext<ExecutionResult> executionInstrumentation = nonNullCtx(instrumentation.beginExecution(instrumentationParameters, instrumentationState));
executionInstrumentation.onDispatched(beginExecutionCF);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this moves into the thenCompose() of state creation

@Override
public @Nullable InstrumentationState createState(InstrumentationCreateStateParameters parameters) {
return Assert.assertShouldNeverHappen("createStateAsync should only ever be used");
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it moved but it didnt

Async.CombinedBuilder<InstrumentationState> builder = Async.ofExpectedSize(instrumentations.size());
for (Instrumentation instrumentation : instrumentations) {
// state can be null including the CF so handle that
CompletableFuture<InstrumentationState> stateCF = Async.orNullCompletedFuture(instrumentation.createStateAsync(parameters));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we allow null to come back from instrumentation states inline with how it was able to be null before so we have Async.orNullCompletedFuture to handle this

@bbakerman bbakerman added this pull request to the merge queue Aug 27, 2023
Merged via the queue into master with commit 1ad3562 Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant