-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Message processing metrics manager (#1050)
- Loading branch information
Showing
6 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/infrastructure/metrics/MessageProcessingMetricsManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { ConsumerBaseMessageType, ProcessedMessageMetadata } from '@message-queue-toolkit/core' | ||
import { | ||
MessageLifetimeMetric, | ||
MessageProcessingMultiMetrics, | ||
MessageProcessingTimeMetric, | ||
} from '@message-queue-toolkit/metrics' | ||
import type { IFastifyMetrics } from 'fastify-metrics' | ||
|
||
export class MessageProcessingMetricsManager extends MessageProcessingMultiMetrics<ConsumerBaseMessageType> { | ||
constructor(appMetrics: IFastifyMetrics) { | ||
const buckets = [100, 200, 300, 500, 1000, 3000, 10000, 50000, 100000] | ||
const messageVersionResolver = ( | ||
messageMetadata: ProcessedMessageMetadata<ConsumerBaseMessageType>, | ||
) => { | ||
return messageMetadata.message?.metadata.schemaVersion | ||
} | ||
|
||
super([ | ||
new MessageProcessingTimeMetric( | ||
{ | ||
name: 'message_processing_milliseconds', | ||
helpDescription: 'Message processing time in milliseconds', | ||
buckets, | ||
messageVersion: messageVersionResolver, | ||
}, | ||
appMetrics.client, | ||
), | ||
new MessageLifetimeMetric( | ||
{ | ||
name: 'message_lifetime_milliseconds', | ||
helpDescription: 'Message lifetime in milliseconds', | ||
buckets, | ||
messageVersion: messageVersionResolver, | ||
}, | ||
appMetrics.client, | ||
), | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters