From 6ac3808f2eada3158699abc30524eb2fb219b019 Mon Sep 17 00:00:00 2001 From: Karanbir Singh <65090469+karansohi@users.noreply.github.com> Date: Sun, 19 Nov 2023 21:30:31 -0800 Subject: [PATCH] Improved Code Examples in Docs (#2943) ### Description of change ##### Checklist - [ ] Tested in playground or other setup - [ ] Screenshot (Grafana) from playground added to PR for 15+ minute run - [x] Documentation is changed or added - [ ] Tests and/or benchmarks are included - [ ] Breaking changes ## Summary by CodeRabbit - **Documentation** - Updated the "Get Started" guide to clarify the process of defining feature control points and adjusted the terminology for consistency. - Revised the "Per-User Rate Limiting" guide to reflect changes in request handling and rate-limiting logic. - Updated the SDK documentation for .NET to include changes in initialization and usage with the new C++ code examples. - Amended the JavaScript SDK manual to align with the updated request handling function and parameters. Co-authored-by: Hardik Shingala <34568645+hdkshingala@users.noreply.github.com> --- .../get-started/define-control-points.md | 29 ++++++++++--------- docs/content/guides/per-user-rate-limiting.md | 7 ++--- docs/content/sdk/dotnet/manual.md | 4 +-- docs/content/sdk/javascript/manual.md | 5 ++-- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/docs/content/get-started/define-control-points.md b/docs/content/get-started/define-control-points.md index b49a3a7f44..11e1293831 100644 --- a/docs/content/get-started/define-control-points.md +++ b/docs/content/get-started/define-control-points.md @@ -69,16 +69,16 @@ export const apertureClient = new ApertureClient({ ``` Once you have configured Aperture SDK, you can create a feature control point -wherever you want in your code. Before executing the business logic of a -specific API, you can create a feature control point that can control the -execution flow of the API and can reject the request based on the policy defined -in Aperture. The [Create Your First Policy](./policies/policies.md) section -showcases how to define policy in Aperture. The code snippet below shows how to -wrap your [Control Point](/concepts/control-point.md) within the `StartFlow` -call and pass [labels](/concepts/flow-label.md) that will be matched with -policy. The function `Flow.ShouldRun()` checks if the flow allows the request. -The `Flow.End()` function is responsible for sending telemetry, and updating the -specified cache entry within Aperture. +anywhere within your code. Before executing the business logic of a specific +API, you can create a feature control point that can control the execution flow +of the API and can reject the request based on the policy defined in Aperture. +The [Create Your First Policy](./policies/policies.md) section showcases how to +define policy in Aperture. The code snippet below shows how to wrap your +[Control Point](/concepts/control-point.md) within the `StartFlow` call and pass +[labels](/concepts/flow-label.md) to Aperture Agents. The function +`Flow.ShouldRun()` checks if the flow allows the request. The `Flow.End()` +function is responsible for sending telemetry, and updating the specified cache +entry within Aperture. Let's create a feature control point in the following code snippet. @@ -88,19 +88,20 @@ Let's create a feature control point in the following code snippet. ``` ```typescript -async function handleFlow() { +async function handleRequest(req, res) { const flow = await apertureClient.StartFlow("archimedes-service", { labels: { - label_key: "api_key", - interval: "60", + api_key: "some_api_key", }, grpcCallOptions: { - deadline: Date.now() + 1200000, // 20 minutes deadline + deadline: Date.now() + 300, // ms }, }); if (flow.ShouldRun()) { // Do Actual Work + // After completing the work, you can return a response, for example: + res.send({ message: "foo" }); } else { // Handle flow rejection flow.SetStatus(FlowStatusEnum.Error); diff --git a/docs/content/guides/per-user-rate-limiting.md b/docs/content/guides/per-user-rate-limiting.md index 063b88447a..baf87e832f 100644 --- a/docs/content/guides/per-user-rate-limiting.md +++ b/docs/content/guides/per-user-rate-limiting.md @@ -90,14 +90,13 @@ specified cache entry within Aperture. ``` ```javascript -async function handleFlow() { +async function handleRequest(req, res) { const flow = await apertureClient.StartFlow("awesomeFeature", { labels: { - label_key: "some_user_id", - interval: "1s", + user_id: "some_user_id", }, grpcCallOptions: { - deadline: Date.now() + 1200000, // 20 minutes deadline + deadline: Date.now() + 300, // ms }, }); diff --git a/docs/content/sdk/dotnet/manual.md b/docs/content/sdk/dotnet/manual.md index 15905f20a8..2398ab930d 100644 --- a/docs/content/sdk/dotnet/manual.md +++ b/docs/content/sdk/dotnet/manual.md @@ -28,7 +28,7 @@ more information, refer to ::: -```csharp +```cpp var sdk = ApertureSdk .Builder() .SetAddress("ORGANIZATION.app.fluxninja.com:443") @@ -38,7 +38,7 @@ var sdk = ApertureSdk The created instance can then be used to start a flow: -```csharp +```cpp // do some business logic to collect labels var labels = new Dictionary(); diff --git a/docs/content/sdk/javascript/manual.md b/docs/content/sdk/javascript/manual.md index 531374c0bf..75cb948b91 100644 --- a/docs/content/sdk/javascript/manual.md +++ b/docs/content/sdk/javascript/manual.md @@ -37,14 +37,13 @@ export const apertureClient = new ApertureClient({ The created instance can then be used to start a flow: ```javascript -async function handleFlow() { +async function handleRequest(req, res) { const flow = await apertureClient.StartFlow("feature-name", { labels: { label_key: "some_user_id", - interval: "60", }, grpcCallOptions: { - deadline: Date.now() + 1200000, // 20 minutes deadline + deadline: Date.now() + 300, // ms }, });