Skip to content

Commit

Permalink
fix: update depdencies
Browse files Browse the repository at this point in the history
Closes #168
Closes #166
Closes #159
Closes #156

This also inlines the metrics function from hello.nrfcloud.com
so this project does not depend on the proto repo
  • Loading branch information
coderbyheart committed Nov 24, 2024
1 parent c81c3bf commit ba2f6d5
Show file tree
Hide file tree
Showing 18 changed files with 2,537 additions and 4,435 deletions.
8 changes: 4 additions & 4 deletions cdk/BackendStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ export class BackendStack extends Stack {
layerVersionName: `${Stack.of(this).stackName}-baseLayer`,
code: new LambdaSource(this, {
id: 'baseLayer',
zipFile: layer.layerZipFile,
zipFilePath: layer.layerZipFilePath,
hash: layer.hash,
}).code,
compatibleArchitectures: [Lambda.Architecture.ARM_64],
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
})

const resolutionJobsQueue = new SQS.Queue(this, 'resolutionJobsQueue', {
Expand Down Expand Up @@ -357,11 +357,11 @@ export class BackendStack extends Stack {
const cdkLayerVersion = new Lambda.LayerVersion(this, 'cdkLayer', {
code: new LambdaSource(this, {
id: 'cdkLayer',
zipFile: cdkLayer.layerZipFile,
zipFilePath: cdkLayer.layerZipFilePath,
hash: cdkLayer.hash,
}).code,
compatibleArchitectures: [Lambda.Architecture.ARM_64],
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
})
const domain = new APICustomDomain(this, {
api,
Expand Down
2 changes: 1 addition & 1 deletion cdk/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ACMClient } from '@aws-sdk/client-acm'
import { IAMClient } from '@aws-sdk/client-iam'
import { ensureGitHubOIDCProvider } from '@bifravst/ci'
import { getCertificateForDomain } from '../aws/acm.js'
import pJSON from '../package.json'
import pJSON from '../package.json' assert { type: 'json' }
import { BackendApp } from './BackendApp.js'
import { packCDKLayer } from './cdkLayer.js'
import { packBackendLambdas } from './lambdas.js'
Expand Down
2 changes: 1 addition & 1 deletion cdk/cdkLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
packLayer,
type PackedLayer,
} from '@bifravst/aws-cdk-lambda-helpers/layer'
import type pJson from '../package.json'
import pJson from '../package.json' assert { type: 'json' }

const dependencies: Array<keyof (typeof pJson)['dependencies']> = [
'cfn-response',
Expand Down
11 changes: 6 additions & 5 deletions cdk/lambdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export type BackendLambdas = {
dailyOnomondoUpdate: PackedLambda
}

const pack = async (id: string) => packLambdaFromPath(id, `lambda/${id}.ts`)
const pack = async (id: string) =>
packLambdaFromPath({ id, sourceFilePath: `lambda/${id}.ts` })

export const packBackendLambdas = async (): Promise<BackendLambdas> => ({
getBasicSIMInformation: await pack('getBasicInformationLambda'),
Expand All @@ -23,9 +24,9 @@ export const packBackendLambdas = async (): Promise<BackendLambdas> => ({
),
getAllSimUsageOnomondo: await pack('getAllSimUsageOnomondo'),
getAllSimUsageWirelessLogic: await pack('getAllSimUsageWirelessLogic'),
createCNAMERecord: await packLambdaFromPath(
'createCNAMERecord',
'cdk/resources/api/createCNAMERecord.ts',
),
createCNAMERecord: await packLambdaFromPath({
id: 'createCNAMERecord',
sourceFilePath: 'cdk/resources/api/createCNAMERecord.ts',
}),
dailyOnomondoUpdate: await pack('dailyOnomondoUpdate'),
})
3 changes: 1 addition & 2 deletions cdk/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import {
packLayer,
type PackedLayer,
} from '@bifravst/aws-cdk-lambda-helpers/layer'
import type pJson from '../package.json'
import pJson from '../package.json' assert { type: 'json' }

const dependencies: Array<keyof (typeof pJson)['dependencies']> = [
'@bifravst/from-env',
'@sinclair/typebox',
'e118-iin-list',
'@bifravst/timestream-helpers',
'@hello.nrfcloud.com/lambda-helpers',
'@middy/core',
'@aws-lambda-powertools/metrics',
]
Expand Down
2 changes: 1 addition & 1 deletion lambda/dailyOnomondoUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
TimestreamWriteClient,
} from '@aws-sdk/client-timestream-write'
import { fromEnv } from '@bifravst/from-env'
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
import middy from '@middy/core'
import { TWO_MONTHS_AGO } from './constants.js'
import { getNewRecords } from './getNewRecords.js'
import { getSIMHistoryTs } from './getSimDetailsFromCache.js'
import { metricsForComponent } from './metrics.js'
import { getSimUsageHistoryOnomondo } from './onomondo/getAllUsedSimsOnomondo.js'
import { storeHistoricalDataInDB } from './storeHistoricalDataInDB.js'

Expand Down
2 changes: 1 addition & 1 deletion lambda/fetchAndValidate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { fetchAndValidate } from './fetchAndValidate.js'
import { SimInfo } from './onomondo/fetchOnomondoSimDetails.js'
import testData from './onomondo/testData/Onomondo-example.json'
import testData from './onomondo/testData/Onomondo-example.json' assert { type: 'json' }

void describe('fetchAndValidate', () => {
void it('should fetch the Onomondo SIM details', async () => {
Expand Down
2 changes: 1 addition & 1 deletion lambda/getAllSimUsageOnomondo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
TimestreamWriteClient,
} from '@aws-sdk/client-timestream-write'
import { fromEnv } from '@bifravst/from-env'
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
import middy from '@middy/core'
import { byTsDesc } from '../util/byTsDesc.js'
import { MaybeDate } from '../util/MaybeDate.js'
import { TWO_MONTHS_AGO } from './constants.js'
import { getNewRecords } from './getNewRecords.js'
import { getSIMHistoryTs } from './getSimDetailsFromCache.js'
import { metricsForComponent } from './metrics.js'
import { getSimUsageHistoryOnomondo } from './onomondo/getAllUsedSimsOnomondo.js'
import { queueJob } from './queueJob.js'
import { storeHistoricalDataInDB } from './storeHistoricalDataInDB.js'
Expand Down
2 changes: 1 addition & 1 deletion lambda/getAllSimUsageWirelessLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
type _Record,
} from '@aws-sdk/client-timestream-write'
import { fromEnv } from '@bifravst/from-env'
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
import middy from '@middy/core'
import { wirelessLogicDataLimit } from './constants.js'
import { metricsForComponent } from './metrics.js'
import { putSimDetails } from './putSimDetails.js'
import { storeHistoricalDataInDB } from './storeHistoricalDataInDB.js'
import { usageToRecord } from './usageToRecord.js'
Expand Down
2 changes: 1 addition & 1 deletion lambda/getBasicInformationLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { SQSClient } from '@aws-sdk/client-sqs'
import { TimestreamQueryClient } from '@aws-sdk/client-timestream-query'
import { fromEnv } from '@bifravst/from-env'
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
import middy from '@middy/core'
import type {
APIGatewayProxyEventV2,
Expand All @@ -20,6 +19,7 @@ import {
getSimDetailsFromCache,
} from './getSimDetailsFromCache.js'
import { HistoricalDataTimeSpans } from './historicalDataTimeSpans.js'
import { metricsForComponent } from './metrics.js'
import { olderThan5min } from './olderThan5min.js'
import { queueJob } from './queueJob.js'
const { simDetailsJobsQueue, cacheTableName, wirelessLogicQueue, tableInfo } =
Expand Down
35 changes: 35 additions & 0 deletions lambda/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Metrics } from '@aws-lambda-powertools/metrics'

const registry: Record<string, Metrics> = {}
export type AddMetricsFn = (...args: Parameters<Metrics['addMetric']>) => void

const metricsEnabled = process.env.DISABLE_METRICS !== '1'
console.debug(`[Metrics]`, metricsEnabled ? `Enabled` : `Disabled`)

/**
* Manages the instantiation of a Metrics object (unless Metrics are disabled)
*/
export const metricsForComponent = (
component: string,
namespace = 'hello-nrfcloud-backend',
): {
metrics: Metrics
track: AddMetricsFn
} => {
if (registry[component] === undefined) {
registry[component] = new Metrics({
namespace,
serviceName: component,
})
}
const metrics = registry[component]
return {
metrics,
track: (...args) => {
if (!metricsEnabled) {
return
}
metrics.addMetric(...args)
},
}
}
6 changes: 3 additions & 3 deletions lambda/onomondo/getAllUsedSimsOnomondo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import nock from 'nock'
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { getSimUsageHistoryOnomondo } from './getAllUsedSimsOnomondo.js'
import testData from './testData/Onomondo-AllSims.json'
import testData2 from './testData/Onomondo-AllSims2.json'
import testData3 from './testData/Onomondo-usageExample.json'
import testData from './testData/Onomondo-AllSims.json' assert { type: 'json' }
import testData2 from './testData/Onomondo-AllSims2.json' assert { type: 'json' }
import testData3 from './testData/Onomondo-usageExample.json' assert { type: 'json' }

void describe('getAllICCIDFromOnomondo', () => {
void it('should return the iccids and usage from all SIMs', async () => {
Expand Down
2 changes: 1 addition & 1 deletion lambda/storeSimInformationOnomondo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
TimestreamWriteClient,
} from '@aws-sdk/client-timestream-write'
import { fromEnv } from '@bifravst/from-env'
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
import middy from '@middy/core'
import type { SQSEvent } from 'aws-lambda'
import { byTsDesc } from '../util/byTsDesc.js'
import { MaybeDate } from '../util/MaybeDate.js'
import { TWO_MONTHS_AGO } from './constants.js'
import { getNewRecords } from './getNewRecords.js'
import { getSIMHistoryTs } from './getSimDetailsFromCache.js'
import { metricsForComponent } from './metrics.js'
import { fetchOnomondoSIMDetails } from './onomondo/fetchOnomondoSimDetails.js'
import { getSimUsageHistoryOnomondo } from './onomondo/getAllUsedSimsOnomondo.js'
import { putSimDetails } from './putSimDetails.js'
Expand Down
2 changes: 1 addition & 1 deletion lambda/storeSimInformationWirelessLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
TimestreamWriteClient,
} from '@aws-sdk/client-timestream-write'
import { fromEnv } from '@bifravst/from-env'
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
import middy from '@middy/core'
import type { SQSEvent } from 'aws-lambda'
import { wirelessLogicDataLimit } from './constants.js'
import { getSimDetailsFromCache } from './getSimDetailsFromCache.js'
import { metricsForComponent } from './metrics.js'
import { putSimDetails } from './putSimDetails.js'
import { storeHistoricalDataInDB } from './storeHistoricalDataInDB.js'
import { usageToRecord } from './usageToRecord.js'
Expand Down
6 changes: 3 additions & 3 deletions lambda/wirelessLogic/fetchWirelessLogicSIMDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import nock from 'nock'
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { fetchWirelessLogicSIMDetails } from './fetchWirelessLogicSIMDetails.js'
import activeSimsTestData1 from './testData/activeSimHistory1.json'
import activeSimsTestData2 from './testData/activeSimHistory2.json'
import activeSimsTestData3 from './testData/activeSimHistory3.json'
import activeSimsTestData1 from './testData/activeSimHistory1.json' assert { type: 'json' }
import activeSimsTestData2 from './testData/activeSimHistory2.json' assert { type: 'json' }
import activeSimsTestData3 from './testData/activeSimHistory3.json' assert { type: 'json' }

void describe('getActiveSimsHistory()', () => {
void it('should return the iccids of the active SIMs', async () => {
Expand Down
2 changes: 1 addition & 1 deletion lambda/wirelessLogic/getActiveSims.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type DynamoDBClient } from '@aws-sdk/client-dynamodb'
import assert from 'node:assert/strict'
import { describe, it, mock } from 'node:test'
import { getActiveSims } from './getActiveSims.js'
import testData from './testData/activeSimsFromDB.json'
import testData from './testData/activeSimsFromDB.json' assert { type: 'json' }

void describe('getActiveSims()', () => {
void it('should return an empty object if no SIMs in DB', async () => {
Expand Down
Loading

0 comments on commit ba2f6d5

Please sign in to comment.