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

feat: adds datasource status to sdk-client #590

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

tanderson-ld
Copy link
Contributor

@tanderson-ld tanderson-ld commented Sep 23, 2024

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

SDK-170

Describe the solution you've provided

Adds DataSourceStatusManager.
Refactors data source errors into common.
Adds DataSourceErrorKind to classify errors so manager can track state.

@tanderson-ld tanderson-ld requested a review from a team as a code owner September 23, 2024 17:30
this.name = 'LaunchDarklyStreamingError';
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: These moved to datasource/errors.ts

@@ -1,6 +1,7 @@
import { LDLogger } from '@launchdarkly/js-sdk-common';

export type EventName = 'error' | 'change';
// TODO: is one emitter with many event names what we want long term?
export type EventName = 'error' | 'change' | 'dataSourceStatus';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: Please provide thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is intended to provide an EventTarget like interface to our objects to make them familiar. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed TODO

Copy link
Contributor Author

@tanderson-ld tanderson-ld Sep 23, 2024

Choose a reason for hiding this comment

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

For reviewers: Majority of content for handling in this file is from LDClientImpl


handlePollingError(error: LDPollingError) {
this.statusManager.setError(error.kind, error.message, error.status, error.recoverable);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: If there is a better way to handle the mapping of StreamingError.code and PollingError.status to status I can unify these functions.

export type PollingErrorHandler = (err: LDPollingError) => void;
// TODO: revisit usage of internal and figure out best practice
const { DataSourceErrorKind, LDPollingError } = internal;
export type PollingErrorHandler = (err: internal.LDPollingError) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: Please provide thoughts on internal import usage here.

@@ -172,64 +170,6 @@ export default class LDClientImpl implements LDClient {
return this.checkedContext;
}

private createStreamListeners(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: This was unused.

/* eslint-disable max-classes-per-file */
import { DataSourceErrorKind } from './DataSourceErrorKinds';

export class LDFileDataSourceError extends Error {
Copy link
Member

Choose a reason for hiding this comment

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

Errors are not intended to be internal. In that the internal package should only be used by SDK implementations, but instance of LDPollingError theoretically is something you could do in an application. Maybe we don't want that, but this one is maybe breaking.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe not expected to be constructed outside though. That part is likely fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Started fixing this, but running into some import/export configuration issue. Pushed most recent commit before having to leave for flight.

@@ -256,8 +251,8 @@ describe('sdk-client storage', () => {
JSON.stringify(putResponse),
);

expect(emitter.emit).toHaveBeenNthCalledWith(1, 'change', context, defaultFlagKeys);
Copy link
Member

Choose a reason for hiding this comment

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

I may need some explanation on these changes also, as the ordering of events mattered and that isn't tested anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that too. I can go through and get them all to be passing, but I don’t think there is any specification around when a change event should come out vs when a dataSourceStatus change should come out and that is leading to them all breaking as I added dataSourceStatus events.

Perhaps an improved way could be to filter to just “change” and then do positional checking on the filtered output.

@@ -30,4 +31,4 @@ export { DataSourcePaths } from './streaming';
export { BaseDataManager } from './DataManager';
export { Requestor };

export { LDClientImpl, LDClientInternalOptions };
export { DataSourceStatus, LDClientImpl, LDClientInternalOptions };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to add DataSourceState, DataSourceStatusErrorInfo, and DataSourceErrorKind

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