Skip to content

Refactor project layout and add remote write control#7

Merged
Suhaibinator merged 2 commits intomainfrom
codex/refactor-repo-structure-and-improve-configurability
May 17, 2025
Merged

Refactor project layout and add remote write control#7
Suhaibinator merged 2 commits intomainfrom
codex/refactor-repo-structure-and-improve-configurability

Conversation

@Suhaibinator
Copy link
Owner

@Suhaibinator Suhaibinator commented May 17, 2025

Summary

  • move main to cmd/smq
  • move server code under internal/server
  • allow disabling remote write calls with ALLOW_REMOTE_WRITES and --allow-remote-writes
  • document new configuration
  • enable remote writes in tests

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the project layout while adding support for controlling remote write operations via a new configuration flag and environment variable. Key changes include moving server code under internal/server, introducing the ALLOW_REMOTE_WRITES configuration (and corresponding command-line flag), and updating tests and documentation to reflect this new feature.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/server/server_test.go Updated import path and set allowRemoteWrites to true in tests.
internal/server/server.go Added allowRemoteWrites flag checks to restrict remote write operations.
errors/errors.go Added a new error constant for disabled remote writes.
config/configuration.go Introduced configuration constant and variable for remote writes.
cmd/smq/main.go Included a new flag/option to control remote write operations.
README.md Documented the new remote writes configuration option.

Comment on lines 37 to +40
func (s *Server) Produce(ctx context.Context, pr *pb.ProduceRequest) (*pb.ProduceResponse, error) {
if !s.allowRemoteWrites {
return nil, smqerrors.ErrRemoteWritesDisabled
}
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider abstracting the remote write permission check into a helper function to avoid repetitive code across multiple endpoints.

Suggested change
func (s *Server) Produce(ctx context.Context, pr *pb.ProduceRequest) (*pb.ProduceResponse, error) {
if !s.allowRemoteWrites {
return nil, smqerrors.ErrRemoteWritesDisabled
}
func (s *Server) checkRemoteWritePermission() error {
if !s.allowRemoteWrites {
return smqerrors.ErrRemoteWritesDisabled
}
return nil
}
func (s *Server) Produce(ctx context.Context, pr *pb.ProduceRequest) (*pb.ProduceResponse, error) {
if err := s.checkRemoteWritePermission(); err != nil {
return nil, err
}

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Suhaibinator Suhaibinator merged commit 5f2431e into main May 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments