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: ucan stream consumer w3 accum store/add size #146

Merged
merged 3 commits into from
Mar 6, 2023

Conversation

vasco-santos
Copy link
Contributor

@vasco-santos vasco-santos commented Feb 22, 2023

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 feat: ucan stream consumer count uploads in space #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.

See DynamoDB Tables content after integration tests ran:

Closes #145

@seed-deploy seed-deploy bot temporarily deployed to pr146 February 22, 2023 09:05 Inactive
@seed-deploy
Copy link

seed-deploy bot commented Feb 22, 2023

View stack outputs
  • pr146-w3infra-CarparkStack

    Name Value
    BucketName carpark-pr146-0
    Region us-east-2
  • pr146-w3infra-SatnavStack

    Name Value
    BucketName satnav-pr146-0
    Region us-east-2
  • pr146-w3infra-UploadApiStack

    Name Value
    ApiEndpoint https://pyi3yh2vid.execute-api.us-east-2.amazonaws.com
    CustomDomain https://pr146.up.web3.storage
  • pr146-w3infra-BusStack

  • pr146-w3infra-ReplicatorStack

  • pr146-w3infra-UcanInvocationStack

  • pr146-w3infra-UploadDbStack

@vasco-santos vasco-santos marked this pull request as ready for review February 22, 2023 09:23
@vasco-santos vasco-santos changed the title feat: ucan stream consume w3r accum store size feat: ucan stream consumer w3 accum store size Feb 22, 2023
@vasco-santos vasco-santos changed the title feat: ucan stream consumer w3 accum store size feat: ucan stream consumer w3 accum store/add size Feb 22, 2023
/**
* This table tracks w3 wider metrics.
*/
const w3MetricsTable = new Table(stack, 'w3-metrics', w3MetricsTableProps)
Copy link
Member

Choose a reason for hiding this comment

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

Why does the table have w3- prefix? The others do not...

Copy link
Member

Choose a reason for hiding this comment

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

Should this be admin-metrics instead to signify it's not user facing?


// Get metrics before upload
const beforeOperationW3Metrics = await getW3Metrics(t)
const beforeW3AccumulatedSize = beforeOperationW3Metrics.find(row => row.name === W3_METRICS_NAMES.STORE_ADD_ACCUM_SIZE)
Copy link
Member

Choose a reason for hiding this comment

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

Please can we have a separate test('POST / updates metrics') for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to do what you suggested and should have documented decision in PR description!

This is the integration tests and therefore we write real CAR files (a new one per PR/commit) that will live in S3/R2. Adding more individual tests will lead into more and more files that we will need to pay for storage + egress just for testing.

Probably I can suggest renaming this file to integration.test.js and make test names more appropriate to include everything. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Ohhh ok, yeah renaming will be fine!

