-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ucan stream consumer w3 accum store/add size (#146)
Adds a consumer to UCAN stream kinesis where total size of store/add operations is tracked in the system. To achieve this tracking, we simply consume UCAN stream, filter `store/add` operations and update a DynamoDB table row incrementing previous value in batches. This PR adds only one metric consumer. Follow up PRs for remaining systsem metrics will follow same pattern as what we decide here. It includes: - DynamoDB Table w3metrics, with one row per each system metric - Default config for consumers - more details about those in #118 - Dead letter queue for failures - Integration tests to check metrics are updated running the UCAN Stream consumer Note that: > [Numbers can be positive, negative, or zero. Numbers can have up to 38 digits of precision.](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes) See DynamoDB Tables content after integration tests ran: - store table: https://us-east-2.console.aws.amazon.com/dynamodbv2/home?region=us-east-2#item-explorer?table=pr146-w3infra-store - w3 metrics table: https://us-east-2.console.aws.amazon.com/dynamodbv2/home?region=us-east-2#item-explorer?table=pr146-w3infra-w3-metrics
- Loading branch information
1 parent
a632872
commit 9c64395
Showing
21 changed files
with
647 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GetItemCommand, ScanCommand } from '@aws-sdk/client-dynamodb' | ||
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb' | ||
|
||
/** | ||
* @param {import('@aws-sdk/client-dynamodb').DynamoDBClient} dynamo | ||
* @param {string} tableName | ||
* @param {object} key | ||
*/ | ||
export async function getTableItem (dynamo, tableName, key) { | ||
const cmd = new GetItemCommand({ | ||
TableName: tableName, | ||
Key: marshall(key) | ||
}) | ||
|
||
const response = await dynamo.send(cmd) | ||
return response.Item && unmarshall(response.Item) | ||
} | ||
|
||
/** | ||
* @param {import("@aws-sdk/client-dynamodb").DynamoDBClient} dynamo | ||
* @param {string} tableName | ||
* @param {object} [options] | ||
* @param {number} [options.limit] | ||
*/ | ||
export async function getAllTableRows (dynamo, tableName, options = {}) { | ||
const cmd = new ScanCommand({ | ||
TableName: tableName, | ||
Limit: options.limit || 30 | ||
}) | ||
|
||
const response = await dynamo.send(cmd) | ||
return response.Items?.map(i => unmarshall(i)) || [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// UCAN protocol | ||
export const STORE_ADD = 'store/add' | ||
|
||
// Metrics | ||
export const METRICS_NAMES = { | ||
STORE_ADD_SIZE_TOTAL: `${STORE_ADD}-size-total` | ||
} |
Oops, something went wrong.