Skip to content

Commit

Permalink
feat: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arein committed Feb 8, 2024
1 parent 4ebb37a commit 7d714ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
6 changes: 3 additions & 3 deletions apps/laboratory/tests/canary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { uploadCanaryResultsToCloudWatch } from './shared/utils/metrics'
const ENV = process.env['ENV'] || 'dev'
const REGION = process.env['REGION'] || 'eu-central-1'

let startTime: number
let startTime = 0

testMW.beforeEach(
async ({ modalPage, walletPage, modalValidator, walletValidator, browserName }) => {
Expand Down Expand Up @@ -47,14 +47,14 @@ testMW(
await modalValidator.expectAcceptedSign()

if (ENV !== 'dev') {
const duration: number = Date.now() - startTime
await uploadCanaryResultsToCloudWatch(
ENV,
REGION,
'https://lab.web3modal.com/',
'HappyPath.sign',
true,
Date.now() - startTime,
[]
duration
)
}
}
Expand Down
41 changes: 12 additions & 29 deletions apps/laboratory/tests/shared/utils/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { CloudWatch, PutMetricDataCommandInput } from '@aws-sdk/client-cloudwatch'
import {
CloudWatch,
type MetricDatum,
type PutMetricDataCommandInput
} from '@aws-sdk/client-cloudwatch'

// eslint-disable-next-line func-style
export const uploadCanaryResultsToCloudWatch = async (
env: string,
region: string,
target: string,
metricsPrefix: string,
isTestPassed: boolean,
testDurationMs: number,
otherLatencies: object[]
testDurationMs: number
// eslint-disable-next-line max-params
) => {
const cloudwatch = new CloudWatch({ region: 'eu-central-1' })
const ts = new Date()
const metrics = [
const metrics: MetricDatum[] = [
{
MetricName: `${metricsPrefix}.success`,
Dimensions: [
Expand Down Expand Up @@ -65,38 +70,16 @@ export const uploadCanaryResultsToCloudWatch = async (
})
}

const latencies = otherLatencies.map(metric => {
const metricName: string = Object.keys(metric)[0] as string
return {
MetricName: `${metricsPrefix}.${metricName}`,
Dimensions: [
{
Name: 'Target',
Value: target
},
{
Name: 'Region',
Value: region
}
],
Unit: 'Milliseconds',
Value: metric[metricName],
Timestamp: ts
}
})

const params: PutMetricDataCommandInput = {
MetricData: [...metrics, ...latencies],
MetricData: metrics,
Namespace: `${env}_Canary_Web3Modal`
}

await new Promise<void>(resolve => {
cloudwatch.putMetricData(params, function (err: Error) {
cloudwatch.putMetricData(params, (err: Error) => {
if (err) {
// eslint-disable-next-line no-console
console.error('Failed to upload metrics to CloudWatch', err, err.stack)
// Swallow error as
// Test shouldn't fail despite CW failing
// we will report on missing metrics
}
resolve()
})
Expand Down

0 comments on commit 7d714ec

Please sign in to comment.