*/
export async function updateAccumulatedSize (ucanInvocations, ctx) {
const invocationsWithStoreAdd = ucanInvocations.filter(
inv => inv.value.att.find(a => a.can === STORE_ADD)
Copy link
Member

Choose a reason for hiding this comment

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

Should we consider also store/remove into this calculation? Or, perhaps better - collect a separate metric that for store/remove-accumulated-size (followup PR)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, follow up PR with your suggestion. The goal of this PR is to get a "this is the way we should do things". Then follow up PRs with consumers for each metrics will be just follow same pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in tracking #117

const afterOperationW3Metrics = await getW3Metrics(t)
const afterW3AccumulatedSize = afterOperationW3Metrics.find(row => row.name === W3_METRICS_NAMES.STORE_ADD_ACCUM_SIZE)

return afterW3AccumulatedSize?.value > beforeW3AccumulatedSize.value
Copy link
Member

Choose a reason for hiding this comment

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

Please can we test the real value after storing multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Goal here was to create a balance to get to a point where we do not have flaky tests. When this integration tests run in the PR scope is actually fine. However, they also run in staging. Making such assumption in staging can be problematic because of parallel engineer testing something in staging or when we hook up other tests in staging that write stuff there (for example, for w3infra)...

We can make a conditional more explicit. If is staging, just accept > and if it is PR expect real value different.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did this in commit


// Metrics
export const W3_METRICS_NAMES = {
STORE_ADD_ACCUM_SIZE: `${STORE_ADD}-accumulated-size`
Copy link
Member

Choose a reason for hiding this comment

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

Meaning is basically the same but I would have gone for total over accumulated for succinctness - just wondering if there was a different reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to total everywhere

*
* @param {Capabilities} operationsInv
*/
incrementAccumulatedSize: async (operationsInv) => {
Copy link
Member

Choose a reason for hiding this comment

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

This should either be specific to store add i.e. incrementStoreAddAccumulatedSize or take the key as a param.

@heyjay44 heyjay44 mentioned this pull request Feb 22, 2023
18 tasks
@vasco-santos vasco-santos requested review from alanshaw and removed request for alanshaw February 23, 2023 13:06
@seed-deploy seed-deploy bot temporarily deployed to pr146 February 23, 2023 17:21 Inactive
@vasco-santos vasco-santos force-pushed the feat/ucan-stream-consumer-accum-store-size branch from ed164c6 to 02d4ee1 Compare February 23, 2023 17:25
@seed-deploy seed-deploy bot temporarily deployed to pr146 February 23, 2023 17:30 Inactive
@vasco-santos vasco-santos force-pushed the feat/ucan-stream-consumer-accum-store-size branch from 02d4ee1 to bc58362 Compare February 23, 2023 18:04
@seed-deploy seed-deploy bot temporarily deployed to pr146 February 23, 2023 18:04 Inactive
/**
* This table tracks w3 wider metrics.
*/
const adminMetricsTable = new Table(stack, 'metrics', adminMetricsTableProps)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const adminMetricsTable = new Table(stack, 'metrics', adminMetricsTableProps)
const adminMetricsTable = new Table(stack, 'admin-metrics', adminMetricsTableProps)


// Get metrics before upload
const beforeOperationMetrics = await getMetrics(t)
const beforeAccumulatedSize = beforeOperationMetrics.find(row => row.name === METRICS_NAMES.STORE_ADD_ACCUM_SIZE)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const beforeAccumulatedSize = beforeOperationMetrics.find(row => row.name === METRICS_NAMES.STORE_ADD_ACCUM_SIZE)
const beforeAccumulatedSize = beforeOperationMetrics.find(row => row.name === METRICS_NAMES.STORE_ADD_TOTAL_SIZE)


// If staging accept more broad condition given multiple parallel tests can happen there
if (stage === 'staging') {
return afterAccumulatedSize?.value > beforeAccumulatedSize.value
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return afterAccumulatedSize?.value > beforeAccumulatedSize.value
return afterAccumulatedSize?.value >= beforeAccumulatedSize.value + carSize

// Check metrics were updated
beforeAccumulatedSize && await pWaitFor(async () => {
const afterOperationMetrics = await getMetrics(t)
const afterAccumulatedSize = afterOperationMetrics.find(row => row.name === METRICS_NAMES.STORE_ADD_ACCUM_SIZE)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const afterAccumulatedSize = afterOperationMetrics.find(row => row.name === METRICS_NAMES.STORE_ADD_ACCUM_SIZE)
const afterTotalSize = afterOperationMetrics.find(row => row.name === METRICS_NAMES.STORE_ADD_ACCUM_SIZE)

@seed-deploy seed-deploy bot temporarily deployed to pr146 March 6, 2023 15:57 Inactive
@vasco-santos
Copy link
Contributor Author

@alanshaw addresses last comments, also renaming lambda consumer to include store-add to better separate from future ones. Also, I named things putting total in the end to be coherent with Prometheus best practises so that once we expose these metrics we can keep everything consistent

@vasco-santos vasco-santos requested a review from alanshaw March 6, 2023 16:09
@vasco-santos vasco-santos merged commit 9c64395 into main Mar 6, 2023
@vasco-santos vasco-santos deleted the feat/ucan-stream-consumer-accum-store-size branch March 6, 2023 16:25
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.

Add w3 wide metrics
2 participants