chore(server): add comment attachment storage metrics (#13143)
close AF-2728 #### PR Dependency Tree * **PR #13143** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added metrics tracking for comment attachment uploads, including recording attachment size and total uploads by MIME type. * Enhanced logging for attachment uploads with detailed information such as workspace ID, document ID, file size, and user ID. * **Chores** * Expanded internal metric categories to include storage-related metrics. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -59,7 +59,8 @@ export type KnownMetricScopes =
|
|||||||
| 'mail'
|
| 'mail'
|
||||||
| 'ai'
|
| 'ai'
|
||||||
| 'event'
|
| 'event'
|
||||||
| 'queue';
|
| 'queue'
|
||||||
|
| 'storage';
|
||||||
|
|
||||||
const metricCreators: MetricCreators = {
|
const metricCreators: MetricCreators = {
|
||||||
counter(meter: Meter, name: string, opts?: MetricOptions) {
|
counter(meter: Meter, name: string, opts?: MetricOptions) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
autoMetadata,
|
autoMetadata,
|
||||||
Config,
|
Config,
|
||||||
EventBus,
|
EventBus,
|
||||||
|
metrics,
|
||||||
OnEvent,
|
OnEvent,
|
||||||
type StorageProvider,
|
type StorageProvider,
|
||||||
StorageProviderFactory,
|
StorageProviderFactory,
|
||||||
@@ -69,15 +70,23 @@ export class CommentAttachmentStorage {
|
|||||||
blob,
|
blob,
|
||||||
meta
|
meta
|
||||||
);
|
);
|
||||||
|
const mime = meta.contentType ?? 'application/octet-stream';
|
||||||
|
const size = blob.length;
|
||||||
await this.models.commentAttachment.upsert({
|
await this.models.commentAttachment.upsert({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
docId,
|
docId,
|
||||||
key,
|
key,
|
||||||
name,
|
name,
|
||||||
mime: meta.contentType ?? 'application/octet-stream',
|
mime,
|
||||||
size: blob.length,
|
size,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
metrics.storage.histogram('comment_attachment_size').record(size, { mime });
|
||||||
|
metrics.storage.counter('comment_attachment_total').add(1, { mime });
|
||||||
|
this.logger.log(
|
||||||
|
`uploaded comment attachment ${workspaceId}/${docId}/${key} with size ${size}, mime: ${mime}, name: ${name}, user: ${userId}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(
|
async get(
|
||||||
|
|||||||
Reference in New Issue
Block a user