From 9de727b98ccd44e8451dab9f4dfbbe10fa6623b5 Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Fri, 27 Sep 2024 11:31:24 -0500 Subject: [PATCH] Trim the names just to be sure the metrics are valid --- src/Foundatio/Queues/QueueBase.cs | 6 +++--- src/Foundatio/Queues/SharedQueueOptions.cs | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Foundatio/Queues/QueueBase.cs b/src/Foundatio/Queues/QueueBase.cs index 5f045dad..185057ae 100644 --- a/src/Foundatio/Queues/QueueBase.cs +++ b/src/Foundatio/Queues/QueueBase.cs @@ -41,10 +41,10 @@ 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}"; + if (!String.IsNullOrWhiteSpace(options.MetricsPrefix)) + _metricsPrefix = $"{_metricsPrefix}.{options.MetricsPrefix.Trim()}"; - QueueId = options.Name + Guid.NewGuid().ToString("N").Substring(10); + QueueId = $"{options.Name.Trim()}{Guid.NewGuid().ToString("N").Substring(10)}"; _serializer = options.Serializer ?? DefaultSerializer.Instance; options.Behaviors.ForEach(AttachBehavior); diff --git a/src/Foundatio/Queues/SharedQueueOptions.cs b/src/Foundatio/Queues/SharedQueueOptions.cs index 76374938..cf1caa5b 100644 --- a/src/Foundatio/Queues/SharedQueueOptions.cs +++ b/src/Foundatio/Queues/SharedQueueOptions.cs @@ -23,8 +23,9 @@ public class SharedQueueOptionsBuilder : SharedOptionsBui { public TBuilder Name(string name) { - if (!String.IsNullOrEmpty(name)) - Target.Name = name; + if (!String.IsNullOrWhiteSpace(name)) + Target.Name = name.Trim(); + return (TBuilder)this; } @@ -72,8 +73,8 @@ public TBuilder AddBehavior(IQueueBehavior behavior) /// public TBuilder MetricsPrefix(string prefix) { - if (!String.IsNullOrEmpty(prefix)) - Target.MetricsPrefix = prefix; + if (!String.IsNullOrWhiteSpace(prefix)) + Target.MetricsPrefix = prefix.Trim(); return (TBuilder)this; } }