Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/amplify/amplify/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const TelemetryBackendSecretsManagerMQTTCredentials = new secretsmanager.Secret(
},
);

const MLCorrelationMatrixSecrets = secretsmanager.Secret.fromSecretNameV2(
TelemetryBackendStack,
"MLCorrelationMatrixSecrets",
"MLCorrelationMatrixSecrets",
);

const TimescaleConnectionString = secretsmanager.Secret.fromSecretNameV2(
TelemetryBackendStack,
"TimescaleConnectionString",
Expand Down Expand Up @@ -367,14 +373,24 @@ TelemetryECSTaskDefinition.addContainer("TheContainer", {
TimescaleConnectionString,
"DATABASE_USERNAME",
),

LAP_CORRELATION_MATRIX_FUNCTION_NAME: ecs.Secret.fromSecretsManager(
MLCorrelationMatrixSecrets,
"LAP_CORRELATION_MATRIX_FUNCTION_NAME",
),
MQTT_PASSWORD: ecs.Secret.fromSecretsManager(
TelemetryBackendSecretsManagerMQTTCredentials,
"password",
),

MQTT_USERNAME: ecs.Secret.fromSecretsManager(
TelemetryBackendSecretsManagerMQTTCredentials,
"username",
),
PACKET_CORRELATION_MATRIX_FUNCTION_NAME: ecs.Secret.fromSecretsManager(
MLCorrelationMatrixSecrets,
"PACKET_CORRELATION_MATRIX_FUNCTION_NAME",
),
PRIVATE_KEY: ecs.Secret.fromSecretsManager(
TelemetryBackendSecretsManagerPrivKey,
),
Expand All @@ -395,6 +411,7 @@ TelemetryBackendSecretsManagerMQTTCredentials.grantRead(
TelemetryECSTaskDefinition.taskRole,
);
TimescaleConnectionString.grantRead(TelemetryECSTaskDefinition.taskRole);
MLCorrelationMatrixSecrets.grantRead(TelemetryECSTaskDefinition.taskRole);

const TelemetryBackendVPCSecurityGroup = ec2.SecurityGroup.fromSecurityGroupId(
TelemetryBackendStack,
Expand Down
3 changes: 2 additions & 1 deletion packages/client/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NEXT_PUBLIC_MAPSAPIKEY=''
NEXT_PUBLIC_MAPSAPIKEY=''
SOCKET_URL=localhost:3001
24 changes: 17 additions & 7 deletions packages/client/src/pages/api/getLapCorrelationMatrix.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import type { NextApiRequest, NextApiResponse } from "next";

const API_ROUTE = process.env.GET_LAP_CORRELATION_MATRIX_URL;
if (!API_ROUTE) {
throw new Error("GET_LAP_CORRELATION_MATRIX_URL is not defined");
}
import { prodURL } from "@shared/helios-types";

const BACKEND_ROUTE = `${prodURL}/ml/correlation-matrix/lap`;

export default async function handler(
req: NextApiRequest,
_req: NextApiRequest,
res: NextApiResponse,
) {
try {
const result = await fetch(API_ROUTE as string);
const result = await fetch(BACKEND_ROUTE);

if (!result.ok) {
const errorData = await result.json().catch(() => ({}));
return res.status(result.status).json({
error: errorData.error || "Failed to fetch correlation matrix data",
});
}

const graph = await result.json();
res.status(200).json(graph);
} catch (err) {
res.status(500).json({ error: "failed to load data" + err });
res.status(500).json({
error: `Failed to load data: ${err instanceof Error ? err.message : String(err)}`,
});
}
}
24 changes: 17 additions & 7 deletions packages/client/src/pages/api/getPacketCorrelationMatrix.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import type { NextApiRequest, NextApiResponse } from "next";

const API_ROUTE = process.env.GET_PACKET_CORRELATION_MATRIX_URL;
if (!API_ROUTE) {
throw new Error("GET_PACKET_CORRELATION_MATRIX_URL is not defined");
}
import { prodURL } from "@shared/helios-types";

const BACKEND_ROUTE = `${prodURL}/ml/correlation-matrix/packet`;

export default async function handler(
req: NextApiRequest,
_req: NextApiRequest,
res: NextApiResponse,
) {
try {
const result = await fetch(API_ROUTE as string);
const result = await fetch(BACKEND_ROUTE);

if (!result.ok) {
const errorData = await result.json().catch(() => ({}));
return res.status(result.status).json({
error: errorData.error || "Failed to fetch correlation matrix data",
});
}

const graph = await result.json();
res.status(200).json(graph);
} catch (err) {
res.status(500).json({ error: "failed to load data" + err });
res.status(500).json({
error: `Failed to load data: ${err instanceof Error ? err.message : String(err)}`,
});
}
}
3 changes: 3 additions & 0 deletions packages/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ DATABASE_PORT=
########################
LAP_POSITION_PASSWORD="changeme"


GET_PACKET_CORRELATION_MATRIX_URL='https://myApiGatewayForPacketMatrix.lambda-url.region.on.aws/'
GET_LAP_CORRELATION_MATRIX_URL='https://myApiGatewayForLapMatrix.lambda-url.region.on.aws/'
3 changes: 3 additions & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.682.0",
"@aws-sdk/client-lambda": "^3.980.0",
"@aws-sdk/lib-dynamodb": "^3.682.0",
"@faker-js/faker": "^9.0.3",
"@godaddy/terminus": "^4.12.1",
Expand All @@ -25,6 +26,7 @@
"log4js": "^6.9.1",
"module-alias": "^2.2.3",
"mqtt": "^5.8.0",
"node-cache": "^5.1.2",
"rimraf": "^5.0.5",
"socket.io": "^4.7.5",
"ts-node": "^10.9.2",
Expand All @@ -39,6 +41,7 @@
"@types/eslint": "^9.6.0",
"@types/express": "^4.17.21",
"@types/node": "^20.14.10",
"@types/node-cache": "^4.1.3",
"@types/prettier": "^3.0.0",
"@types/sqlite3": "^3.1.11",
"@typescript-eslint/eslint-plugin": "^7.4.0",
Expand Down
Loading