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 initial documentation. #263

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contract-tests/sdkClientEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function makeSdkConfig(options, tag) {
}

function getExecution(order) {
switch(order) {
switch (order) {
case 'serial': {
return new LDSerialExecution(LDExecutionOrdering.Fixed);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ export async function newSdkClientEntity(options) {
case 'migrationOperation':
const migrationOperation = params.migrationOperation;
const readExecutionOrder = migrationOperation.readExecutionOrder;

const migration = new Migration(client, {
execution: getExecution(readExecutionOrder),
latencyTracking: migrationOperation.trackLatency,
Expand Down
35 changes: 35 additions & 0 deletions packages/shared/sdk-server/src/Migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,45 @@ async function safeCall<TResult>(
}
}

/**
* Report a successful migration operation from `readNew`, `readOld`, `writeNew` or `writeOld`.
*
* ```
* readNew: async () => {
* const myResult = doMyOldRead();
* if(myResult.wasGood) {
* return LDMigrationSuccess(myResult);
* }
* return LDMigrationError(myResult.error)
* }
* ```
*
* @param result The result of the operation.
* @returns An {@link LDMethodResult}
*/
export function LDMigrationSuccess<TResult>(result: TResult): LDMethodResult<TResult> {
return {
success: true,
result,
};
}

/**
* Report a failed migration operation from `readNew`, `readOld`, `writeNew` or `writeOld`.
*
* ```
* readNew: async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same sample, but I think it makes things easier for customers.

* const myResult = doMyOldRead();
* if(myResult.wasGood) {
* return LDMigrationSuccess(myResult);
* }
* return LDMigrationError(myResult.error)
* }
* ```
*
* @param result The result of the operations.
* @returns An {@link LDMethodResult}
*/
export function LDMigrationError(error: Error): { success: false; error: Error } {
return {
success: false,
Expand All @@ -59,6 +91,9 @@ interface MigrationContext<TPayload> {
checkRatio?: number;
}

/**
* Class which allows performing technology migrations.
*/
export default class Migration<
TMigrationRead,
TMigrationWrite,
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/sdk-server/src/api/LDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export interface LDClient {
): Promise<LDEvaluationDetail>;

/**
* TKTK: Should use a common description.
* MigrationVariation returns the migration stage of the migration feature flag for the given
* evaluation context.
*
* If the evaluated value of the flag cannot be converted to an LDMigrationStage, then an error
* event will be raised.
Expand Down
8 changes: 3 additions & 5 deletions packages/shared/sdk-server/src/api/LDMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export type LDMigrationWriteResult<TResult> = {
};

/**
* Interface for a migration.
*
* TKTK
* Interface representing a migration.
*/
export interface LDMigration<
TMigrationRead,
Expand All @@ -62,7 +60,7 @@ export interface LDMigration<
TMigrationWriteInput,
> {
/**
* TKTK
* Perform a read using the migration.
*
* @param key The key of the flag controlling the migration.
* @param context The context requesting the flag. The client will generate an analytics event to
Expand All @@ -78,7 +76,7 @@ export interface LDMigration<
): Promise<LDMigrationReadResult<TMigrationRead>>;

/**
* TKTK
* Perform a write using the migration.
*
* @param key The key of the flag controlling the migration.
* @param context The context requesting the flag. The client will generate an analytics event to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export enum LDConsistencyCheck {

/**
* Used to track information related to a migration operation.
*
* TKTK
*/
export interface LDMigrationTracker {
/**
Expand Down
34 changes: 34 additions & 0 deletions packages/shared/sdk-server/src/api/data/LDMigrationStage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
/**
* Stage denotes one of six possible stages a technology migration could be a
* part of, progressing through the following order.
*
* Off -> DualWrite -> Shadow -> Live -> RampDown -> Complete
*/
export enum LDMigrationStage {
/**
* Off - migration hasn't started, "old" is authoritative for reads and writes
*/
Off = 'off',

/**
* DualWrite - write to both "old" and "new", "old" is authoritative for reads
*/
DualWrite = 'dualwrite',

/**
* Shadow - both "new" and "old" versions run with a preference for "old"
*/
Shadow = 'shadow',

/**
* Live - both "new" and "old" versions run with a preference for "new"
*/
Live = 'live',

/**
* RampDown - only read from "new", write to "old" and "new"
*/
RampDown = 'rampdown',

/**
* Complete - migration is done
*/
Complete = 'complete',
}

/**
* Check if the given string is a migration stage.
* @param value The string to check.
* @returns True if the string is a migration stage.
*/
export function IsMigrationStage(value: string): boolean {
return Object.values(LDMigrationStage).includes(value as LDMigrationStage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,69 @@ export interface LDMigrationOptions<
errorTracking?: boolean;

/**
* TKTK
* Implementation which provides a read from the "new" source.
*
* Users are required to provide two different read methods -- one to read from the old migration source, and one to
* read from the new source. Additionally, customers can opt-in to consistency tracking by providing a `check`
* function.
*
* Depending on the migration stage, one or both of these read methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
* @param payload An optional payload. The payload is provided when calling the `read` method on the migration.
* @returns The result of the operation. Use {@link LDMigrationSuccess} or {@link LDMigrationError} to create a suitable return value.
*/
readNew: (payload?: TMigrationReadInput) => Promise<LDMethodResult<TMigrationRead>>;

/**
* TKTK
* Implementation which provides a write to the "new" source.
*
* Users are required to provide two different write methods -- one to write to the old migration source, and one to
Copy link
Member Author

Choose a reason for hiding this comment

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

There is a bit of duplication here, again because it makes finding the information a bit easier.

* write to the new source. Not every stage requires
*
*
* Depending on the migration stage, one or both of these write methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
* @param payload An optional payload. The payload is provided when calling the `read` method on the migration.
* @returns The result of the operation. Use {@link LDMigrationSuccess} or {@link LDMigrationError} to create a suitable return value.
*/
writeNew: (payload?: TMigrationWriteInput) => Promise<LDMethodResult<TMigrationWrite>>;

/**
* TKTK
* Implementation which provides a read from the "old" source.
*
* Users are required to provide two different read methods -- one to read from the old migration source, and one to
* read from the new source. Additionally, customers can opt-in to consistency tracking by providing a `check`
* function.
*
* Depending on the migration stage, one or both of these read methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
*/
readOld: (payload?: TMigrationReadInput) => Promise<LDMethodResult<TMigrationRead>>;

/**
* TKTK
* Implementation which provides a write to the "old" source.
*
* Users are required to provide two different write methods -- one to write to the old migration source, and one to
* write to the new source. Not every stage requires
*
* Depending on the migration stage, one or both of these write methods may be called.
*
* Throwing an exception from this method will be treated as an error.
*
* @param payload An optional payload. The payload is provided when calling the `read` method on the migration.
* @returns The result of the operation. Use {@link LDMigrationSuccess} or {@link LDMigrationError} to create a suitable return value.
*/
writeOld: (payload?: TMigrationWriteInput) => Promise<LDMethodResult<TMigrationWrite>>;

/**
* TKTK
* Method used to do consistency checks for read operations. After a read operation, during which both data sources
* are read from, a check of read consistency may be done using this method.
*/
check?: (a: TMigrationRead, b: TMigrationRead) => boolean;
}
Loading