Skip to content

Commit a42ca08

Browse files
committed
HomeTracker - Add debug messages
1 parent 48bda31 commit a42ca08

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/libs/middleware/authIOT.middleware.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export class UnkownApiKeyError extends ApiKeyError {
7676
// this livemode control whether or not we enforce the API keys validation
7777
const livemode = true;
7878
export const validateAPIKeyHeader = async (req: Request, _res: Response, next: NextFunction) => {
79+
const dataStr = JSON.stringify({path: req.path})
80+
slog.log('debug', 'validateAPIKeyHeader', { dataStr });
7981
const authHeader = req.headers.authorization;
8082

8183
let error;

src/libs/middleware/logging.middleware.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { LoggableContext, slog } from '../modules/logging/index.js';
55
import { config } from '../../packages/config/index.js';
66

77
export const loggingHandler = async (req: Request, res: Response, next: NextFunction) => {
8+
const dataStr = JSON.stringify({path: req.path})
9+
slog.log('debug', 'loggingHandler', { dataStr });
810
const path = req.path;
911
const remoteIp = req.socket.remoteAddress ?? 'N/A';
1012
const cfRay = req.get('cf-ray') ?? 'N/A';

src/libs/modules/homeTracker/services/sensorMetaData.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ export const getAllSensorsMetadata = async (): Promise<SensorMetaData[]> => {
2323
};
2424

2525
export const updateSensorLastSyncDate = async (params: { sensorName: string }) => {
26-
const [rows] = await db.query(
26+
db.query(
2727
`UPDATE HomeTrackerSensor
28-
SET lastSyncDateUnix = UNIX_TIMESTAMP()
29-
WHERE name = ?
30-
`,
28+
SET lastSyncDateUnix = UNIX_TIMESTAMP()
29+
WHERE name = ?
30+
`,
3131
[params.sensorName]
3232
);
33-
34-
return rows;
3533
};

src/libs/modules/logging/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export type AppLogComponent =
8686
| 'app'
8787
| 'auth'
8888
| 'chords'
89+
| 'debug'
8990
| 'env-helpers'
9091
| 'home-tracker'
9192
| 'meteo-france'

src/libs/routes/homeTracker/upload.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import {
55
sensorRawDataInputSchema,
66
updateSensorLastSyncDate
77
} from '../../modules/homeTracker/index.js';
8+
import { slog } from '../../modules/logging/index.js';
89

910
const handler: RouteHandler<Input> = async (params) => {
11+
slog.log('debug', 'Starting hometracker upload', { sensorName: params.input.sensorName });
1012
params.loggableContext.addData('sensorName', params.input.sensorName);
1113
params.loggableContext.addData('dataStr', JSON.stringify(params.input));
1214

1315
updateSensorLastSyncDate({ sensorName: params.input.sensorName });
16+
slog.log('debug', 'After updateSensorLastSyncDate', { sensorName: params.input.sensorName });
1417
// Don't await for data ingestion to avoid keeping the sensor up for too long
1518
// I think it should make tests flaky but it doesn't seem to be the case. Not sure why.
1619
ingestSensorData(params.input);
20+
slog.log('debug', 'After ingestSensorData', { sensorName: params.input.sensorName });
1721

1822
// For now sensors always sleep for 10 minutes between two uploads
1923
// The -4 is to try to reduce drift due to sensors restarting

0 commit comments

Comments
 (0)