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

Support new parser #80

Merged
merged 5 commits into from
Apr 17, 2024
Merged

Support new parser #80

merged 5 commits into from
Apr 17, 2024

Conversation

Sam-Killgallon
Copy link
Contributor

@Sam-Killgallon Sam-Killgallon commented Apr 16, 2024

The new default parser for GraphQL Ruby doesn't call the lex step, but the tests were expecting the lexing_duration to be non-zero. This updates the tests to to match the new behaviour of:

  • Recording the lexing_duration for GraphQL Ruby versions less than 2.2
  • Recording the lexing_duration for GraphQL Ruby versions of 2.2+ if they are using the C parser (which does call lex)
  • lexing_duration being 0 for GraphQL Ruby versions of 2.2+ if they are not using the C parser

I also encountered a bug with tests leaking state due to the pre_context not being reset in all cases.

Repro command:

BUNDLE_GEMFILE=gemfiles/graphql_2.0.gemfile ruby -Itest:lib -Itest -Ilib -e 'require "./test/unit/graphql/metrics/integration_test.rb" ; require "./test/unit/graphql/metrics/trace_integration_test.rb"' -- --seed 5488  -n "/^(?:GraphQL::Metrics::IntegrationTest#(?:test_skips_analysis,_if_the_query_is_semantically_invalid|test_extracts_metrics_from_queries,_as_well_as_their_fields_and_arguments_\(when_using_Query#result\)))$/"

This was caused by the the first test running:

query = GraphQL::Query.new(
  SchemaWithFullMetrics,
  'HELLO',
)

analysis_results = GraphQL::Analysis::AST.analyze_query(query, [SimpleAnalyzer]).first

and the second test running

query = GraphQL::Query.new(
  SchemaWithFullMetrics,
  kitchen_sink_query_document,
  variables: { 'postId': '1', 'titleUpcase': true },
  operation_name: 'PostDetails',
  context: {}
)
result = query.result.to_h

Test 1 triggered the following trace steps:

analyze_query
parse
validate

pre_context is only reset on the analyze_multiplex step, meaning that some data still existed on the following test. This also bypassed the execute_multiplex step so multiplex_start_time doesn't get set to anything, but lexing_duration does get set to 0

When Test 2 ran the tracer we do:

execute_multiplex
parse
validate
analyze_multiplex
analyze_query
execute_query

and hit the check for lexing_duration it was already 0, not nil which meant we didn't overwrite the lexing_start_time_offset causing it to stay at nil, even though we did have a value available.

We run tests against the latest versions of GraphQL, this schedule ensures we
are informed early of any breaking changes
As of GraphQL v2.2 the default ruby parser changed and no longer invokes the
'lex' step in the instrumentation so it will always return 0
Comment on lines +2 to +6
on:
push:
pull_request:
schedule:
- cron: '0 8 * * 1'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a cron here to surface CI failures regularly as GraphQL Ruby changes, rather than only discovering them when making an unrelated PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Would this trigger a notification? Or just a badge refresh on README (which looks broken to me)

Copy link
Contributor Author

@Sam-Killgallon Sam-Killgallon Apr 16, 2024

Choose a reason for hiding this comment

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

https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/notifications-for-workflow-runs A notification but only to the creator of the workflow.

Which badge in the readme are you referring to? I don't see one for this repo.

EDIT: Ah I misunderstood you mean that the badge is currently broken, which is why I can't see it

@Sam-Killgallon Sam-Killgallon marked this pull request as ready for review April 16, 2024 13:04
@Sam-Killgallon Sam-Killgallon self-assigned this Apr 16, 2024
Comment on lines +2 to +6
on:
push:
pull_request:
schedule:
- cron: '0 8 * * 1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this trigger a notification? Or just a badge refresh on README (which looks broken to me)

Comment on lines 133 to 139
def capture_validation_time(context)
# Queries may already be lexed and parsed before execution (whether a single query or multiplex).
# If we don't have those values, use some sane defaults.
if pre_context.lexing_duration.nil?
if [nil, 0].include?(pre_context.lexing_duration)
pre_context.lexing_start_time_offset = pre_context.multiplex_start_time
pre_context.lexing_duration = 0.0
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should just skip all this conditional for lexing/parsing and default the durations to 0.0 to start with and fallback to multiplex_start_time if neither of the start times exist.

Then the test helper wouldn't be needed either?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably ignore this for now tbh, let's just focus on fixing the immediate issue

Comment on lines 133 to 139
def capture_validation_time(context)
# Queries may already be lexed and parsed before execution (whether a single query or multiplex).
# If we don't have those values, use some sane defaults.
if pre_context.lexing_duration.nil?
if [nil, 0].include?(pre_context.lexing_duration)
pre_context.lexing_start_time_offset = pre_context.multiplex_start_time
pre_context.lexing_duration = 0.0
end
Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably ignore this for now tbh, let's just focus on fixing the immediate issue

@Sam-Killgallon Sam-Killgallon merged commit ad0bede into main Apr 17, 2024
27 checks passed
@Sam-Killgallon Sam-Killgallon deleted the support-new-parser branch April 17, 2024 10:37
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.

3 participants