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:
fengmk2
2025-07-10 23:43:12 +08:00
committed by GitHub
parent 46901c472c
commit fc1104cd68
2 changed files with 13 additions and 3 deletions

View File

@@ -59,7 +59,8 @@ export type KnownMetricScopes =
| 'mail'
| 'ai'
| 'event'
| 'queue';
| 'queue'
| 'storage';
const metricCreators: MetricCreators = {
counter(meter: Meter, name: string, opts?: MetricOptions) {

View File

@@ -4,6 +4,7 @@ import {
autoMetadata,
Config,
EventBus,
metrics,
OnEvent,
type StorageProvider,
StorageProviderFactory,
@@ -69,15 +70,23 @@ export class CommentAttachmentStorage {
blob,
meta
);
const mime = meta.contentType ?? 'application/octet-stream';
const size = blob.length;
await this.models.commentAttachment.upsert({
workspaceId,
docId,
key,
name,
mime: meta.contentType ?? 'application/octet-stream',
size: blob.length,
mime,
size,
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(