forked from man-group/dapr-sidekick-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaprMetricsOptions.cs
64 lines (55 loc) · 1.91 KB
/
DaprMetricsOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Collections.Generic;
namespace Man.Dapr.Sidekick
{
public class DaprMetricsOptions
{
/// <summary>
/// Gets or sets a value that determines whether the metrics collector is enabled for this component (default true).
/// </summary>
public bool? EnableCollector { get; set; }
/// <summary>
/// Gets or sets the labels to add to each metric line.
/// </summary>
public IDictionary<string, string> Labels { get; set; }
/// <summary>
/// Creates a deep clone of this instance.
/// </summary>
/// <returns>A deep clone of this insteance.</returns>
public DaprMetricsOptions Clone() => (DaprMetricsOptions)MemberwiseClone();
/// <summary>
/// Updates any undefined properties in this instance with the values in <paramref name="source"/> where specified.
/// </summary>
/// <param name="source">A source options instance.</param>
public void EnrichFrom(DaprMetricsOptions source)
{
if (source == null)
{
return;
}
EnableCollector ??= source.EnableCollector;
if (source.Labels != null)
{
foreach (var label in source.Labels)
{
SetLabel(label.Key, label.Value);
}
}
}
public void SetLabel(string name, string value, bool overwrite = false)
{
if (string.IsNullOrEmpty(name))
{
return;
}
if (Labels == null)
{
Labels = new Dictionary<string, string>();
}
// Set the label if not already existing or the overwrite flag is specified
if (!Labels.ContainsKey(name) || overwrite)
{
Labels[name] = value;
}
}
}
}