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

Improved Code Examples in Docs #2943

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 15 additions & 14 deletions docs/content/get-started/define-control-points.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

In the organization created within Aperture Cloud, navigate to the
**`Aperture`** tab in the sidebar menu. From there, select **`Agent API Keys`**
in the top bar. This is where you can find and copy the **`AGENT_API_KEY`** and

Check warning on line 46 in docs/content/get-started/define-control-points.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 It appears that a noun is missing after “the”. (THE_CC[1]) Rule: https://community.languagetool.org/rule/show/THE_CC?lang=en-US&subId=1 Category: GRAMMAR Raw Output: docs/content/get-started/define-control-points.md:46:52: It appears that a noun is missing after “the”. (THE_CC[1]) Rule: https://community.languagetool.org/rule/show/THE_CC?lang=en-US&subId=1 Category: GRAMMAR
use it in the SDK as follows:

:::
Expand All @@ -69,16 +69,16 @@
```

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
karansohi marked this conversation as resolved.
Show resolved Hide resolved
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.

Expand All @@ -88,19 +88,20 @@
```

```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);
karansohi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
7 changes: 3 additions & 4 deletions docs/content/guides/per-user-rate-limiting.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
:::note

The following policy is based on the
[Rate Limiting](/reference/blueprints/rate-limiting/base.md) blueprint.

Check warning on line 53 in docs/content/guides/per-user-rate-limiting.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL) Suggestions: `Rate-Limiting` Rule: https://community.languagetool.org/rule/show/EN_COMPOUND_ADJECTIVE_INTERNAL?lang=en-US Category: MISC Raw Output: docs/content/guides/per-user-rate-limiting.md:53:1: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL) Suggestions: `Rate-Limiting` Rule: https://community.languagetool.org/rule/show/EN_COMPOUND_ADJECTIVE_INTERNAL?lang=en-US Category: MISC

:::

## Rate Limiting with Aperture SDK

The first step to use Aperture SDK is to import and set up Aperture Client:

Check warning on line 59 in docs/content/guides/per-user-rate-limiting.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 This verb may not be in the correct form. Consider using a different form for this context. (AI_EN_LECTOR_REPLACEMENT_VERB_FORM) Suggestions: `using` Rule: https://community.languagetool.org/rule/show/AI_EN_LECTOR_REPLACEMENT_VERB_FORM?lang=en-US Category: MISC Raw Output: docs/content/guides/per-user-rate-limiting.md:59:18: This verb may not be in the correct form. Consider using a different form for this context. (AI_EN_LECTOR_REPLACEMENT_VERB_FORM) Suggestions: `using` Rule: https://community.languagetool.org/rule/show/AI_EN_LECTOR_REPLACEMENT_VERB_FORM?lang=en-US Category: MISC

```mdx-code-block
<Tabs>
Expand Down Expand Up @@ -90,14 +90,13 @@
```

```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
},
});
karansohi marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -124,8 +123,8 @@
## Configuration

This policy is based on the
[Rate Limiting](/reference/blueprints/rate-limiting/base.md) blueprint. It

Check warning on line 126 in docs/content/guides/per-user-rate-limiting.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL) Suggestions: `Rate-Limiting` Rule: https://community.languagetool.org/rule/show/EN_COMPOUND_ADJECTIVE_INTERNAL?lang=en-US Category: MISC Raw Output: docs/content/guides/per-user-rate-limiting.md:126:1: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL) Suggestions: `Rate-Limiting` Rule: https://community.languagetool.org/rule/show/EN_COMPOUND_ADJECTIVE_INTERNAL?lang=en-US Category: MISC
applies a rate limiter to the **`awesomeFeature`** and identifies unique users

Check warning on line 127 in docs/content/guides/per-user-rate-limiting.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 It appears that a noun is missing after “the”. (THE_CC[1]) Rule: https://community.languagetool.org/rule/show/THE_CC?lang=en-US&subId=1 Category: GRAMMAR Raw Output: docs/content/guides/per-user-rate-limiting.md:127:26: It appears that a noun is missing after “the”. (THE_CC[1]) Rule: https://community.languagetool.org/rule/show/THE_CC?lang=en-US&subId=1 Category: GRAMMAR

Check warning on line 127 in docs/content/guides/per-user-rate-limiting.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 Did you mean “end”? (AND_END[1]) Suggestions: `end` Rule: https://community.languagetool.org/rule/show/AND_END?lang=en-US&subId=1 Category: GRAMMAR Raw Output: docs/content/guides/per-user-rate-limiting.md:127:51: Did you mean “end”? (AND_END[1]) Suggestions: `end` Rule: https://community.languagetool.org/rule/show/AND_END?lang=en-US&subId=1 Category: GRAMMAR
by referencing the **`user_id`**.

Each user is allowed **`2`** requests every **`1s`** (1 second) period. A burst
Expand Down
4 changes: 2 additions & 2 deletions docs/content/sdk/dotnet/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ more information, refer to

:::

```csharp
```cpp
var sdk = ApertureSdk
.Builder()
.SetAddress("ORGANIZATION.app.fluxninja.com:443")
Expand All @@ -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<string, string>();
karansohi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 2 additions & 3 deletions docs/content/sdk/javascript/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
});
karansohi marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading