-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Create FDv2 compatible datasource implementation (#186)
Introduces the new `datasourcev2` package to hold all FDv2 related functionality. This package contains a streaming datasource implementation that is compatible with our current SDK, but pulls data updates from a FDv2-compatible source. It does not support any of the other FDv2-specific features like picking up from a known state. That will be introduced in later work as we re-shape the datasource integration on a larger scale.
- Loading branch information
Showing
4 changed files
with
762 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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,54 @@ | ||
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" | ||
|
||
"github.com/launchdarkly/go-sdk-common/v3/ldlog" | ||
) | ||
|
||
// 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 | ||
} |
This file contains 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.