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

Make -> method registration more flexible and type-safe #6455

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Dec 13, 2024

Previously, -> methods (#5762) were implemented as functions and registered in a lazy_static! map for dynamic lookup at runtime.

This PR refactors the system for registering methods, so there is now an ArrowMethod enum with a variant for each known method, and each method is now represented by a struct type that has an ::apply method, whose signature resembles the previous function implementations.

In the future, we can add other methods to these structs, so -> methods can programmatically define their interactions with the output shape of the JSONSelection, for example.

@benjamn benjamn self-assigned this Dec 13, 2024
@benjamn benjamn requested a review from a team as a code owner December 13, 2024 20:55
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Dec 13, 2024

✅ Docs Preview Ready

No new or changed pages found.

@router-perf
Copy link

router-perf bot commented Dec 13, 2024

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • 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

@benjamn benjamn force-pushed the benjamn/JSONSelection-ArrowMethod-refactor branch from 8f4c23d to 62775ad Compare December 16, 2024 18:23
Copy link
Member

@dylan-apollo dylan-apollo left a comment

Choose a reason for hiding this comment

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

Very excited for the enum!!! My only suggestion is that maybe strum would make to/from name conversions easier? But also maybe not...

// This Deref implementation allows us to call .apply(...) directly on the
// ArrowMethod enum.
impl std::ops::Deref for ArrowMethod {
type Target = dyn ArrowMethodImpl;
Copy link
Member

Choose a reason for hiding this comment

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

Oh nice, don't think I've ever done a dyn Deref before, good to know that's possible.

Comment on lines +134 to +137
// As this case suggests, we can't necessarily provide a name()
// method for ArrowMethod (the opposite of lookup), because method
// implementations can be used under multiple names.
"matchIf" | "match_if" => Some(Self::MatchIf),
Copy link
Member

Choose a reason for hiding this comment

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

We could make the design decision not to have multiple names, though. Seems like we should standardize on camelCase and not snake_case.

That would also mean we could use strum to impl both FromStr and Display for all the methods without all the boilerplate.

Copy link
Member

Choose a reason for hiding this comment

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

I guess strum would make it harder to do the public/future split. Might end up having to add a #[cfg(test)] to every future method...

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'm open to ideas, though not previously familiar with strum.

I'd be ok with sticking to one method name/style, but I think it's worthwhile to keep passing method_name as an argument into the method apply/shape implementations, so there's only one spot in the code we need to change if we want to rename a method (compared to each method implicitly "knowing" its own name and encoding it into error messages, for example).

Copy link
Member

Choose a reason for hiding this comment

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

For sure. I thought about suggesting that the macro could inject the name, but I think we still want location data down in the implementation so it wouldn't save us much.

@benjamn benjamn merged commit bf03ba7 into next Dec 16, 2024
12 checks passed
@benjamn benjamn deleted the benjamn/JSONSelection-ArrowMethod-refactor branch December 16, 2024 19:09
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.

4 participants