<commit_before>﻿// <copyright file="ElasticSearchReporterSettings.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using App.Metrics.Abstractions.Reporting;
using App.Metrics.Extensions.Reporting.ElasticSearch.Client;
using App.Metrics.Reporting;

namespace App.Metrics.Extensions.Reporting.ElasticSearch
{
    public class ElasticSearchReporterSettings : IReporterSettings
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ElasticSearchReporterSettings" /> class.
        /// </summary>
        public ElasticSearchReporterSettings()
        {
            var customHistogramDataKeys = new Dictionary<HistogramValueDataKeys, string>
                                          {
                                              { HistogramValueDataKeys.Count, "countHist" },
                                              { HistogramValueDataKeys.UserLastValue, "userLast" },
                                              { HistogramValueDataKeys.UserMinValue, "userMin" },
                                              { HistogramValueDataKeys.UserMaxValue, "userMax" }
                                          };

            var customMeterDataKeys = new Dictionary<MeterValueDataKeys, string>
                                      {
                                          { MeterValueDataKeys.Count, "countMeter" },
                                          { MeterValueDataKeys.RateMean, "rateMean" }
                                      };
            DataKeys = new MetricValueDataKeys(histogram: customHistogramDataKeys, meter: customMeterDataKeys);

            ElasticSearchSettings = new ElasticSearchSettings(new Uri("http://localhost:9200"), "metrics");
            HttpPolicy = new HttpPolicy
                         {
                             FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff,
                             BackoffPeriod = Constants.DefaultBackoffPeriod,
                             Timeout = Constants.DefaultTimeout
                         };
            ReportInterval = TimeSpan.FromSeconds(5);
            MetricNameFormatter = (metricContext, metricName) => string.IsNullOrWhiteSpace(metricContext)
                ? $"{metricName}".Replace(' ', '_').ToLowerInvariant()
                : $"{metricContext}__{metricName}".Replace(' ', '_').ToLowerInvariant();
            MetricTagValueFormatter = tagValue => tagValue.Replace("=", "\\=")
                                                          .Replace(@"\", @"\\\")
                                                          .Replace(@"/", @"\\/")
                                                          .Replace(" ", "\\ ")
                                                          .Replace(",", "\\,");
        }

        /// <summary>
        ///     Gets or sets the HTTP policy settings which allows circuit breaker configuration to be adjusted
        /// </summary>
        /// <value><commit_msg>#112 more es document tag escaping<commit_after>﻿// <copyright file="ElasticSearchReporterSettings.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using App.Metrics.Abstractions.Reporting;
using App.Metrics.Extensions.Reporting.ElasticSearch.Client;
using App.Metrics.Reporting;

namespace App.Metrics.Extensions.Reporting.ElasticSearch
{
    public class ElasticSearchReporterSettings : IReporterSettings
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ElasticSearchReporterSettings" /> class.
        /// </summary>
        public ElasticSearchReporterSettings()
        {
            var customHistogramDataKeys = new Dictionary<HistogramValueDataKeys, string>
                                          {
                                              { HistogramValueDataKeys.Count, "countHist" },
                                              { HistogramValueDataKeys.UserLastValue, "userLast" },
                                              { HistogramValueDataKeys.UserMinValue, "userMin" },
                                              { HistogramValueDataKeys.UserMaxValue, "userMax" }
                                          };

            var customMeterDataKeys = new Dictionary<MeterValueDataKeys, string>
                                      {
                                          { MeterValueDataKeys.Count, "countMeter" },
                                          { MeterValueDataKeys.RateMean, "rateMean" }
                                      };
            DataKeys = new MetricValueDataKeys(histogram: customHistogramDataKeys, meter: customMeterDataKeys);

            ElasticSearchSettings = new ElasticSearchSettings(new Uri("http://localhost:9200"), "metrics");
            HttpPolicy = new HttpPolicy
                         {
                             FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff,
                             BackoffPeriod = Constants.DefaultBackoffPeriod,
                             Timeout = Constants.DefaultTimeout
                         };
            ReportInterval = TimeSpan.FromSeconds(5);
            MetricNameFormatter = (metricContext, metricName) => string.IsNullOrWhiteSpace(metricContext)
                ? $"{metricName}".Replace(' ', '_').ToLowerInvariant()
                : $"{metricContext}__{metricName}".Replace(' ', '_').ToLowerInvariant();
            MetricTagValueFormatter = tagValue => tagValue
                                                          .Replace(@"\", "_")
                                                          .Replace(@"/", "_")
                                                          .Replace(' ', '_')
                                                          .Replace(',', '_');
        }

        /// <summary>
        ///     Gets or sets the HTTP policy settings which allows circuit breaker configuration to be adjusted
        /// </summary>
        /// <value>
{'fraction_non_alphanumeric': 0.0960554546954943, 'fraction_numerical': 0.002145568575672553, 'mean_word_length': 1.3718199608610568, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651372', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1241, 'n_words': 238}