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

Update Source interface to use SourceID and JobID types #1774

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

mcastorina
Copy link
Collaborator

@mcastorina mcastorina commented Sep 13, 2023

Description:

The previous implementation used int64 for both, which can be mixed up easily. Using distinct types adds a layer of type safety checked by the compiler.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

The previous implementation used int64 for both, which can be mixed up
easily. Using distinct types adds a layer of type safety checked by the
compiler.
@@ -123,7 +123,7 @@ func (s *Source) InjectConnection(conn *sourcespb.Syslog) {
}

// Init returns an initialized Syslog source.
func (s *Source) Init(_ context.Context, name string, jobId, sourceId int64, verify bool, connection *anypb.Any, concurrency int) error {
func (s *Source) Init(_ context.Context, name string, jobId sources.JobID, sourceId sources.SourceID, verify bool, connection *anypb.Any, concurrency int) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: any reason sometimes it's jobID like in line 52 and sometimes it's jobId?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, just ambiguity in what "camel case" means. I asked Ahrav at one point and the official Google style guide recommends jobID, so I tend to use that.

https://google.github.io/styleguide/go/decisions#initialisms

I'll make a followup PR to update the variable names, since this PR is just updating the types.

@@ -111,7 +111,7 @@ func (c *persistableCache) shouldPersist() (bool, string) {
}

// Init returns an initialized GCS source.
func (s *Source) Init(aCtx context.Context, name string, id int64, sourceID int64, verify bool, connection *anypb.Any, concurrency int) error {
func (s *Source) Init(aCtx context.Context, name string, id sources.JobID, sourceID sources.SourceID, verify bool, connection *anypb.Any, concurrency int) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same question as jobID - looks like sometimes we use sourceID and sometimes it's sourceId. should this be standardized or do we use them for different purposes?

Copy link
Contributor

@0x1 0x1 left a comment

Choose a reason for hiding this comment

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

when you say the implementation of int64 can be mixed up easily, do you mean by humans - or is there some Go thing that can happen? and what kind of additional type safety do we get beyond when it's just int64?

(other than the question^ and nits looks solid)

@mcastorina
Copy link
Collaborator Author

when you say the implementation of int64 can be mixed up easily, do you mean by humans - or is there some Go thing that can happen? and what kind of additional type safety do we get beyond when it's just int64?

Yeah, by humans. Making them distinct types will allow the compiler to catch accidentally using a job ID as a source ID or vice versa.

func Foo(sourceID int64, jobID int64)
func Bar(sourceID SourceID, jobID JobID)

Foo(jobID, sourceID) // no problemo (jobID and sourceID are both int64)
Bar(jobID, sourceID) // problemo (jobID and sourceID are distinct types)

@mcastorina mcastorina merged commit dbcb888 into main Sep 14, 2023
@mcastorina mcastorina deleted the source-job-ids branch September 14, 2023 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants