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: edge sdks should send events to bulk/environment endpoint #256

Merged

Conversation

yusinto
Copy link
Contributor

@yusinto yusinto commented Aug 26, 2023

Edge sdks use clientSideID not sdk-key. We should be able to post events to the eventsUri/bulk/clientSideID endpoint for edge sdks without needing to specify the sdk key in the authorization header.

This is an alternate solution to #217. Both prs are attempting to enable events for edge sdks.

Don't be alarmed with the filecount, it's mostly shell file fixes unrelated to this to include a directive which seems to be needed for local build.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #214758: Send events to environment endpoint for edge sdks.

@yusinto yusinto marked this pull request as draft August 26, 2023 06:43
@yusinto yusinto requested a review from ldhenry August 26, 2023 06:43
@yusinto
Copy link
Contributor Author

yusinto commented Aug 26, 2023

I still need to test this PR in a real application but based on existing js sdk code, this PR should work.

packages/sdk/cloudflare/example/src/index.ts Outdated Show resolved Hide resolved
packages/shared/sdk-server/src/events/EventSender.ts Outdated Show resolved Hide resolved
scripts/build-doc.sh Outdated Show resolved Hide resolved
packages/sdk/cloudflare/example/src/index.ts Outdated Show resolved Hide resolved
link-dev.sh Outdated Show resolved Hide resolved
@yusinto
Copy link
Contributor Author

yusinto commented Aug 28, 2023

I ran the cloudflare example app using this code which uses clientSideID and events seem to be sent.

Screenshot 2023-08-27 at 7 36 47 PM

@yusinto yusinto marked this pull request as ready for review August 28, 2023 02:54
@kinyoklion
Copy link
Member

I am not sure about this. The events that can be generated from a client SDK are not 100% the same. So I do not know how the endpoints for a client SDK handle the data.

The server-side SDKs, which these are, generate prerequisite record events. Would the client SDK endpoint for events handle those correctly? If we have a definitive answer, then I can see pursuing it.

@kinyoklion
Copy link
Member

Secondarily it appears these changes break many contract tests, so some investigation is need there.

Copy link
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

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

Need to investigate the event test failures in the contract tests.

@yusinto
Copy link
Contributor Author

yusinto commented Aug 28, 2023

Would the client SDK endpoint for events handle those correctly

@kinyoklion Thank you for your feedback. I submitted this PR having done due diligence checking the event recorder logic how it handles events for server and client sdks.

My investigation reveals both the /bulk and /events/bulk/{envId} endpoints are handled equally by the postBulkEvents handler. You'll see this postBulkEvents contain the RecordRequest logic you are concerned with so I think this is covered for both server and client sdks.

I understand your concerns though and you want us to be thorough with this kind of hybrid logic because we never had to mix the two before. The edge sdks are unique in this way, it is truly somewhat of a hybrid. This approach opens the door for the future for such sdks so I'm hopeful this works. I will assign someone from the events pipeline to review my work.

I will investigate the contract tests failures, I suspect they are related to the sdk- key prefix which is necessary now. If those tests use some arbitrary strings as sdkKey then those will fail.

@yusinto yusinto requested a review from samstokes August 28, 2023 19:09
@yusinto
Copy link
Contributor Author

yusinto commented Aug 28, 2023

Added @samstokes as reviewer from the Events pipeline team.

Copy link

@samstokes samstokes left a comment

Choose a reason for hiding this comment

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

LGTM from an event pipeline standpoint. (Leaving it to the SDK team to do the approving.)

Re:

The events that can be generated from a client SDK are not 100% the same. So I do not know how the endpoints for a client SDK handle the data.

I can confirm that both endpoints behave identically in terms of what event payloads they will accept. e.g. even though only browser SDKs generate click events, the /bulk endpoint that handles server-side SDK payloads will happily accept a click event. It all goes into the same Kinesis stream :)

Re the specific concern about prerequisite events:

The server-side SDKs, which these are, generate prerequisite record events. Would the client SDK endpoint for events handle those correctly? If we have a definitive answer, then I can see pursuing it.

I don't think anything in our event pipeline does anything special with prerequisites. Definitely the events endpoint handlers don't.

(AFAIK there's nothing special about prerequisite events, right - they're just regular evaluation events? And the only special consideration is that client-side SDKs don't send them.

packages/shared/sdk-server-edge/src/api/LDClient.ts Outdated Show resolved Hide resolved
packages/shared/sdk-server/src/events/EventSender.ts Outdated Show resolved Hide resolved
@yusinto
Copy link
Contributor Author

yusinto commented Aug 28, 2023

from a security standpoint it'd be nice if there was a clearer distinction between sdkKey and clientSideID in the code

Thanks @samstokes ! I have improved the code to provide a better distinction between sdkKey and clientSideID.

packages/sdk/cloudflare/example/src/index.ts Outdated Show resolved Hide resolved
packages/sdk/cloudflare/example/src/index.ts Outdated Show resolved Hide resolved
@yusinto yusinto requested a review from ldhenry August 31, 2023 00:49
@yusinto
Copy link
Contributor Author

yusinto commented Sep 5, 2023

@ldhenry pls re-review when able. Thank you

@ldhenry
Copy link
Contributor

ldhenry commented Sep 8, 2023

@ldhenry pls re-review when able. Thank you

Hey @yusinto, I was hoping to get some sort of evidence that this is working from our alpha customers before making this more widely available. However, I can't see any usage in honeycomb. Do you know if there is a better way to see adoption?

@yusinto
Copy link
Contributor Author

yusinto commented Sep 13, 2023

Do you know if there is a better way to see adoption?

Yep we can try querying cmetrics directly following these instructions.

Copy link

@samstokes samstokes left a comment

Choose a reason for hiding this comment

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

Nothing to add, just commenting so GitHub will stop reminding me about this PR. If there's anything that does need my feedback please feel free to "re-request review".

@yusinto
Copy link
Contributor Author

yusinto commented Nov 8, 2023

@ldhenry @kinyoklion I resolved conflicts and made minor updates and added unit tests. Please re-review. Thank you.

Tested with the example app and verified in the UI.

Screenshot 2023-11-08 at 1 54 54 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

To the Vercel and/or Akamai examples also need to be updated? I initially thought this change only applied to Cloudflare because only the Cloudflare example was changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those examples can be updated, but not necessary. I'll leave that to @ldhenry .

@yusinto yusinto enabled auto-merge (squash) November 12, 2023 03:02
@yusinto
Copy link
Contributor Author

yusinto commented Nov 12, 2023

@ldhenry please approve so this can be merged. Thank you.

@yusinto yusinto merged commit f45910f into main Nov 12, 2023
15 checks passed
@yusinto yusinto deleted the yus/sc-214758/send-events-to-environment-endpoint-for-edge branch November 12, 2023 22:56
@github-actions github-actions bot mentioned this pull request Nov 12, 2023
kinyoklion added a commit that referenced this pull request Nov 14, 2023
🤖 I have created a release *beep* *boop*
---


<details><summary>@launchdarkly/akamai-edgeworker-sdk-common:
1.0.3</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from ^2.0.2 to ^2.1.0
</details>

<details><summary>@launchdarkly/akamai-server-base-sdk: 2.0.3</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.2 to
^1.0.3
    * @launchdarkly/js-server-sdk-common bumped from ^2.0.2 to ^2.1.0
</details>

<details><summary>@launchdarkly/akamai-server-edgekv-sdk:
1.0.11</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.2 to
^1.0.3
    * @launchdarkly/js-server-sdk-common bumped from ^2.0.2 to ^2.1.0
</details>

<details><summary>cloudflare-server-sdk: 2.3.0</summary>

##
[2.3.0](cloudflare-server-sdk-v2.2.3...cloudflare-server-sdk-v2.3.0)
(2023-11-14)


### Features

* edge sdks should send events to bulk/environment endpoint
([#256](#256))
([f45910f](f45910f))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.0.2 to 2.1.0
</details>

<details><summary>js-sdk-common: 2.1.0</summary>

##
[2.1.0](js-sdk-common-v2.0.0...js-sdk-common-v2.1.0)
(2023-11-14)


### Features

* edge sdks should send events to bulk/environment endpoint
([#256](#256))
([f45910f](f45910f))
</details>

<details><summary>js-server-sdk-common: 2.1.0</summary>

##
[2.1.0](js-server-sdk-common-v2.0.2...js-server-sdk-common-v2.1.0)
(2023-11-14)


### Features

* edge sdks should send events to bulk/environment endpoint
([#256](#256))
([f45910f](f45910f))


### Bug Fixes

* Better handle waiting for initialization for failure cases.
([#314](#314))
([16515df](16515df)),
closes [#312](#312)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-sdk-common bumped from 2.0.0 to 2.1.0
</details>

<details><summary>js-server-sdk-common-edge: 2.1.0</summary>

##
[2.1.0](js-server-sdk-common-edge-v2.0.2...js-server-sdk-common-edge-v2.1.0)
(2023-11-14)


### Features

* edge sdks should send events to bulk/environment endpoint
([#256](#256))
([f45910f](f45910f))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.0.2 to 2.1.0
</details>

<details><summary>@launchdarkly/node-server-sdk: 9.0.3</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.0.2 to 2.1.0
</details>

<details><summary>@launchdarkly/node-server-sdk-dynamodb:
6.0.3</summary>

### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.0.2 to 9.0.3
</details>

<details><summary>@launchdarkly/node-server-sdk-redis: 4.0.3</summary>

### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.0.2 to 9.0.3
</details>

<details><summary>vercel-server-sdk: 1.2.0</summary>

##
[1.2.0](vercel-server-sdk-v1.1.7...vercel-server-sdk-v1.2.0)
(2023-11-14)


### Features

* Support analytics events in the vercel SDK.
([#316](#316))
([cc41db4](cc41db4))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.0.2 to 2.1.0
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ryan Lamb <[email protected]>
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.

6 participants