-
Notifications
You must be signed in to change notification settings - Fork 21
refactor: encapsulate existing SDK data system [DRAFT] #188
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
Closed
cwaldren-ld
wants to merge
33
commits into
mk/sc-254810/fdv2-polling
from
cw/sc-254717/data-system-config
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
953d678
chore: Create FDv2 compatible datasource implementation
keelerm84 77aa8df
chore: Create FDv2 compatible polling data source
keelerm84 91236e8
refactor: add internal data system config
cwaldren-ld 7d47e83
more docs
cwaldren-ld bf7f04d
refactor persistent store config
cwaldren-ld d1d1992
make package name shorter in import
cwaldren-ld 0eec886
adding a V2 method to existing data sources
cwaldren-ld dbdf59d
creating the dataSystem interface
cwaldren-ld 18e415b
tests pass
cwaldren-ld 6bcced3
lints
cwaldren-ld bfc6cbf
add concept of DataStatus, remove need to check initialized
cwaldren-ld 15ecf0b
create stub fdv2 data system
cwaldren-ld 3b2db18
add dual-mode store
cwaldren-ld cb76023
refactoring the store component
cwaldren-ld e0f7cd9
comment
cwaldren-ld 2b8a48f
doc comments
cwaldren-ld 7799ab1
copious comments
cwaldren-ld 2528954
adding store unit tests
cwaldren-ld 9712057
use pointer swap to switch stores
cwaldren-ld 7cb03b1
goimports
cwaldren-ld 1ee88b2
more store unit tests
cwaldren-ld 4850f82
revert changes to StreamingDataSourceBuilder, and make a V2 struct in…
cwaldren-ld cb3678b
remove now-unnecessary ToSynchronizer converter
cwaldren-ld cdbac24
make v2 data sources implement Synchronizer
cwaldren-ld b21c901
ensure closeWhenReady is closed in offline mode
cwaldren-ld 3685b07
expose some fdv2 types in datasourcev2, and use them to implement e2e…
cwaldren-ld 04faaba
break out data destination/status reporter from DataSourceUpdateSink …
cwaldren-ld b76539a
make separate test file for fdv2 e2e tests
cwaldren-ld e0c9cd0
use top-level cfg.Offline to determine if data system should be enabled
cwaldren-ld 11bf0e6
add dedicated FDv2 streaming protocol builder for unit tests
cwaldren-ld bc3c696
add another unit test
cwaldren-ld 7a535af
more fdv2 parity e2e tests
cwaldren-ld 5b8230f
goimports
cwaldren-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package datasourcev2 | ||
|
||
//nolint: godox | ||
// TODO: This was copied from datasource/helpers.go. We should extract these | ||
// out into a common module, or if we decide we don't need these later in the | ||
// v2 implementation, we should clean this up. | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/launchdarkly/go-sdk-common/v3/ldlog" | ||
) | ||
|
||
type httpStatusError struct { | ||
Message string | ||
Code int | ||
} | ||
|
||
func (e httpStatusError) Error() string { | ||
return e.Message | ||
} | ||
|
||
// Tests whether an HTTP error status represents a condition that might resolve on its own if we retry, | ||
// or at least should not make us permanently stop sending requests. | ||
func isHTTPErrorRecoverable(statusCode int) bool { | ||
if statusCode >= 400 && statusCode < 500 { | ||
switch statusCode { | ||
case 400: // bad request | ||
return true | ||
case 408: // request timeout | ||
return true | ||
case 429: // too many requests | ||
return true | ||
default: | ||
return false // all other 4xx errors are unrecoverable | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func httpErrorDescription(statusCode int) string { | ||
message := "" | ||
if statusCode == 401 || statusCode == 403 { | ||
message = " (invalid SDK key)" | ||
} | ||
return fmt.Sprintf("HTTP error %d%s", statusCode, message) | ||
} | ||
|
||
// Logs an HTTP error or network error at the appropriate level and determines whether it is recoverable | ||
// (as defined by isHTTPErrorRecoverable). | ||
func checkIfErrorIsRecoverableAndLog( | ||
loggers ldlog.Loggers, | ||
errorDesc, errorContext string, | ||
statusCode int, | ||
recoverableMessage string, | ||
) bool { | ||
if statusCode > 0 && !isHTTPErrorRecoverable(statusCode) { | ||
loggers.Errorf("Error %s (giving up permanently): %s", errorContext, errorDesc) | ||
return false | ||
} | ||
loggers.Warnf("Error %s (%s): %s", errorContext, recoverableMessage, errorDesc) | ||
return true | ||
} | ||
|
||
func checkForHTTPError(statusCode int, url string) error { | ||
if statusCode == http.StatusUnauthorized { | ||
return httpStatusError{ | ||
Message: fmt.Sprintf("Invalid SDK key when accessing URL: %s. Verify that your SDK key is correct.", url), | ||
Code: statusCode} | ||
} | ||
|
||
if statusCode == http.StatusNotFound { | ||
return httpStatusError{ | ||
Message: fmt.Sprintf("Resource not found when accessing URL: %s. Verify that this resource exists.", url), | ||
Code: statusCode} | ||
} | ||
|
||
if statusCode/100 != 2 { | ||
return httpStatusError{ | ||
Message: fmt.Sprintf("Unexpected response code: %d when accessing URL: %s", statusCode, url), | ||
Code: statusCode} | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Package datasourcev2 is an internal package containing implementation types for the SDK's data source | ||
// implementations (streaming, polling, etc.) and related functionality. These types are not visible | ||
// from outside of the SDK. | ||
// | ||
// WARNING: This particular implementation supports the upcoming flag delivery v2 format which is not | ||
// publicly available. | ||
// | ||
// This does not include the file data source, which is in the ldfiledata package. | ||
package datasourcev2 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making this prepend, can this be a simple add style method? Prepending adds an unnecessary "think of this as a stack" mental overhead I think we'd like to avoid.
I realize these are supposed to run before our default initializer, but maybe we can figure out a better way to represent that. Maybe we call these custom initializers, and the docs make that clear that's before the built-in. We can discuss.
Also we should make this method singular unless it is going to be variadic.