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

Added event feeds to the baton SDK #92

Merged
merged 22 commits into from
Jan 26, 2024
Merged

Conversation

notanthony
Copy link
Contributor

No description provided.

@loganintech loganintech changed the title Anthony/logan/event feeds Added event feeds to the baton SDK Jan 11, 2024
@loganintech loganintech marked this pull request as ready for review January 11, 2024 00:23
@loganintech loganintech requested a review from jirwin as a code owner January 11, 2024 00:23
@@ -44,7 +44,7 @@ func (m *localRevoker) Process(ctx context.Context, task *v1.Task, cc types.Conn
return nil
}

// NewGranter returns a task manager that queues a sync task.
// NewRevoker returns a task manager that queues a sync task.
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should fix the rest of the comment while we're at it.

Copy link
Contributor

@jirwin jirwin left a comment

Choose a reason for hiding this comment

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

Good progress here. The main thing missing at this point is a way to persist the events, and more importantly how/where we persist the next page token.

My hunch is that we'll want to update the syncer package to have an explicit SyncEvents step that isn't called as part of a normal sync, but allows you to store the events in the c1z, as well as the next page/last token.

If not a part of the syncer, I think we'll want to still come up with a place for that logic to live.

fmt.Println(string(bytes))
}
pageToken = resp.GetNextPageToken()
if pageToken == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the semantics of a page token are exactly what we want. Normally we loop until the page token is empty, and then we know there isn't any data left. We may want to consider another field on the response to track the 'page token' to save for the next request.

Imagine we return 10 results per page. On the 3rd page, we only have 5 results, so we'd return an empty page token. But the connector also needs to provide a token to use for the next call to resume from after the 5th result that it returned. That way when the connector is woken up in an hour, it can start off where it was at last more easily.

Copy link
Contributor

Choose a reason for hiding this comment

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

To sum that up: since it is a feed, there will always be a next page token, so we can't use the same value to know that we need to continue making more requests. Maybe it is a bool on the response message?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it gets worse. Feeds are assumed to log data from oldest to newest, but in the two connectors that we are planning on implementing this for first, they return data from newest to oldest with no way of inverting it. We got around this in another connector by looping over all events it was able to find. If we hit a pageSize cutoff, it would return the next page token that the service needs and use that as the page token. If not, we returned the most recent timestamp and put a filter to only get objects newer than that timestamp. But this doesn't really work either because events in a service may come in out of order. We either have to live with that to a certain extend while minimizing our risk for it, or sync everything, or provide some ID tracking mechanism that says "well get everything after this day - a few and only return net new IDs." Lots of ideas on how to tackle this one. This should definitely be solved by the SDK to make connector implementation easier.

@@ -0,0 +1,43 @@
package c1api

//
Copy link
Contributor

Choose a reason for hiding this comment

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

delet

@@ -219,6 +219,9 @@ func (c *c1ApiTaskManager) Process(ctx context.Context, task *v1.Task, cc types.
case tasks.RevokeType:
handler = newRevokeTaskHandler(task, tHelpers)

// case tasks.EventFeedType:
Copy link
Contributor

Choose a reason for hiding this comment

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

delet

@@ -42,6 +47,7 @@ type builderImpl struct {
resourceBuilders map[string]ResourceSyncer
resourceProvisioners map[string]ResourceProvisioner
resourceProvisionersV2 map[string]ResourceProvisionerV2
eventFeed EventProvider
Copy link
Contributor

@loganintech loganintech Jan 22, 2024

Choose a reason for hiding this comment

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

should this be map[string]EventProvider, then we could have potentially multiple streams, one per resource type?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, maybe it is just []EventProvider? I don't know that they are tied to a resource type specifically, but the idea of supporting multiple feeds makes sense to me.

var pageToken string
for {
resp, err := cc.ListEvents(ctx, &v2.ListEventsRequest{
PageSize: 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should maybe make this a const, even think about increasing it. Event feeds tend to have a larger volume of events than the items that give 100 like we're used to.

@loganintech loganintech force-pushed the anthony/logan/event-feeds branch from 9ea209d to 488213e Compare January 25, 2024 21:55
@@ -216,6 +216,9 @@ type rotateCredentialsConfig struct {
resourceType string
}

type eventStreamConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just placeholder for when we might eventually need a config?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, and follows the same format as the other runners.

Copy link
Contributor

@jirwin jirwin left a comment

Choose a reason for hiding this comment

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

Looks good!

@loganintech loganintech merged commit f272c8f into main Jan 26, 2024
4 checks passed
@loganintech loganintech deleted the anthony/logan/event-feeds branch January 26, 2024 17:36
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.

3 participants