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: add fdv2 store & update sources to use fdv2 protocol definitions #192

Merged
merged 40 commits into from
Oct 8, 2024

Conversation

cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented Sep 17, 2024

This adds the FDv2 dual-mode store, which supports serving data requests from an in-memory store or from a persistent store (with cache).

@@ -16,7 +16,7 @@ var (
deleteDataRequiredProperties = []string{"path", "version"} //nolint:gochecknoglobals
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a reversion of recent changes that made these public (for use in datasourcev2), but are no longer necessary.

@cwaldren-ld cwaldren-ld force-pushed the cw/sdk-557/fdv2-store branch 2 times, most recently from 9d79eaf to c91fd1e Compare September 25, 2024 23:14
return s.active
}

//nolint:revive // Implementation for ReadOnlyStore.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we return a pointer to the right store once for each evaluation?

@cwaldren-ld
Copy link
Contributor Author

@keelerm84 , realized why I was confused - the data system config PR has some of the other improvements in the streaming/polling sources (like replacing strings with constants). I tried to only touch the sources enough to get them to interact with the new store.

I'll have another PR that focuses on cleaning up the sources.

@cwaldren-ld cwaldren-ld changed the title chore: add fdv2 store chore: add fdv2 store & update sources to use fdv2 protocol definitions Sep 26, 2024
Comment on lines 94 to 95
item, err := kind.DeserializeFromJSONReader(&r)
return item, err
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is equivalent:

Suggested change
item, err := kind.DeserializeFromJSONReader(&r)
return item, err
return kind.DeserializeFromJSONReader(&r)

Which makes parseItem a single line method. At that point, is there value in having it as a a separate function?

internal/datasourcev2/polling_http_request.go Outdated Show resolved Hide resolved
internal/datasourcev2/polling_response.go Show resolved Hide resolved

parseItem := func(r jreader.Reader, kind datakinds.DataKindInternal) (ldstoretypes.ItemDescriptor, error) {
item, err := kind.DeserializeFromJSONReader(&r)
return item, err
}

for _, event := range events {
switch event.Event() {
case putEventName:
switch fdv2proto.EventName(event.Event()) {
Copy link
Member

Choose a reason for hiding this comment

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

I can't comment on the actual line, but parseItem here suffers from the same issue I pointed out above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out this whole bit of logic (the event parsing) doesn't work properly due to the streaming JSON parser. I'm going to have to refactor this to more closely match how the existing datasource (V1) parsers work - which is two passes.

The reason is because we might visit the "object" field before we've visited the kind field.

internal/datasystem/store.go Outdated Show resolved Hide resolved
internal/datasystem/store.go Outdated Show resolved Hide resolved
func ToStorableItems(events []Event) []ldstoretypes.Collection {
flagCollection := ldstoretypes.Collection{
Kind: datakinds.Features,
Items: make([]ldstoretypes.KeyedItemDescriptor, 0),
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it's worth reserving some capacity here to prevent the additional allocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't know the size up front, although we could calculate it. I think I'd rather let Go's allocation strategy do its thing and if it's a problem we can fix it.

This fully converts the datasources to use `fdv2` protocol domain
objects.
Use the new `toposort` package to insert items int persistent store in
dependency order.
@cwaldren-ld cwaldren-ld merged commit ece9cab into v7 Oct 8, 2024
19 checks passed
@cwaldren-ld cwaldren-ld deleted the cw/sdk-557/fdv2-store branch October 8, 2024 16:43
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