Skip to content

added missing call to onDispatched for instrumentation context of beginExecution - resolves #1620 - #2722

Closed
bsara wants to merge 1 commit into
graphql-java:masterfrom
bsara:issue-1620-add-missing-onDispatched
Closed

bsara wants to merge 1 commit into
graphql-java:masterfrom
bsara:issue-1620-add-missing-onDispatched

Conversation

@bsara

@bsara bsara commented Feb 10, 2022 •

Copy link
Copy Markdown

Added a call to onDispatched for the beginExecution instrumentation context.

resolves #1620

@bsara
bsara force-pushed the issue-1620-add-missing-onDispatched branch from c24a1a1 to c9cc5ab Compare February 10, 2022 20:11
Comment thread src/main/java/graphql/GraphQL.java Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this fix - it is indeed missing. But its slightly wrong in this fix

Tthis should be before the method parseValidateAndExecute

The idea of onDispacthed is indicate that an instrumented stage is now really underway with a CF promise to it being completed.

With a sync process like this it should be immediately after its called. That is its dispatched immediately. Near zero nanos later.

It should be this

    public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionInput) {
        try {
            if (logNotSafe.isDebugEnabled()) {
                logNotSafe.debug("Executing request. operation name: '{}'. query: '{}'. variables '{}'", executionInput.getOperationName(), executionInput.getQuery(), executionInput.getVariables());
            }
            executionInput = ensureInputHasId(executionInput);

            InstrumentationState instrumentationState = instrumentation.createState(new InstrumentationCreateStateParameters(this.graphQLSchema, executionInput));

            InstrumentationExecutionParameters inputInstrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState);
            executionInput = instrumentation.instrumentExecutionInput(executionInput, inputInstrumentationParameters);


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

            GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters);

            CompletableFuture<ExecutionResult> executionResult = parseValidateAndExecute(executionInput, graphQLSchema, instrumentationState);
            //
            // finish up instrumentation
            executionResult = executionResult.whenComplete(executionInstrumentation::onCompleted);
            //
            // allow instrumentation to tweak the result
            executionResult = executionResult.thenCompose(result -> instrumentation.instrumentExecutionResult(result, instrumentationParameters));
            executionResult = executionResult.whenComplete((result,throwable) -> {
                if (throwable != null) {
                    beginExecutionCF.completeExceptionally(throwable);
                } else {
                    beginExecutionCF.complete(result);
                }
                executionInstrumentation.onDispatched(beginExecutionCF);
            });
            return executionResult;
        } catch (AbortExecutionException abortException) {
            return CompletableFuture.completedFuture(abortException.toExecutionResult());
        }

That is its dispatched IMMEDIATELY and the CF given on that is completed at the end

Can you change your PR and take this code please. This is the right fix

this will change the test below

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Awesome. I'll make the change. Thank you for the quick turn around.

@bsara bsara Feb 11, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can't seem to get the tests to run locally for me (something with the gradle daemon). Could I get approval for this to run the tests? I don't want to move this from draft status until I can successfully test it, of course.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tend to run the tests inside IDEA - albeit .gradlew clean build also works for me

I have approved the build and hence the github actions will run the builds

@bsara
bsara force-pushed the issue-1620-add-missing-onDispatched branch from c9cc5ab to 04a944c Compare February 11, 2022 22:42
beginExecutionCF.complete(result);
}
executionInstrumentation.onCompleted(result, throwable);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah that is better than what I proposed

@bbakerman

Copy link
Copy Markdown
Member

SubscriptionExecutionStrategyTest > instrumentation gets called on subscriptions FAILED
ChainedInstrumentationStateTest > basic chaining and state management FAILED
InstrumentationTest > Instrumentation of simple serial execution FAILED
PreparsedDocumentProviderTest > Preparse of simple serial execution FAILED

Lots of tests that assert instrument test call chain are failing. You really need to work out your local test env to runs tests

@bbakerman

Copy link
Copy Markdown
Member

Or just keep commiting and allow github to run them

@bsara

bsara commented Feb 14, 2022

Copy link
Copy Markdown
Author

I'll get it running locally.

@bbakerman

Copy link
Copy Markdown
Member

See #2730

@bbakerman bbakerman closed this Feb 17, 2022
@bbakerman

Copy link
Copy Markdown
Member

Thanks for the original PR - I took it and tweaked it a little and fixed the tests

@bsara

bsara commented Feb 18, 2022

Copy link
Copy Markdown
Author

@bbakerman Awesome! thanks so much, sorry that I wasn't able to finish it off faster, I got pulled onto some other things for a bit.

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.

InstrumentationContext onDispatched not called for parsing

2 participants