Skip to content

Parse supergraph schema early to avoid re-parsing#5736

Merged
SimonSapin merged 2 commits intodevfrom
simon/early-schema
Jul 30, 2024
Merged

Parse supergraph schema early to avoid re-parsing#5736
SimonSapin merged 2 commits intodevfrom
simon/early-schema

Conversation

@SimonSapin
Copy link
Contributor

@SimonSapin SimonSapin commented Jul 29, 2024

As discussed in #5623 (comment)

This may may startup and reload slightly faster for large schemas, but more importantly it makes spec::Schema available in more places which will help upcoming changes for Rust replatforming.


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

@SimonSapin SimonSapin requested review from a team and Geal July 29, 2024 12:54
@SimonSapin SimonSapin requested a review from a team as a code owner July 29, 2024 12:54
@github-actions
Copy link
Contributor

@SimonSapin, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

@router-perf
Copy link

router-perf bot commented Jul 29, 2024

CI performance tests

  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

@SimonSapin SimonSapin enabled auto-merge (squash) July 30, 2024 12:27
@SimonSapin SimonSapin disabled auto-merge July 30, 2024 12:29
@SimonSapin SimonSapin enabled auto-merge (squash) July 30, 2024 12:30
@SimonSapin SimonSapin merged commit b96224c into dev Jul 30, 2024
@SimonSapin SimonSapin deleted the simon/early-schema branch July 30, 2024 14:51
),
))
.supergraph_sdl(schema.raw_sdl.clone())
.supergraph_schema(Arc::new(schema.supergraph_schema().clone()))
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we creating a new Arc here? the supergraph_schema method returns a &Valid<FederationSchema> but the struct we get it from already has an Arc:

pub struct ValidFederationSchema {
    schema: Arc<Valid<FederationSchema>>,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arc<Valid<FederationSchema>> contains a apollo_compiler::Schema together with other data, so get an Arc<Valid<apollo_compiler::Schema>> we need a new Arc.

I previously tried to change FederationSchema to contain an Arc, but that clashes with code that mutates schemas a lot (namely extract subgraph schemas from supergraph, and eventually composition). Maybe we apollo-federation should have separate types for mutable v.s. immutable schemas, but that’s larger change.

pub(crate) fn build(
configuration: &Configuration,
schema: &apollo_compiler::ast::Document,
schema: &Schema,
Copy link
Contributor

Choose a reason for hiding this comment

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

nice :)

Comment on lines -217 to -226
for subgraph_url in schema
.definitions
.iter()
.filter_map(|def| def.as_enum_type_definition())
.filter(|def| def.name == "join__Graph")
.flat_map(|def| def.values.iter())
.flat_map(|val| val.directives.iter())
.filter(|d| d.name == "join__graph")
.filter_map(|dir| (dir.arguments.iter().find(|arg| arg.name == "url")))
.filter_map(|arg| arg.value.as_str())
Copy link
Contributor

Choose a reason for hiding this comment

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

that code can finally be deleted :)
(BTW could youmerge after the connectors PR? This part will conflict with it, because there's some connectors specific code in license enforcement)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Auto-merge happened before I saw this, sorry! Is connectors merging very soon? If this PR is an obstacle it could be reverted long enough to merge connectors and I’ll manage the conflict later.

Copy link
Contributor

Choose a reason for hiding this comment

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

This PR was merged to dev but not forward ported to next, right?

}


directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
Copy link
Contributor

Choose a reason for hiding this comment

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

is that (and other schema changes) to convert to fed 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, previously some of these files had just enough Federation boilerplate to be able to parse as AST and go through license_enforcement.rs. Now they have enough to validate as well, but fed 1 vs fed 2 is unchanged.

.directives
.get_all(LINK_DIRECTIVE_NAME)
.filter_map(|link| {
ParsedLinkSpec::from_link_directive(link).map(|maybe_spec| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be replaced with something from apollo-federation? (Through schema.federation_supergraph().schema.metadata())

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