-
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 store/add and store/remove count (#151)
Part of metrics work #117 Adds system total metrics for `store/add` and `store/remove`. With these, we can track number of CARs that we commited to store, and how many were removed. Other notes: - we will still need to collect the effective number of CARs that are stored given this metrics is just number of signed URLs we provided in `store/add`. - helper functions for database were moved around to be re-used in all tests for metrics
- Loading branch information
1 parent
9461e93
commit 57842a1
Showing
11 changed files
with
573 additions
and
45 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
// UCAN protocol | ||
export const STORE_ADD = 'store/add' | ||
export const STORE_REMOVE = 'store/remove' | ||
export const UPLOAD_ADD = 'upload/add' | ||
|
||
// Admin Metrics | ||
export const METRICS_NAMES = { | ||
STORE_ADD_SIZE_TOTAL: `${STORE_ADD}-size-total` | ||
UPLOAD_ADD_TOTAL: `${UPLOAD_ADD}-total`, | ||
STORE_ADD_TOTAL: `${STORE_ADD}-total`, | ||
STORE_ADD_SIZE_TOTAL: `${STORE_ADD}-size-total`, | ||
STORE_REMOVE_TOTAL: `${STORE_REMOVE}-total`, | ||
} | ||
|
||
// Spade Metrics | ||
export const SPACE_METRICS_NAMES = { | ||
UPLOAD_ADD_TOTAL: `${UPLOAD_ADD}-total` | ||
UPLOAD_ADD_TOTAL: `${UPLOAD_ADD}-total`, | ||
STORE_ADD_TOTAL: `${STORE_ADD}-total`, | ||
STORE_ADD_SIZE_TOTAL: `${STORE_ADD}-size-total`, | ||
STORE_REMOVE_TOTAL: `${STORE_REMOVE}-total`, | ||
} |
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,46 @@ | ||
import * as Sentry from '@sentry/serverless' | ||
|
||
import { createMetricsTable } from '../tables/metrics.js' | ||
import { parseKinesisEvent } from '../utils/parse-kinesis-event.js' | ||
import { STORE_ADD } from '../constants.js' | ||
|
||
Sentry.AWSLambda.init({ | ||
environment: process.env.SST_STAGE, | ||
dsn: process.env.SENTRY_DSN, | ||
tracesSampleRate: 1.0, | ||
}) | ||
|
||
const AWS_REGION = process.env.AWS_REGION || 'us-west-2' | ||
|
||
/** | ||
* @param {import('aws-lambda').KinesisStreamEvent} event | ||
*/ | ||
async function handler(event) { | ||
const ucanInvocations = parseKinesisEvent(event) | ||
|
||
const { | ||
TABLE_NAME: tableName = '', | ||
// set for testing | ||
DYNAMO_DB_ENDPOINT: dbEndpoint, | ||
} = process.env | ||
|
||
await updateStoreAddTotal(ucanInvocations, { | ||
metricsTable: createMetricsTable(AWS_REGION, tableName, { | ||
endpoint: dbEndpoint | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* @param {import('../types').UcanInvocation[]} ucanInvocations | ||
* @param {import('../types').TotalSizeCtx} ctx | ||
*/ | ||
export async function updateStoreAddTotal (ucanInvocations, ctx) { | ||
const invocationsWithStoreAdd = ucanInvocations.filter( | ||
inv => inv.value.att.find(a => a.can === STORE_ADD) | ||
).flatMap(inv => inv.value.att) | ||
|
||
await ctx.metricsTable.incrementStoreAddTotal(invocationsWithStoreAdd) | ||
} | ||
|
||
export const consumer = Sentry.AWSLambda.wrapHandler(handler) |
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,46 @@ | ||
import * as Sentry from '@sentry/serverless' | ||
|
||
import { createMetricsTable } from '../tables/metrics.js' | ||
import { parseKinesisEvent } from '../utils/parse-kinesis-event.js' | ||
import { STORE_REMOVE } from '../constants.js' | ||
|
||
Sentry.AWSLambda.init({ | ||
environment: process.env.SST_STAGE, | ||
dsn: process.env.SENTRY_DSN, | ||
tracesSampleRate: 1.0, | ||
}) | ||
|
||
const AWS_REGION = process.env.AWS_REGION || 'us-west-2' | ||
|
||
/** | ||
* @param {import('aws-lambda').KinesisStreamEvent} event | ||
*/ | ||
async function handler(event) { | ||
const ucanInvocations = parseKinesisEvent(event) | ||
|
||
const { | ||
TABLE_NAME: tableName = '', | ||
// set for testing | ||
DYNAMO_DB_ENDPOINT: dbEndpoint, | ||
} = process.env | ||
|
||
await updateStoreRemoveTotal(ucanInvocations, { | ||
metricsTable: createMetricsTable(AWS_REGION, tableName, { | ||
endpoint: dbEndpoint | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* @param {import('../types').UcanInvocation[]} ucanInvocations | ||
* @param {import('../types').TotalSizeCtx} ctx | ||
*/ | ||
export async function updateStoreRemoveTotal (ucanInvocations, ctx) { | ||
const invocationsWithStoreRemove = ucanInvocations.filter( | ||
inv => inv.value.att.find(a => a.can === STORE_REMOVE) | ||
).flatMap(inv => inv.value.att) | ||
|
||
await ctx.metricsTable.incrementStoreRemoveTotal(invocationsWithStoreRemove) | ||
} | ||
|
||
export const consumer = Sentry.AWSLambda.wrapHandler(handler) |
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
Oops, something went wrong.