Skip to content

Commit

Permalink
Add ability to set a metrics prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Sep 27, 2024
1 parent 609ec17 commit 7fe9227
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Foundatio/Queues/QueueBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions src/Foundatio/Queues/SharedQueueOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class SharedQueueOptions<T> : SharedOptions where T : class
public int Retries { get; set; } = 2;
public TimeSpan WorkItemTimeout { get; set; } = TimeSpan.FromMinutes(5);
public ICollection<IQueueBehavior<T>> Behaviors { get; set; } = new List<IQueueBehavior<T>>();

/// <summary>
/// Allows you to set a prefix on queue metrics. This allows you to have unique metrics for keyed queues (e.g., priority queues).
/// </summary>
public string MetricsPrefix { get; set; }
}

public class SharedQueueOptionsBuilder<T, TOptions, TBuilder> : SharedOptionsBuilder<TOptions, TBuilder>
Expand Down Expand Up @@ -61,4 +66,14 @@ public TBuilder AddBehavior(IQueueBehavior<T> behavior)

return (TBuilder)this;
}

/// <summary>
/// Allows you to set a prefix on queue metrics. This allows you to have unique metrics for keyed queues (e.g., priority queues).
/// </summary>
public TBuilder MetricsPrefix(string prefix)
{
if (!String.IsNullOrEmpty(prefix))
Target.MetricsPrefix = prefix;
return (TBuilder)this;
}
}

0 comments on commit 7fe9227

Please sign in to comment.