Skip to content

Commit 1a4be4a

Browse files
committed
feedback: move 'massage' to the default body
1 parent f5f0b4f commit 1a4be4a

File tree

8 files changed

+140
-113
lines changed

8 files changed

+140
-113
lines changed

packages/api/src/fixtures.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ const healthCheck = async () => {
6363
const client = await getClickhouseClient();
6464
const result = await client.ping();
6565
if (!result.success) {
66-
logger.error({
67-
message: 'ClickHouse health check failed',
68-
error: result.error,
69-
});
66+
logger.error({ error: result.error }, 'ClickHouse health check failed');
7067
throw result.error;
7168
}
7269
};

packages/api/src/middleware/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function handleAuthError(
4444
res: Response,
4545
next: NextFunction,
4646
) {
47-
logger.debug({ message: 'Auth error', authErr: serializeError(err) });
47+
logger.debug({ authErr: serializeError(err) }, 'Auth error');
4848
if (res.headersSent) {
4949
return next(err);
5050
}

packages/api/src/routers/api/ai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ router.post(
188188
const source = await getSource(teamId.toString(), sourceId);
189189

190190
if (source == null) {
191-
logger.error({ message: 'invalid source id', sourceId, teamId });
191+
logger.error({ sourceId, teamId }, 'invalid source id');
192192
return res.status(400).json({
193193
error: 'Invalid source',
194194
});

packages/api/src/tasks/checkAlerts.ts

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ const fireChannelEvent = async ({
9292
}
9393

9494
if ((alert.silenced?.until?.getTime() ?? 0) > Date.now()) {
95-
logger.info({
96-
message: 'Skipped firing alert due to silence',
97-
alertId: alert.id,
98-
silenced: alert.silenced,
99-
});
95+
logger.info(
96+
{
97+
alertId: alert.id,
98+
silenced: alert.silenced,
99+
},
100+
'Skipped firing alert due to silence',
101+
);
100102
return;
101103
}
102104

@@ -157,14 +159,16 @@ export const processAlert = async (
157159
previous &&
158160
fns.getTime(previous.createdAt) === fns.getTime(nowInMinsRoundDown)
159161
) {
160-
logger.info({
161-
message: `Skipped to check alert since the time diff is still less than 1 window size`,
162-
windowSizeInMins,
163-
nowInMinsRoundDown,
164-
previous,
165-
now,
166-
alertId: alert.id,
167-
});
162+
logger.info(
163+
{
164+
windowSizeInMins,
165+
nowInMinsRoundDown,
166+
previous,
167+
now,
168+
alertId: alert.id,
169+
},
170+
`Skipped to check alert since the time diff is still less than 1 window size`,
171+
);
168172
return;
169173
}
170174
const checkStartTime = previous
@@ -218,20 +222,24 @@ export const processAlert = async (
218222
};
219223
}
220224
} else {
221-
logger.error({
222-
message: `Unsupported alert source: ${alert.source}`,
223-
alertId: alert.id,
224-
});
225+
logger.error(
226+
{
227+
alertId: alert.id,
228+
},
229+
`Unsupported alert source: ${alert.source}`,
230+
);
225231
return;
226232
}
227233

228234
// Fetch data
229235
if (chartConfig == null) {
230-
logger.error({
231-
message: 'Failed to build chart config',
232-
chartConfig,
233-
alertId: alert.id,
234-
});
236+
logger.error(
237+
{
238+
chartConfig,
239+
alertId: alert.id,
240+
},
241+
'Failed to build chart config',
242+
);
235243
return;
236244
}
237245

@@ -241,13 +249,15 @@ export const processAlert = async (
241249
metadata,
242250
});
243251

244-
logger.info({
245-
message: `Received alert metric [${alert.source} source]`,
246-
alertId: alert.id,
247-
checksData,
248-
checkStartTime,
249-
checkEndTime,
250-
});
252+
logger.info(
253+
{
254+
alertId: alert.id,
255+
checksData,
256+
checkStartTime,
257+
checkEndTime,
258+
},
259+
`Received alert metric [${alert.source} source]`,
260+
);
251261

252262
// TODO: support INSUFFICIENT_DATA state
253263
const history: IAlertHistory = {
@@ -276,19 +286,23 @@ export const processAlert = async (
276286
);
277287

278288
if (timestampColumnName == null) {
279-
logger.error({
280-
message: 'Failed to find timestamp column',
281-
meta,
282-
alertId: alert.id,
283-
});
289+
logger.error(
290+
{
291+
meta,
292+
alertId: alert.id,
293+
},
294+
'Failed to find timestamp column',
295+
);
284296
return;
285297
}
286298
if (valueColumnNames.size === 0) {
287-
logger.error({
288-
message: 'Failed to find value column',
289-
meta,
290-
alertId: alert.id,
291-
});
299+
logger.error(
300+
{
301+
meta,
302+
alertId: alert.id,
303+
},
304+
'Failed to find value column',
305+
);
292306
return;
293307
}
294308

packages/api/src/tasks/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ const main = async (argv: TaskArgs) => {
3434
`Task [${task.name()}] finished in ${(performance.now() - t0).toFixed(2)} ms`,
3535
);
3636
} catch (e: unknown) {
37-
logger.error({
38-
message: `Task [${task.name()}] failed: ${serializeError(e)}`,
39-
cause: e,
40-
task,
41-
});
37+
logger.error(
38+
{
39+
cause: e,
40+
task,
41+
},
42+
`Task [${task.name()}] failed: ${serializeError(e)}`,
43+
);
4244
} finally {
4345
await task.asyncDispose();
4446
span.end();

packages/api/src/tasks/providers/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ export async function loadProvider(
102102
try {
103103
return providerFn();
104104
} catch (err) {
105-
logger.error({
106-
message: `error creating instance of ${providerName} provider; using default`,
107-
cause: err,
108-
providerName,
109-
});
105+
logger.error(
106+
{
107+
cause: err,
108+
providerName,
109+
},
110+
`error creating instance of ${providerName} provider; using default`,
111+
);
110112
}
111113
}
112114
}

packages/api/src/tasks/template.ts

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ function validateWebhookUrl(
106106
// check that hostname ends in "slack.com"
107107
if (!isValidSlackUrl(webhook.url)) {
108108
const message = `Slack Webhook URL ${webhook.url} does not have hostname that ends in 'slack.com'`;
109-
logger.warn({
110-
webhook: {
111-
id: webhook._id.toString(),
112-
name: webhook.name,
113-
url: webhook.url,
114-
body: webhook.body,
109+
logger.warn(
110+
{
111+
webhook: {
112+
id: webhook._id.toString(),
113+
name: webhook.name,
114+
url: webhook.url,
115+
body: webhook.body,
116+
},
115117
},
116118
message,
117-
});
119+
);
118120
throw new Error(`SSRF AllowedDomainError: ${message}`);
119121
}
120122
} else {
@@ -124,15 +126,17 @@ function validateWebhookUrl(
124126
const message = `Webhook attempting to query blacklisted route ${blacklistedWebhookHosts.get(
125127
url.host,
126128
)}`;
127-
logger.warn({
128-
webhook: {
129-
id: webhook._id.toString(),
130-
name: webhook.name,
131-
url: webhook.url,
132-
body: webhook.body,
129+
logger.warn(
130+
{
131+
webhook: {
132+
id: webhook._id.toString(),
133+
name: webhook.name,
134+
url: webhook.url,
135+
body: webhook.body,
136+
},
133137
},
134138
message,
135-
});
139+
);
136140
throw new Error(`SSRF AllowedDomainError: ${message}`);
137141
}
138142
}
@@ -200,10 +204,12 @@ export const handleSendGenericWebhook = async (
200204
title: escapeJsonString(message.title),
201205
});
202206
} catch (e) {
203-
logger.error({
204-
message: 'Failed to compile generic webhook body',
205-
error: serializeError(e),
206-
});
207+
logger.error(
208+
{
209+
error: serializeError(e),
210+
},
211+
'Failed to compile generic webhook body',
212+
);
207213
return;
208214
}
209215

@@ -220,10 +226,12 @@ export const handleSendGenericWebhook = async (
220226
throw new Error(errorText);
221227
}
222228
} catch (e) {
223-
logger.error({
224-
message: 'Failed to send generic webhook message',
225-
error: serializeError(e),
226-
});
229+
logger.error(
230+
{
231+
error: serializeError(e),
232+
},
233+
'Failed to send generic webhook message',
234+
);
227235
}
228236
};
229237

@@ -508,12 +516,14 @@ export const renderAlertTemplate = async ({
508516
2500,
509517
);
510518
} catch (e) {
511-
logger.error({
512-
message: 'Failed to fetch sample logs',
513-
savedSearchId: savedSearch.id,
514-
chartConfig,
515-
error: serializeError(e),
516-
});
519+
logger.error(
520+
{
521+
savedSearchId: savedSearch.id,
522+
chartConfig,
523+
error: serializeError(e),
524+
},
525+
'Failed to fetch sample logs',
526+
);
517527
}
518528

519529
rawTemplateBody = `${group ? `Group: "${group}"` : ''}

packages/api/src/tasks/usageStats.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -128,37 +128,39 @@ async function getUsageStats() {
128128
getClickhouseTableSize(),
129129
]);
130130
const clusterId = team[0]?._id.toString();
131-
logger.info({
132-
message: 'track-hyperdx-oss-usage-stats',
133-
clusterId,
134-
version: config.CODE_VERSION,
135-
userCounts,
136-
os: {
137-
arch: os.arch(),
138-
freemem: os.freemem(),
139-
uptime: os.uptime(),
140-
},
141-
chStats: {
142-
tables: chTables.reduce(
143-
(acc, curr) => ({
144-
...acc,
145-
[curr.table]: {
146-
avgDaySize: parseInt(curr.avgDaySize),
147-
days: parseInt(curr.days),
148-
lastModified: new Date(curr.latestModification).getTime(),
149-
maxTime: new Date(curr.max_time).getTime(),
150-
minTime: new Date(curr.min_time).getTime(),
151-
rows: parseInt(curr.rows),
152-
size: parseInt(curr.size),
153-
},
154-
}),
155-
{},
156-
),
157-
rows: chTables.reduce((acc, curr) => acc + parseInt(curr.rows), 0),
158-
size: chTables.reduce((acc, curr) => acc + parseInt(curr.size), 0),
131+
logger.info(
132+
{
133+
clusterId,
134+
version: config.CODE_VERSION,
135+
userCounts,
136+
os: {
137+
arch: os.arch(),
138+
freemem: os.freemem(),
139+
uptime: os.uptime(),
140+
},
141+
chStats: {
142+
tables: chTables.reduce(
143+
(acc, curr) => ({
144+
...acc,
145+
[curr.table]: {
146+
avgDaySize: parseInt(curr.avgDaySize),
147+
days: parseInt(curr.days),
148+
lastModified: new Date(curr.latestModification).getTime(),
149+
maxTime: new Date(curr.max_time).getTime(),
150+
minTime: new Date(curr.min_time).getTime(),
151+
rows: parseInt(curr.rows),
152+
size: parseInt(curr.size),
153+
},
154+
}),
155+
{},
156+
),
157+
rows: chTables.reduce((acc, curr) => acc + parseInt(curr.rows), 0),
158+
size: chTables.reduce((acc, curr) => acc + parseInt(curr.size), 0),
159+
},
160+
timestamp: nowInMs,
159161
},
160-
timestamp: nowInMs,
161-
});
162+
'track-hyperdx-oss-usage-stats',
163+
);
162164
} catch (err) {
163165
// ignore
164166
}

0 commit comments

Comments
 (0)