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

chore(refactor): create timeline package in controller #2674

Merged
merged 2 commits into from
Sep 14, 2024

Conversation

wesbillman
Copy link
Collaborator

Shouldn't change any functionality just creating a new package for the timeline since it's has a bunch of code and we'll be adding many more event types in the near future.

@wesbillman wesbillman added the run-all A PR with this label will run the full set of CI jobs in the PR rather than in the merge queue label Sep 13, 2024
@wesbillman wesbillman requested review from a team, jonathanj-square and deniseli and removed request for a team September 13, 2024 21:42
This was referenced Sep 13, 2024
'log',
sqlc.arg('payload')
);

-- name: InsertTimelineDeploymentCreatedEvent :exec
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to remove these as well, but they are used in a transaction in the controller/dal and I didn't want to break that functionality for now. We could insert the timeline event after the transaction as well, which might be cleaner, but would slightly decouple the event from the action, just slightly though :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely pull them out into a separate .sql file, and just add them to the controller/dal sql gen, like here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok I think I did this correctly, but please lemme know if I'm off the rails :)

)

type Service struct {
dal dal.DAL
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should just be a pointer like it is everywhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops!

Comment on lines 57 to 58
Response optional.Option[*ftlv1.CallResponse]
CallError optional.Option[error]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could use an either here, which might make it a bit clearer:

Suggested change
Response optional.Option[*ftlv1.CallResponse]
CallError optional.Option[error]
Response either.Either[*ftlv1.CallResponse, error]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh neat! I didn't know about either

return nil
}

func (s *Service) QueryTimeline(ctx context.Context, limit int, filters ...dal.TimelineFilter) ([]dal.TimelineEvent, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally I think we wouldn't be exposing dal types directly here, but in practice I think that would be difficult to achieve.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I agree. I was torn here since it would be a bit of duplication. maybe as I add more to the timeline it will make sense to fully decouple. I'll keep an eye on it

@wesbillman wesbillman force-pushed the create-timeline-package-in-controller branch from c0a146c to df981d8 Compare September 14, 2024 02:12
sqlc.yaml Outdated
type: "optional.Option[time.Time]"
- db_type: "pg_catalog.interval"
go_type: "github.com/TBD54566975/ftl/backend/controller/sql/sqltypes.Duration"
- db_type: "pg_catalog.interval"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't want to duplicate these types, just keep all the type mappings in the root overrides.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I must be doing something weird because if I don't have these it seems like the code won't build anymore. Seems like stuff generates like this:

type InsertTimelineCallEventParams struct {
	DeploymentKey    interface{}
	RequestKey       sql.NullString
	ParentRequestKey sql.NullString
	TimeStamp        time.Time
	SourceModule     sql.NullString
	SourceVerb       sql.NullString
	DestModule       string
	DestVerb         string
	Payload          encryption.EncryptedTimelineColumn
}

Instead of optional.Option[string] for example. Maybe I need another change for the sqlc config

Copy link
Collaborator

Choose a reason for hiding this comment

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

I dunno. I deleted it, merged it, and everything compiled fine... 🤷‍♂️

@alecthomas alecthomas force-pushed the create-timeline-package-in-controller branch from 61abf6d to 6bc23c1 Compare September 14, 2024 23:13
@alecthomas alecthomas force-pushed the create-timeline-package-in-controller branch from a61c517 to dd41626 Compare September 14, 2024 23:18
@alecthomas alecthomas force-pushed the create-timeline-package-in-controller branch from dd41626 to 63c99e0 Compare September 14, 2024 23:22
@alecthomas alecthomas added this pull request to the merge queue Sep 14, 2024
Merged via the queue into main with commit 88fb90c Sep 14, 2024
89 checks passed
@alecthomas alecthomas deleted the create-timeline-package-in-controller branch September 14, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-all A PR with this label will run the full set of CI jobs in the PR rather than in the merge queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants