Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { buildNewMessageUpdate, eventRouter } from "@/app/events/eventRouter";
import { messageEncryptedBytesHistogram, messageBatchSizeHistogram } from "@/app/monitoring/metrics2";
import { db } from "@/storage/db";
import { allocateSessionSeqBatch, allocateUserSeq } from "@/storage/seq";
import { randomKeyNaked } from "@/utils/randomKeyNaked";
Expand Down Expand Up @@ -112,6 +113,12 @@ export function v3SessionRoutes(app: Fastify) {
const { sessionId } = request.params;
const { messages } = request.body;

// Record message size metrics for compression baseline
messageBatchSizeHistogram.observe(messages.length);
for (const msg of messages) {
messageEncryptedBytesHistogram.observe(Buffer.byteLength(msg.content, 'utf8'));
}

const session = await db.session.findFirst({
where: {
id: sessionId,
Expand Down
15 changes: 15 additions & 0 deletions packages/happy-server/sources/app/monitoring/metrics2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ export const httpRequestDurationHistogram = new Histogram({
registers: [register]
});

// Message size metrics (for compression baseline)
export const messageEncryptedBytesHistogram = new Histogram({
name: 'happy_message_encrypted_bytes',
help: 'Size of encrypted message content in bytes (base64-encoded ciphertext)',
buckets: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144],
registers: [register]
});

export const messageBatchSizeHistogram = new Histogram({
name: 'happy_message_batch_count',
help: 'Number of messages per batch POST',
buckets: [1, 2, 3, 5, 10, 20, 50, 100],
registers: [register]
});

// Database count metrics
export const databaseRecordCountGauge = new Gauge({
name: 'database_records_total',
Expand Down