From 7fe92271d4b2f04438b16a8b292d26a878c178eb Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Fri, 27 Sep 2024 11:09:51 -0500 Subject: [PATCH] Add ability to set a metrics prefix --- src/Foundatio/Queues/QueueBase.cs | 2 ++ src/Foundatio/Queues/SharedQueueOptions.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Foundatio/Queues/QueueBase.cs b/src/Foundatio/Queues/QueueBase.cs index 07f53e8f..5f045dad 100644 --- a/src/Foundatio/Queues/QueueBase.cs +++ b/src/Foundatio/Queues/QueueBase.cs @@ -41,6 +41,8 @@ protected QueueBase(TOptions options) : base(options?.TimeProvider, options?.Log { _options = options ?? throw new ArgumentNullException(nameof(options)); _metricsPrefix = $"foundatio.{typeof(T).Name.ToLowerInvariant()}"; + if (!String.IsNullOrEmpty(options.MetricsPrefix)) + _metricsPrefix = $"{_metricsPrefix}.{options.MetricsPrefix}"; QueueId = options.Name + Guid.NewGuid().ToString("N").Substring(10); diff --git a/src/Foundatio/Queues/SharedQueueOptions.cs b/src/Foundatio/Queues/SharedQueueOptions.cs index 944e7589..76374938 100644 --- a/src/Foundatio/Queues/SharedQueueOptions.cs +++ b/src/Foundatio/Queues/SharedQueueOptions.cs @@ -9,6 +9,11 @@ public class SharedQueueOptions : SharedOptions where T : class public int Retries { get; set; } = 2; public TimeSpan WorkItemTimeout { get; set; } = TimeSpan.FromMinutes(5); public ICollection> Behaviors { get; set; } = new List>(); + + /// + /// Allows you to set a prefix on queue metrics. This allows you to have unique metrics for keyed queues (e.g., priority queues). + /// + public string MetricsPrefix { get; set; } } public class SharedQueueOptionsBuilder : SharedOptionsBuilder @@ -61,4 +66,14 @@ public TBuilder AddBehavior(IQueueBehavior behavior) return (TBuilder)this; } + + /// + /// Allows you to set a prefix on queue metrics. This allows you to have unique metrics for keyed queues (e.g., priority queues). + /// + public TBuilder MetricsPrefix(string prefix) + { + if (!String.IsNullOrEmpty(prefix)) + Target.MetricsPrefix = prefix; + return (TBuilder)this; + } }