Exemplo n.º 1
0
        public IEnumerable <string> GetIndexNames(DiagnosticsSource source, int daysToGoBack = 7)
        {
            // static index name
            if (!string.IsNullOrEmpty(source.IndexName))
            {
                return new[] { source.IndexName }
            }
            ;

            if (String.IsNullOrEmpty(source.LastOffsetPoint))
            {
                source.LastOffsetPoint = DateTimeOffset.UtcNow.AddDays(-daysToGoBack).ToString("O");
            }

            var dateTimeOffset = FileOffset.Parse(source.LastOffsetPoint);

            var days = (int)(DateTimeOffset.UtcNow.AddDays(1) - dateTimeOffset.TimeOffset).TotalDays + 1; // to cover today as well - Aboo was here

            if (days <= 0)
            {
                return(Enumerable.Empty <string>());
            }

            return(Enumerable.Range(0, days).Select(x => DateTimeOffset.UtcNow.AddDays(1).AddDays(-x))
                   .Select(z => _indexNamer.BuildName(dateTimeOffset.TimeOffset, source.GetMappingName().ToLowerInvariant())));
        }
    }
Exemplo n.º 2
0
        private async Task SetupMappingsAsync(DiagnosticsSource source)
        {
            foreach (var indexName in source.GetIndexNames())
            {
                var esUrl = _configurationValueProvider.GetValue(ConfigurationKeys.ElasticSearchUrl);
                await _elasticsearchClient.CreateIndexIfNotExistsAsync(esUrl, indexName);

                if (!await _elasticsearchClient.MappingExistsAsync(esUrl, indexName, source.ToTypeKey()))
                {
                    var jsonPath = string.Format("{0}{1}.json",
                                                 _configurationValueProvider.GetValue(ConfigurationKeys.MappingsPath),
                                                 source.GetMappingName());

                    var response = await _nonAuthenticatingClient.GetAsync(jsonPath);

                    if (response.Content == null)
                    {
                        throw new ApplicationException(response.ToString());
                    }

                    var content = await response.Content.ReadAsStringAsync();

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new InvalidOperationException(content);
                    }

                    var mapping = content.Replace("___type_name___", source.ToTypeKey());
                    await _elasticsearchClient.UpdateMappingAsync(esUrl, indexName, source.ToTypeKey(), mapping);
                }
            }
        }
Exemplo n.º 3
0
        private async Task SetupMappingsAsync(DiagnosticsSource source)
        {
            foreach (var indexName in source.GetIndexNames())
            {
                var esUrl = _configurationValueProvider.GetValue(ConfigurationKeys.ElasticSearchUrl);
                await _elasticsearchClient.CreateIndexIfNotExistsAsync(esUrl, indexName);

                if (!await _elasticsearchClient.MappingExistsAsync(esUrl, indexName, source.ToTypeKey()))
                {
                    var jsonPath = string.Format("{0}{1}.json",
                                                 _configurationValueProvider.GetValue(ConfigurationKeys.MappingsPath),
                                                 source.GetMappingName());
                    var client  = new WebClient();
                    var mapping = client.DownloadString(jsonPath).Replace("___type_name___", source.ToTypeKey());
                    await _elasticsearchClient.UpdateMappingAsync(esUrl, indexName, source.ToTypeKey(), mapping);
                }
            }
        }
Exemplo n.º 4
0
 private async Task SetupMappingsAsync(DiagnosticsSource source)
 {
     
     foreach (var indexName in source.GetIndexNames())
     {
         var esUrl = _configurationValueProvider.GetValue(ConfigurationKeys.ElasticSearchUrl);
         await _elasticsearchClient.CreateIndexIfNotExistsAsync(esUrl, indexName);
         if (!await _elasticsearchClient.MappingExistsAsync(esUrl, indexName, source.ToTypeKey()))
         {
             var jsonPath = string.Format("{0}{1}.json",
                 _configurationValueProvider.GetValue(ConfigurationKeys.MappingsPath),
                 source.GetMappingName());
             var client = new WebClient();
             var mapping = client.DownloadString(jsonPath).Replace("___type_name___", source.ToTypeKey());
             await _elasticsearchClient.UpdateMappingAsync(esUrl, indexName, source.ToTypeKey(), mapping);
         }
     }
 }