Skip to content

feat: Added a Lite bundle excluding Data file manager and Event Processor packages. #699

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

Merged
merged 26 commits into from
Oct 7, 2021

Conversation

zashraf1985
Copy link
Contributor

@zashraf1985 zashraf1985 commented Aug 24, 2021

Summary

Some platforms (such as edge providers), do not need extended functionality offered by data file manager and event processor. This PR creates a lite bundle which uses a NoOpDatafileManager and a ForwardingEventProcessor which immediately dispatches events when a custom event dispatcher is provided. This results in up to 20% reduction in bundle size. This also fixes the errors that SDK was throwing on edge platforms.

Usage

To use the lite bundle, user needs to explicitly import from it.
import { createInstance } from '@optimizely/optimizely-sdk/dist/optimizely.lite.es.mins.js'

Test plan

  1. All the Full stack compatibility suite tests pass for the existing bundles.
  2. Fixed all the failing unit tests.
  3. Added new unit tests to lite entry point.

@coveralls
Copy link

coveralls commented Aug 24, 2021

Coverage Status

Coverage increased (+0.08%) to 97.072% when pulling f94e45b on yasir/edge-support-testing into 7a73b91 on master.

@zashraf1985 zashraf1985 force-pushed the yasir/edge-support-testing branch from 86950ba to 59855e6 Compare September 2, 2021 14:04
@zashraf1985 zashraf1985 changed the title Feat: Experimenting Edge Bundle Feat: Added a Lite bundle which does not include Data file manager and Event Processor. Sep 13, 2021
@zashraf1985 zashraf1985 removed their assignment Sep 13, 2021
@zashraf1985 zashraf1985 marked this pull request as ready for review September 13, 2021 21:49
@zashraf1985 zashraf1985 requested a review from a team as a code owner September 13, 2021 21:49
@yavorona yavorona self-requested a review September 21, 2021 17:28
@@ -0,0 +1,257 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a License header

Copy link
Contributor

Choose a reason for hiding this comment

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

what does event_v1 means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v1 is the version of event on logx end point

tags?: EventTags
}

type Attributes = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this type being used anywhere, so we should delete it

Copy link
Contributor

Choose a reason for hiding this comment

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

We already have an Attribute type called UserAttributes in shared_types, can't we use that?

ep.stop().then(done);
});
});

Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: remove blank line

createInstance,
OptimizelyDecideOption,
};

Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: extra blank line

* @export
* @interface EventBuilderV1
*/

Choose a reason for hiding this comment

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

NIT: Extra blank line here

@@ -0,0 +1,27 @@
import { DatafileManager, DatafileUpdateListener} from '../../shared_types';
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem like we use these types anywhere else outside of this module, so we can define them here. The intension for shared_types to only contain types that are shared across modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are generic interfaces and are being used in the main optimizely class in its constructor

@yavorona yavorona self-requested a review September 22, 2021 17:03
Copy link
Contributor

@yavorona yavorona left a comment

Choose a reason for hiding this comment

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

LGTM except for a couple of minor comments. I also tested it locally and it works as expected!

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

have some questions.

@@ -0,0 +1,257 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

what does event_v1 means?

tags?: EventTags
}

type Attributes = {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have an Attribute type called UserAttributes in shared_types, can't we use that?

}
}

function makeConversionSnapshot(conversion: ConversionEvent): Snapshot {
Copy link
Contributor

Choose a reason for hiding this comment

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

assuming this whole code is copied from buildEventV1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! copied from event processor because we wanted to create a forwarding event processor without importing that package and we still needed this to build the payload.. I know this is not the best way to do it but we plan to consolidate those packages into one anyway. this redundancy will be solved then.

OnReadyResult,
OptimizelyConfig
OptimizelyConfig,
DatafileManager,
Copy link
Contributor

Choose a reason for hiding this comment

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

so you are preparing ConfigManager outside and importing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Building datafileManager outside and including here. The DatafileManager in this particular import is the interface.

const errorHandler = getErrorHandler();
const notificationCenter = createNotificationCenter({ logger: logger, errorHandler: errorHandler });

const eventProcessorConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a lot of common code in index.browser / react / node . ts file, It would be good if we can have a separate util class from where we create eventProcess/ Config & other stuff which is common.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! you are right in principle. There is some common code but there are some subtle differences too. I would recommend to leave it like this for this PR and take it up separately later. what do you say?

@zashraf1985 zashraf1985 removed their assignment Oct 4, 2021
@zashraf1985 zashraf1985 changed the title Feat: Added a Lite bundle which does not include Data file manager and Event Processor. Feat: Added a Lite bundle excluding Data file manager and Event Processor packages. Oct 4, 2021
@zashraf1985 zashraf1985 changed the title Feat: Added a Lite bundle excluding Data file manager and Event Processor packages. feat: Added a Lite bundle excluding Data file manager and Event Processor packages. Oct 4, 2021
Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -424,6 +436,7 @@ describe('lib/core/project_config/project_config_manager', function() {
var manager = projectConfigManager.createProjectConfigManager({
datafile: testData.getTestProjectConfig(),
sdkKey: '12345',
datafileManager: createHttpPollingDatafileManager('12345', logger, testData.getTestProjectConfig()),

Choose a reason for hiding this comment

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

Not sure if necessary but would it make sense to pull out the test value of '12345' and move to a constant?

sandbox.stub(projectConfig, 'tryCreatingProjectConfig').returns({ configObj: null, error: 'Error creating config'});
sandbox.stub(projectConfig, 'toDatafile');
});
it('Should log error when error is thrown while creating project config', () => {

Choose a reason for hiding this comment

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

NIT: used a capital here but not on other it( statements.

Copy link

@The-inside-man The-inside-man left a comment

Choose a reason for hiding this comment

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

Couple very small things but LGTM!

@zashraf1985 zashraf1985 merged commit b0478ec into master Oct 7, 2021
@zashraf1985 zashraf1985 deleted the yasir/edge-support-testing branch October 7, 2021 21:35
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.

7 participants