-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathElasticsearchFormatterConstants.cs
28 lines (24 loc) · 1.23 KB
/
ElasticsearchFormatterConstants.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
// <copyright file="ElasticsearchFormatterConstants.cs" company="Allan Hardy">
// Copyright (c) Allan Hardy. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
namespace App.Metrics.Formatters.Elasticsearch.Internal
{
public static class ElasticsearchFormatterConstants
{
public class ElasticsearchDefaults
{
public static readonly string[] SpecialChars = { @"\", @"/", " ", "-", "+", "=", "{", "}", "[", "]", ":", "&", "^", "~", "?", "!", "," };
public static readonly Func<string, string, string> MetricNameFormatter =
(metricContext, metricName) => string.IsNullOrWhiteSpace(metricContext)
? SpecialChars.Aggregate(metricName, (current, @char) => current.Replace(@char, "_")).ToLowerInvariant()
: SpecialChars.Aggregate($"{metricContext}__{metricName}", (current, @char) => current.Replace(@char, "_")).ToLowerInvariant();
public static readonly Func<string, string> MetricTagValueFormatter = tagValue =>
{
return SpecialChars.Aggregate(tagValue, (current, @char) => current.Replace(@char, "_")).ToLowerInvariant();
};
}
}
}