Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#269 - this adds instrumentation to the execution of the graphql query #270

Merged

Conversation

bbakerman
Copy link
Member

as per #269 the desire here is to be able to measure how long a graphql query is taken

This approach of "return call back " allows for a fairly stateless system if we have multi threaded execution.

So you can "create a timer and then have the end time - start time be calculated via this created object.

this.graphQLSchema = graphQLSchema;
this.executionStrategy = executionStrategy;
this.instrumentation = instrumentation;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Yet more constructors is an anti pattern I know. I think GraphQL needs a builder

  GraphQL graphQL = GraphQL.builder(schema).
      .strategy(x)
      .instrumentation(y)
      .build()

That way the API can be evolved more easily without breaking existing client or adding yet more overloaded methods / constructors


public Execution(ExecutionStrategy strategy) {
this.strategy = strategy;
public Execution(ExecutionStrategy strategy, Instrumentation instrumentation) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think may of the classes in the package should be package private and hence not API.

This will allow better evolution of the implementation without breaking people. For example I dont think any consumers should be able to create this class. Its really an implementation class

@@ -13,6 +15,7 @@

public class ExecutionContext {

private final Instrumentation instrumentation;
private GraphQLSchema graphQLSchema;
Copy link
Member Author

Choose a reason for hiding this comment

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

The other variables in this class should be final. The setters are an anti pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

#263 outlines this. Immutability for the win

@@ -0,0 +1,77 @@
package graphql.execution.instrumentation;
Copy link
Member Author

Choose a reason for hiding this comment

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

InstrumentationContext allows for callback that are site specific and not casting of Object is needed. eg the parse call back gets the parsed document

* @param arguments the arguments in play
* @return a non null {@link InstrumentationContext} object that will be called back when the step ends
*/
InstrumentationContext<Document> beginParse(String requestString, String operationName, Object context, Map<String, Object> arguments);
Copy link
Member Author

Choose a reason for hiding this comment

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

Having Document passed back and String requestString, String operationName, Object context, Map<String, Object> arguments is a contentious design

On the one hand this allows you to SPY on every thing as it happens and that could be great for better instrumentation.

On the other hand it means the parameters are no API and cant easily be changed.

I think we either do NONE or have a Builder of InstrumentationParseParameters so we can add extra parameters in the future. In fact as I type... this is what I think it should be.

Or.... we have a Map<String,Object> arangement which is not at all type safe but infinitely extendable. Its quasi secret information and might change at any time.

Thoughts?

* @param document the GraphQL query string
* @return a non null {@link InstrumentationContext} object that will be called back when the step ends
*/
InstrumentationContext<List<ValidationError>> beginValidation(Document document);
Copy link
Member Author

Choose a reason for hiding this comment

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

Same thougths here - Should document be API?

… and hence makes it less brittle for future changes
… and hence makes it less brittle for future changes. Hmm missed test commit
@@ -4,14 +4,34 @@
import graphql.ExecutionResult;
Copy link
Member Author

Choose a reason for hiding this comment

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

There are no code hygeine rules for the project so I let IDEA do its full import behaviour of .* imports. This is what we use here in Atlassian and I am a fan of it.

import graphql.language.Document;

import java.util.Map;

Copy link
Member Author

Choose a reason for hiding this comment

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

Having Document as API is the most contentious parameter in my book

@bbakerman bbakerman merged commit 5774291 into graphql-java:master Mar 3, 2017
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.

None yet

1 participant