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

feat(subscriptions): Add create subscriptions RPC #6499

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

shruthilayaj
Copy link
Member

@shruthilayaj shruthilayaj commented Nov 4, 2024

This PR adds a CreateSubscription RPC endpoint. There wasn't a clean way I could split this PR up into smaller chunks so I ended up adding rpc support for the entire the subscriptions pipeline (although a large chunk of it is test coverage).

Copy link

codecov bot commented Nov 4, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2502 1 2501 5
View the top 1 failed tests by shortest run time
tests.subscriptions.test_scheduler_consumer test_scheduler_consumer
Stack Traces | 5.05s run time
Traceback (most recent call last):
  File ".../tests/subscriptions/test_scheduler_consumer.py", line 152, in test_scheduler_consumer
    scheduler._run_once()
  File ".../local/lib/python3.11.../arroyo/processing/processor.py", line 385, in _run_once
    self.__message = self.__consumer.poll(timeout=1.0)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../snuba/subscriptions/scheduler_consumer.py", line 168, in poll
    ).time_shift(self.__time_shift),
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../snuba/subscriptions/utils.py", line 28, in time_shift
    return Tick(
           ^^^^
  File ".../local/lib/python3.11/bdb.py", line 90, in trace_dispatch
    return self.dispatch_line(frame)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../local/lib/python3.11/bdb.py", line 115, in dispatch_line
    if self.quitting: raise BdbQuit
                      ^^^^^^^^^^^^^
bdb.BdbQuit

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

Comment on lines +370 to +373
rounded_ts = (
int(timestamp.replace(tzinfo=UTC).timestamp() / self.time_window_sec)
* self.time_window_sec
)
Copy link
Member Author

@shruthilayaj shruthilayaj Nov 8, 2024

Choose a reason for hiding this comment

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

hack for now, we want to round this to the lowest available granularity (15s) more context here

Comment on lines +348 to +353
if (self.request_name, self.request_version) not in REQUEST_TYPE_ALLOWLIST:
raise InvalidSubscriptionError(
f"{self.request_name} {self.request_version} not supported."
)

# TODO: Validate no group by, having, order by etc
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'll add more validation in a follow up so it's easier to review

@shruthilayaj shruthilayaj marked this pull request as ready for review November 8, 2024 21:29
@shruthilayaj shruthilayaj requested review from a team as code owners November 8, 2024 21:29
Copy link
Member

@volokluev volokluev left a comment

Choose a reason for hiding this comment

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

Why can the create subscription RPC call not be its own PR?

@shruthilayaj
Copy link
Member Author

shruthilayaj commented Nov 8, 2024

Why can the create subscription RPC call not be its own PR?

@volokluev Creating a subscription requires validation, so I needed to build and run the request before storing it. That introduces the RPCSubscriptionData class. And basically once I introduced it in one place, I kinda had to follow all the typing issues and handle it everywhere.

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.

2 participants