From 3502b6b013f4202e785c833f665338a9d4cbd7bc Mon Sep 17 00:00:00 2001 From: Alex McCool Date: Fri, 23 Mar 2018 00:15:04 -0700 Subject: [PATCH] Remove type for index (#12) * testing 151 compatibility * unit test project removed the Orleans Converters ---- taking a chance here bump to 1.5.1 * just save this branch * cleanout nest * use index not type to differenciate on different log types --- .../ClientMetricsEntry.cs | 20 -- .../ElasticClientMetricsProvider.cs | 221 ----------------- .../ElasticSearchTelemetryConsumer.cs | 75 +++--- .../ElasticStatisticsProvider.cs | 232 ------------------ .../ProviderConfigurationExtensions.cs | 46 ---- ...ns.TelemetryConsumers.ElasticSearch.csproj | 7 - .../SiloMetricsEntry.cs | 32 --- src/ElasticSearchTelemetryConsumer/State.cs | 16 -- .../StatsTableEntry.cs | 20 -- test/TestHost/OrleansHostWrapper.cs | 2 +- 10 files changed, 43 insertions(+), 628 deletions(-) delete mode 100644 src/ElasticSearchTelemetryConsumer/ClientMetricsEntry.cs delete mode 100644 src/ElasticSearchTelemetryConsumer/ElasticClientMetricsProvider.cs delete mode 100644 src/ElasticSearchTelemetryConsumer/ElasticStatisticsProvider.cs delete mode 100644 src/ElasticSearchTelemetryConsumer/Extensions/ProviderConfigurationExtensions.cs delete mode 100644 src/ElasticSearchTelemetryConsumer/SiloMetricsEntry.cs delete mode 100644 src/ElasticSearchTelemetryConsumer/State.cs delete mode 100644 src/ElasticSearchTelemetryConsumer/StatsTableEntry.cs diff --git a/src/ElasticSearchTelemetryConsumer/ClientMetricsEntry.cs b/src/ElasticSearchTelemetryConsumer/ClientMetricsEntry.cs deleted file mode 100644 index 400eceb..0000000 --- a/src/ElasticSearchTelemetryConsumer/ClientMetricsEntry.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Orleans.Telemetry -{ - internal class ClientMetricsEntry - { - public string Address { get; set; } - public long AvailablePhysicalMemory { get; set; } - public string ClientId { get; set; } - public long ConnectedGatewayCount { get; set; } - public float CpuUsage { get; set; } - public string DeploymentId { get; set; } - public string HostName { get; set; } - public long MemoryUsage { get; set; } - public long ReceivedMessages { get; set; } - public int ReceiveQueueLength { get; set; } - public int SendQueueLength { get; set; } - public long SentMessages { get; set; } - public string Time { get; set; } - public long TotalPhysicalMemory { get; set; } - } -} \ No newline at end of file diff --git a/src/ElasticSearchTelemetryConsumer/ElasticClientMetricsProvider.cs b/src/ElasticSearchTelemetryConsumer/ElasticClientMetricsProvider.cs deleted file mode 100644 index c61de6c..0000000 --- a/src/ElasticSearchTelemetryConsumer/ElasticClientMetricsProvider.cs +++ /dev/null @@ -1,221 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Dynamic; -//using System.Globalization; -//using System.Linq; -//using System.Net; -//using System.Threading.Tasks; -//using Orleans; -//using Orleans.Runtime; -//using Orleans.Providers; -//using Nest; -//using Orleans.Runtime.Configuration; - -//namespace Orleans.Telemetry -//{ -// public class ElasticClientMetricsProvider : -// IConfigurableClientMetricsDataPublisher, -// IClientMetricsDataPublisher, -// IStatisticsPublisher, -// IProvider -// { -// private string _elasticHostAddress; -// private string _elasticIndex { get; set; } = "orleans_statistics"; -// private string _elasticMetricType { get; set; } = "metric"; -// private string _elasticCounterType { get; set; } = "counter"; - - -// private string ElasticHostAddress() => _elasticHostAddress; -// private string ElasticIndex() => _elasticIndex + "-" + DateTime.UtcNow.ToString("yyyy-MM-dd-HH"); -// private string ElasticMetricType() => _elasticMetricType; -// private string ElasticCounterType() => _elasticCounterType; - - -// // Example: 2010-09-02 09:50:43.341 GMT - Variant of UniversalSorta­bleDateTimePat­tern -// const string DATE_TIME_FORMAT = "yyyy-MM-dd-" + "HH:mm:ss.fff 'GMT'"; -// int MAX_BULK_UPDATE_DOCS = 200; -// State _state = new State(); -// Logger _logger; - -// /// -// /// Name of the provider -// /// -// public string Name { get; private set; } - -// /// -// /// Closes provider -// /// -// public Task Close() => TaskDone.Done; - -// /// -// /// Initialization of ElasticStatisticsProvider -// /// -// public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) -// { -// Name = name; -// _state.ServiceId = providerRuntime.ServiceId; -// _logger = providerRuntime.GetLogger(typeof(ElasticClientMetricsProvider).Name); - -// if (config.Properties.ContainsKey("ElasticHostAddress")) -// _elasticHostAddress = config.Properties["ElasticHostAddress"]; - -// if (config.Properties.ContainsKey("ElasticIndex")) -// _elasticIndex = config.Properties["ElasticIndex"]; - -// if (config.Properties.ContainsKey("ElasticMetricType")) -// _elasticMetricType = config.Properties["ElasticMetricType"]; -// if (config.Properties.ContainsKey("ElasticCounterype")) -// _elasticCounterType = config.Properties["ElasticCounterType"]; - -// if (string.IsNullOrWhiteSpace(name)) -// throw new ArgumentNullException(nameof(name)); -// if (string.IsNullOrWhiteSpace(_elasticHostAddress)) -// throw new ArgumentNullException("ElasticHostAddress"); -// if (string.IsNullOrWhiteSpace(_elasticIndex)) -// throw new ArgumentNullException("ElasticIndex"); -// if (string.IsNullOrWhiteSpace(_elasticMetricType)) -// throw new ArgumentNullException("ElasticMetricType"); -// if (string.IsNullOrWhiteSpace(_elasticCounterType)) -// throw new ArgumentNullException("ElasticCounterType"); - - -// return TaskDone.Done; -// } - -// public void AddConfiguration(string deploymentId, string hostName, string clientId, IPAddress address) -// { -// _state.DeploymentId = deploymentId; -// _state.Id = clientId; -// _state.Address = address.ToString(); -// _state.HostName = hostName; -// } - - -// public Task Init(ClientConfiguration config, IPAddress address, string clientId) -// { -// _state.Id = clientId; -// _state.Address = address.ToString(); - -// return TaskDone.Done; -// } - -// public Task Init(bool isSilo, string storageConnectionString, string deploymentId, string address, -// string siloName, string hostName) => TaskDone.Done; - - - -// /// -// /// Metrics for client -// /// -// public async Task ReportMetrics(IClientPerformanceMetrics metricsData) -// { -// if (_logger != null && _logger.IsVerbose3) -// _logger.Verbose3($"{nameof(ElasticClientMetricsProvider)}.ReportMetrics called with metrics: {0}, name: {1}, id: {2}.", metricsData, _state.SiloName, _state.Id); - -// try -// { -// var esClient = CreateElasticClient(ElasticHostAddress()); - -// var clientMetrics = PopulateClientMetricsEntry(metricsData, _state); - -// var response = await esClient.IndexAsync(clientMetrics, (ds) => ds.Index(ElasticIndex()) -// .Type(ElasticMetricType())); - -// if (!response.IsValid && _logger != null && _logger.IsVerbose) -// _logger.Verbose($"status: {response.ServerError.Status}, error: {response.ServerError.Error}"); -// } -// catch (Exception ex) -// { -// if (_logger != null && _logger.IsVerbose) -// _logger.Verbose($"{ nameof(ElasticClientMetricsProvider)}.ReportMetrics failed: {0}", ex); - -// throw; -// } -// } - -// /// -// /// Stats for Silo and Client -// /// -// public async Task ReportStats(List statsCounters) -// { -// if (_logger != null && _logger.IsVerbose3) -// _logger.Verbose3($"{ nameof(ElasticClientMetricsProvider)}.ReportStats called with {0} counters, name: {1}, id: {2}", statsCounters.Count, _state.SiloName, _state.Id); - -// try -// { -// var esClient = CreateElasticClient(ElasticHostAddress()); - -// var counterBatches = statsCounters.Where(cs => cs.Storage == CounterStorage.LogAndTable) -// .OrderBy(cs => cs.Name) -// .Select(cs => PopulateStatsTableEntry(cs, _state)) -// .BatchIEnumerable(MAX_BULK_UPDATE_DOCS); - -// foreach (var batch in counterBatches) -// { -// var bulkDesc = new BulkDescriptor(); -// bulkDesc.IndexMany(batch, (bulk, q) => bulk.Index(ElasticIndex()) -// .Type(ElasticCounterType())); - -// var response = await esClient.BulkAsync(bulkDesc); - -// if (response.Errors && _logger != null && _logger.IsVerbose) -// _logger.Error(0, $"status: {response.ServerError.Status}, error: {response.ServerError.Error}"); -// } -// } -// catch (Exception ex) -// { -// if (_logger != null && _logger.IsVerbose) -// _logger.Verbose($"{ nameof(ElasticClientMetricsProvider)}.ReportStats failed: {0}", ex); - -// throw; -// } -// } - - -// static ElasticClient CreateElasticClient(string elasticHostAddress) -// { -// var node = new Uri(elasticHostAddress); -// return new ElasticClient(new ConnectionSettings(node)); -// } - -// static ClientMetricsEntry PopulateClientMetricsEntry(IClientPerformanceMetrics metricsData, State state) -// { -// return new ClientMetricsEntry -// { -// ConnectedGatewayCount = metricsData.ConnectedGatewayCount, - -// ClientId = state.Id, -// DeploymentId = state.DeploymentId, -// Address = state.Address, -// HostName = state.HostName, - -// CpuUsage = metricsData.CpuUsage, -// TotalPhysicalMemory = metricsData.TotalPhysicalMemory, -// AvailablePhysicalMemory = metricsData.AvailablePhysicalMemory, -// MemoryUsage = metricsData.MemoryUsage, -// SendQueueLength = metricsData.SendQueueLength, -// ReceiveQueueLength = metricsData.ReceiveQueueLength, -// SentMessages = metricsData.SentMessages, -// ReceivedMessages = metricsData.ReceivedMessages, - -// Time = DateTime.UtcNow.ToString(DATE_TIME_FORMAT, CultureInfo.InvariantCulture) -// }; -// } - -// static dynamic PopulateStatsTableEntry(ICounter counter, State state) -// { -// var stat = new ExpandoObject() as IDictionary; -// stat.Add("ClientId", state.Id); - -// stat.Add("DeploymentId", state.DeploymentId); -// stat.Add("HostName", state.HostName); -// stat.Add("UtcDateTime", DateTimeOffset.UtcNow.UtcDateTime); -// stat.Add(counter.Name, counter.IsValueDelta ? float.Parse(counter.GetDeltaString()) : float.Parse(counter.GetValueString())); - -// return stat; -// } - - -// } - -//} diff --git a/src/ElasticSearchTelemetryConsumer/ElasticSearchTelemetryConsumer.cs b/src/ElasticSearchTelemetryConsumer/ElasticSearchTelemetryConsumer.cs index eb43028..44cd275 100644 --- a/src/ElasticSearchTelemetryConsumer/ElasticSearchTelemetryConsumer.cs +++ b/src/ElasticSearchTelemetryConsumer/ElasticSearchTelemetryConsumer.cs @@ -34,6 +34,7 @@ public class ElasticSearchTelemetryConsumer : IRequestTelemetryConsumer, IFlushableLogConsumer { + private const string DocumentType = "doc"; private readonly Uri _elasticSearchUri; private readonly string _indexPrefix; @@ -42,7 +43,7 @@ public class ElasticSearchTelemetryConsumer : private readonly string _dateFormatter; private readonly object _machineName; - public ElasticSearchTelemetryConsumer(Uri elasticSearchUri, string indexPrefix, string dateFormatter = "yyyy-MM-dd-HH", int bufferWaitSeconds = 1, int bufferSize = 50) + public ElasticSearchTelemetryConsumer(Uri elasticSearchUri, string indexPrefix, string dateFormatter = "yyyy-MM-dd-HH", int bufferWaitSeconds = 1, int bufferSize = 50) { _elasticSearchUri = elasticSearchUri; _indexPrefix = indexPrefix; @@ -76,27 +77,34 @@ public IElasticLowLevelClient GetClient(Uri esurl) } } - private void SetupObserverBatchy(TimeSpan waitTime, int bufferSize) - { - this._queueToBePosted.GetConsumingEnumerable() - .ToObservable(Scheduler.Default) - .Buffer(waitTime, bufferSize) - .Subscribe(async (x) => await this.ElasticSearchBulkWriter(x)); - } - - - private string ElasticIndex() => _indexPrefix + "-" + DateTime.UtcNow.ToString(_dateFormatter); //DateTime.UtcNow.ToString("yyyy-MM-dd-HH"); - private string ElasticMetricTelemetryType() => "metric"; - //private string ElastiTraceTelemetryType() => "trace"; - private string ElasticEventTelemetryType() => "event"; - private string ElasticExceptionTelemetryType() => "exception"; - private string ElasticDependencyTelemetryType() => "dependency"; - private string ElasticRequestTelemetryType() => "request"; - private string ElasticLogType() => "log"; - - #region IFlushableLogConsumer - - public void Log(Severity severity, LoggerType loggerType, string caller, string message, IPEndPoint myIPEndPoint, + private void SetupObserverBatchy(TimeSpan waitTime, int bufferSize) + { + this._queueToBePosted.GetConsumingEnumerable() + .ToObservable(Scheduler.Default) + .Buffer(waitTime, bufferSize) + .Subscribe(async (x) => await this.ElasticSearchBulkWriter(x)); + } + + + //private string ElasticIndex() => _indexPrefix + "-" + DateTime.UtcNow.ToString(_dateFormatter); + //private string ElastiTraceTelemetryType() => "trace"; //obsoleted + + //private string ElasticMetricTelemetryType() => "metric"; + private string ElasticMetricTelemetryIndex() => _indexPrefix + "-metric-" + DateTime.UtcNow.ToString(_dateFormatter); + //private string ElasticEventTelemetryType() => "event"; + private string ElasticEventTelemetryIndex() => _indexPrefix + "-event-" + DateTime.UtcNow.ToString(_dateFormatter); + //private string ElasticExceptionTelemetryType() => "exception"; + private string ElasticExceptionTelemetryIndex() => _indexPrefix + "-exception-" + DateTime.UtcNow.ToString(_dateFormatter); + //private string ElasticDependencyTelemetryType() => "dependency"; + private string ElasticDependencyTelemetryIndex() => _indexPrefix + "-dependency-" + DateTime.UtcNow.ToString(_dateFormatter); + //private string ElasticRequestTelemetryType() => "request"; + private string ElasticRequestTelemetryIndex() => _indexPrefix + "-request-" + DateTime.UtcNow.ToString(_dateFormatter); + //private string ElasticLogType() => "log"; + private string ElasticLogIndex() => _indexPrefix + "-log-" + DateTime.UtcNow.ToString(_dateFormatter); + + #region IFlushableLogConsumer + + public void Log(Severity severity, LoggerType loggerType, string caller, string message, IPEndPoint myIPEndPoint, Exception exception, int eventCode = 0) { Task.Run(async () => @@ -110,7 +118,7 @@ public void Log(Severity severity, LoggerType loggerType, string caller, string tm.Add("Exception", exception?.ToString()); tm.Add("EventCode", eventCode); - await FinalESWrite(tm, ElasticLogType); + await FinalESWrite(tm, ElasticLogIndex); }); } @@ -141,7 +149,7 @@ public void TrackException(Exception exception, IDictionary prop } } - await FinalESWrite(tm, ElasticExceptionTelemetryType); + await FinalESWrite(tm, ElasticExceptionTelemetryIndex); }); } @@ -242,7 +250,7 @@ public void WriteMetric(string name, double value, IDictionary p tm.Add(prop.Key, prop.Value); } } - await FinalESWrite(tm, ElasticMetricTelemetryType); + await FinalESWrite(tm, ElasticMetricTelemetryIndex); }); } @@ -263,7 +271,7 @@ public void TrackDependency(string dependencyName, string commandName, DateTimeO tm.Add("Duration", duration); tm.Add("Success", success); - await FinalESWrite(tm, ElasticDependencyTelemetryType); + await FinalESWrite(tm, ElasticDependencyTelemetryIndex); }); } @@ -283,7 +291,7 @@ public void TrackRequest(string name, DateTimeOffset startTime, TimeSpan duratio tm.Add("ResponseCode", responseCode); tm.Add("Success", success); - await FinalESWrite(tm, ElasticRequestTelemetryType); + await FinalESWrite(tm, ElasticRequestTelemetryIndex); }); } @@ -312,7 +320,7 @@ public void TrackEvent(string eventName, IDictionary properties } } - await FinalESWrite(tm, ElasticEventTelemetryType); + await FinalESWrite(tm, ElasticEventTelemetryIndex); }); } @@ -321,7 +329,7 @@ public void TrackEvent(string eventName, IDictionary properties #region FinalWrite - private async Task FinalESWrite(IDictionary tm, Func type) + private async Task FinalESWrite(IDictionary tm, Func index) { tm.Add("UtcDateTime", DateTimeOffset.UtcNow.UtcDateTime); tm.Add("MachineName", _machineName); @@ -334,8 +342,8 @@ private async Task FinalESWrite(IDictionary tm, Func typ _queueToBePosted.Add(new TelemetryRecord() { tm = jo, - IndexName = ElasticIndex(), - IndexType = type() + IndexName = index(), + IndexType = DocumentType }); } catch (Exception e) @@ -358,8 +366,9 @@ private async Task ElasticSearchBulkWriter(IEnumerable jos) try { var ret = await GetClient(this._elasticSearchUri) - .BulkPutAsync(this.ElasticIndex(), this.ElasticMetricTelemetryType(), - bbo.ToArray(), br => br.Refresh(false)); + .BulkPutAsync( + bbo.ToArray(), + br => br.Refresh(false)); } catch (Exception ex) { diff --git a/src/ElasticSearchTelemetryConsumer/ElasticStatisticsProvider.cs b/src/ElasticSearchTelemetryConsumer/ElasticStatisticsProvider.cs deleted file mode 100644 index 16ac613..0000000 --- a/src/ElasticSearchTelemetryConsumer/ElasticStatisticsProvider.cs +++ /dev/null @@ -1,232 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Dynamic; -//using System.Globalization; -//using System.Linq; -//using System.Net; -//using System.Threading.Tasks; -//using Orleans; -//using Orleans.Runtime; -//using Orleans.Providers; -//using Nest; - -//namespace Orleans.Telemetry -//{ -// public class ElasticStatisticsProvider : IConfigurableSiloMetricsDataPublisher, -// IStatisticsPublisher, -// IProvider -// { -// private string _elasticHostAddress; -// private string _elasticIndex { get; set; } = "orleans_statistics"; -// private string _elasticMetricType { get; set; } = "metric"; -// private string _elasticCounterType { get; set; } = "counter"; - - -// private string ElasticHostAddress() => _elasticHostAddress; -// private string ElasticIndex() => _elasticIndex + "-" + DateTime.UtcNow.ToString("yyyy-MM-dd-HH"); -// private string ElasticMetricType() => _elasticMetricType; -// private string ElasticCounterType() => _elasticCounterType; - - -// // Example: 2010-09-02 09:50:43.341 GMT - Variant of UniversalSorta­bleDateTimePat­tern -// const string DATE_TIME_FORMAT = "yyyy-MM-dd-" + "HH:mm:ss.fff 'GMT'"; -// int MAX_BULK_UPDATE_DOCS = 200; -// State _state = new State(); -// Logger _logger; - -// /// -// /// Name of the provider -// /// -// public string Name { get; private set; } - -// /// -// /// Closes provider -// /// -// public Task Close() => TaskDone.Done; - -// /// -// /// Initialization of ElasticStatisticsProvider -// /// -// public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) -// { -// Name = name; -// _state.Id = providerRuntime.SiloIdentity; -// _state.ServiceId = providerRuntime.ServiceId; -// _logger = providerRuntime.GetLogger(typeof(ElasticStatisticsProvider).Name); - -// if (config.Properties.ContainsKey("ElasticHostAddress")) -// _elasticHostAddress = config.Properties["ElasticHostAddress"]; - -// if (config.Properties.ContainsKey("ElasticIndex")) -// _elasticIndex = config.Properties["ElasticIndex"]; - -// if (config.Properties.ContainsKey("ElasticMetricType")) -// _elasticMetricType = config.Properties["ElasticMetricType"]; -// if (config.Properties.ContainsKey("ElasticCounterype")) -// _elasticCounterType = config.Properties["ElasticCounterType"]; - -// if (string.IsNullOrWhiteSpace(name)) -// throw new ArgumentNullException(nameof(name)); -// if (string.IsNullOrWhiteSpace(_elasticHostAddress)) -// throw new ArgumentNullException("ElasticHostAddress"); -// if (string.IsNullOrWhiteSpace(_elasticIndex)) -// throw new ArgumentNullException("ElasticIndex"); -// if (string.IsNullOrWhiteSpace(_elasticMetricType)) -// throw new ArgumentNullException("ElasticMetricType"); -// if (string.IsNullOrWhiteSpace(_elasticCounterType)) -// throw new ArgumentNullException("ElasticCounterType"); - - -// return TaskDone.Done; -// } - -// public Task Init(string deploymentId, string storageConnectionString, SiloAddress siloAddress, string siloName, IPEndPoint gateway, string hostName) -// { -// _state.DeploymentId = deploymentId; -// _state.SiloName = siloName; -// _state.GatewayAddress = gateway.ToString(); -// _state.HostName = hostName; - -// return TaskDone.Done; -// } - - -// public Task Init(bool isSilo, string storageConnectionString, string deploymentId, string address, -// string siloName, string hostName) -// { -// _state.DeploymentId = deploymentId; -// _state.IsSilo = isSilo; -// _state.SiloName = siloName; -// _state.Address = address.ToString(); -// _state.HostName = hostName; - -// return TaskDone.Done; -// } - - -// public void AddConfiguration(string deploymentId, bool isSilo, string siloName, SiloAddress address, IPEndPoint gateway, string hostName) -// { -// _state.DeploymentId = deploymentId; -// _state.IsSilo = isSilo; -// _state.SiloName = siloName; -// _state.Address = address.ToString(); -// _state.GatewayAddress = gateway.ToString(); -// _state.HostName = hostName; -// } - - -// /// -// /// Metrics for Silo -// /// -// public async Task ReportMetrics(ISiloPerformanceMetrics metricsData) -// { -// if (_logger != null && _logger.IsVerbose3) -// _logger.Verbose3($"{ nameof(ElasticStatisticsProvider)}.ReportMetrics called with metrics: {0}, name: {1}, id: {2}.", metricsData, _state.SiloName, _state.Id); - -// try -// { -// var esClient = CreateElasticClient(_elasticHostAddress); - -// var siloMetrics = PopulateSiloMetricsEntry(metricsData, _state); - -// var response = await esClient.IndexAsync(siloMetrics, (ds) => ds.Index(ElasticIndex()).Type(ElasticMetricType())); - -// if (!response.IsValid && _logger != null && _logger.IsVerbose) -// _logger.Verbose($"status: {response.ServerError.Status}, error: {response.ServerError.Error}"); -// } -// catch (Exception ex) -// { -// if (_logger != null && _logger.IsVerbose) -// _logger.Verbose($"{ nameof(ElasticStatisticsProvider)}.ReportMetrics failed: {0}", ex); - -// throw; -// } -// } - -// /// -// /// Stats for Silo and Client -// /// -// public async Task ReportStats(List statsCounters) -// { -// if (_logger != null && _logger.IsVerbose3) -// _logger.Verbose3($"{ nameof(ElasticStatisticsProvider)}.ReportStats called with {0} counters, name: {1}, id: {2}", statsCounters.Count, _state.SiloName, _state.Id); - -// try -// { -// var esClient = CreateElasticClient(_elasticHostAddress); - -// var counterBatches = statsCounters.Where(cs => cs.Storage == CounterStorage.LogAndTable) -// .OrderBy(cs => cs.Name) -// .Select(cs => PopulateStatsTableEntry(cs, _state)) -// .BatchIEnumerable(MAX_BULK_UPDATE_DOCS); - -// foreach (var batch in counterBatches) -// { -// var bulkDesc = new BulkDescriptor(); -// var b = bulkDesc.IndexMany(batch, (bulk, q) => bulk.Index(ElasticIndex()).Type(ElasticCounterType())); - -// var response = await esClient.BulkAsync(b); - -// if (response.Errors && _logger != null && _logger.IsVerbose) -// _logger.Error(0, $"status: {response.ServerError.Status}, error: {response.ServerError.Error}"); -// } -// } -// catch (Exception ex) -// { -// if (_logger != null && _logger.IsVerbose) -// _logger.Verbose($"{ nameof(ElasticStatisticsProvider)}.ReportStats failed: {0}", ex); - -// throw; -// } -// } - - -// static ElasticClient CreateElasticClient(string elasticHostAddress) -// { -// var node = new Uri(elasticHostAddress); -// return new ElasticClient(new ConnectionSettings(node)); -// } - -// static SiloMetricsEntry PopulateSiloMetricsEntry(ISiloPerformanceMetrics metricsData, State state) -// { -// return new SiloMetricsEntry -// { -// SiloId = state.Id, -// SiloName = state.SiloName, -// DeploymentId = state.DeploymentId, -// Address = state.Address, -// HostName = state.HostName, -// GatewayAddress = state.GatewayAddress, -// CpuUsage = metricsData.CpuUsage, -// TotalPhysicalMemory = metricsData.TotalPhysicalMemory, -// AvailablePhysicalMemory = metricsData.AvailablePhysicalMemory, -// MemoryUsage = metricsData.MemoryUsage, -// SendQueueLength = metricsData.SendQueueLength, -// ReceiveQueueLength = metricsData.ReceiveQueueLength, -// SentMessages = metricsData.SentMessages, -// ReceivedMessages = metricsData.ReceivedMessages, -// ActivationsCount = metricsData.ActivationCount, -// RecentlyUsedActivations = metricsData.RecentlyUsedActivationCount, -// RequestQueueLength = metricsData.ReceiveQueueLength, -// IsOverloaded = metricsData.IsOverloaded, -// ClientCount = metricsData.ClientCount, -// Time = DateTime.UtcNow.ToString(DATE_TIME_FORMAT, CultureInfo.InvariantCulture) , -// UtcDateTime = DateTimeOffset.UtcNow.UtcDateTime -// }; -// } - -// static dynamic PopulateStatsTableEntry(ICounter counter, State state) -// { -// var stat = new ExpandoObject() as IDictionary; -// stat.Add("SiloId", state.Id); -// stat.Add("SiloName", state.SiloName); - -// stat.Add("DeploymentId", state.DeploymentId); -// stat.Add("HostName", state.HostName); -// stat.Add("UtcDateTime", DateTimeOffset.UtcNow.UtcDateTime); -// stat.Add(counter.Name, counter.IsValueDelta ? float.Parse(counter.GetDeltaString()): float.Parse(counter.GetValueString())); - -// return stat; -// } -// } -//} diff --git a/src/ElasticSearchTelemetryConsumer/Extensions/ProviderConfigurationExtensions.cs b/src/ElasticSearchTelemetryConsumer/Extensions/ProviderConfigurationExtensions.cs deleted file mode 100644 index 5383dd7..0000000 --- a/src/ElasticSearchTelemetryConsumer/Extensions/ProviderConfigurationExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using Orleans.Runtime.Configuration; - -//namespace Orleans.Telemetry -//{ -// public static class ProviderConfigurationExtensions -// { -// public static void AddElasticSearchStatisticsProvider(this ClusterConfiguration config, -// string providerName, Uri ElasticHostAddress, string ElasticIndex= "orleans_statistics", string ElasticMetricType= "metric", string ElasticCounterType = "counter") -// { -// if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullException(nameof(providerName)); -// if (string.IsNullOrWhiteSpace(ElasticIndex)) throw new ArgumentNullException(nameof(ElasticIndex)); -// if (string.IsNullOrWhiteSpace(ElasticMetricType)) throw new ArgumentNullException(nameof(ElasticMetricType)); -// if (string.IsNullOrWhiteSpace(ElasticCounterType)) throw new ArgumentNullException(nameof(ElasticCounterType)); - -// var properties = new Dictionary -// { -// {"ElasticHostAddress", ElasticHostAddress.ToString()}, -// {"ElasticIndex", ElasticIndex}, -// {"ElasticMetricsType", ElasticMetricType}, -// {"ElasticCounterType", ElasticCounterType}, -// }; - -// config.Globals.RegisterStatisticsProvider(providerName, properties); -// } - -// public static void AddElasticSearchStatisticsProvider(this ClientConfiguration config, -// string providerName, Uri ElasticHostAddress, string ElasticIndex = "orleans_statistics", string ElasticType = "metrics") -// { -// if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullException(nameof(providerName)); -// if (string.IsNullOrWhiteSpace(ElasticIndex)) throw new ArgumentNullException(nameof(ElasticIndex)); -// if (string.IsNullOrWhiteSpace(ElasticType)) throw new ArgumentNullException(nameof(ElasticType)); - -// var properties = new Dictionary -// { -// {"ElasticHostAddress", ElasticHostAddress.ToString()}, -// {"ElasticIndex", ElasticIndex}, -// {"ElasticMetricsType", ElasticType}, -// }; - -// config.RegisterStatisticsProvider(providerName, properties); -// } - -// } -//} diff --git a/src/ElasticSearchTelemetryConsumer/Orleans.TelemetryConsumers.ElasticSearch.csproj b/src/ElasticSearchTelemetryConsumer/Orleans.TelemetryConsumers.ElasticSearch.csproj index 0aabc3d..001fbfc 100644 --- a/src/ElasticSearchTelemetryConsumer/Orleans.TelemetryConsumers.ElasticSearch.csproj +++ b/src/ElasticSearchTelemetryConsumer/Orleans.TelemetryConsumers.ElasticSearch.csproj @@ -152,16 +152,9 @@ - - - - - - - diff --git a/src/ElasticSearchTelemetryConsumer/SiloMetricsEntry.cs b/src/ElasticSearchTelemetryConsumer/SiloMetricsEntry.cs deleted file mode 100644 index 3ddfa3a..0000000 --- a/src/ElasticSearchTelemetryConsumer/SiloMetricsEntry.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; - -namespace Orleans.Telemetry -{ - [Serializable] - internal class SiloMetricsEntry - { - public string SiloId { get; set; } - public string SiloName { get; set; } - public string DeploymentId { get; set; } - public string Address { get; set; } - public string HostName { get; set; } - public string GatewayAddress { get; set; } - public double CpuUsage { get; set; } - public long TotalPhysicalMemory { get; set; } - public long AvailablePhysicalMemory { get; set; } - public long MemoryUsage { get; set; } - public int SendQueueLength { get; set; } - public int ReceiveQueueLength { get; set; } - public long SentMessages { get; set; } - public long ReceivedMessages { get; set; } - public int ActivationsCount { get; set; } - public int RecentlyUsedActivations { get; set; } - public int RequestQueueLength { get; set; } - public bool IsOverloaded { get; set; } - public long ClientCount { get; set; } - public string Time { get; set; } - public DateTime UtcDateTime { get; set; } - - public override string ToString() => $"SiloMetricsEntry[ SiloId={SiloId} DeploymentId={DeploymentId} Address={Address} HostName={HostName} GatewayAddress={GatewayAddress} CpuUsage={CpuUsage} TotalPhysicalMemory={TotalPhysicalMemory} AvailablePhysicalMemory={AvailablePhysicalMemory} MemoryUsage={MemoryUsage} SendQueueLength={SendQueueLength} ReceiveQueueLength={ReceiveQueueLength} SentMessages={SentMessages} ReceivedMessages={ReceivedMessages} ActivationsCount={ActivationsCount} RecentlyUsedActivations={RecentlyUsedActivations} RequestQueueLength={RequestQueueLength} IsOverloaded={IsOverloaded} ClientCount={ClientCount} Time={Time} ]"; - } -} \ No newline at end of file diff --git a/src/ElasticSearchTelemetryConsumer/State.cs b/src/ElasticSearchTelemetryConsumer/State.cs deleted file mode 100644 index 6d05537..0000000 --- a/src/ElasticSearchTelemetryConsumer/State.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace Orleans.Telemetry -{ - class State - { - public string DeploymentId { get; set; } = ""; - public bool IsSilo { get; set; } = true; - public string SiloName { get; set; } = ""; - public string Id { get; set; } = ""; - public string Address { get; set; } = ""; - public string GatewayAddress { get; set; } = ""; - public string HostName { get; set; } = ""; - public Guid ServiceId { get; set; } = Guid.Empty; - } -} \ No newline at end of file diff --git a/src/ElasticSearchTelemetryConsumer/StatsTableEntry.cs b/src/ElasticSearchTelemetryConsumer/StatsTableEntry.cs deleted file mode 100644 index 713924a..0000000 --- a/src/ElasticSearchTelemetryConsumer/StatsTableEntry.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Orleans.Telemetry -{ - [Serializable] - internal class StatsTableEntry - { - public string Identity { get; set; } - public string DeploymentId { get; set; } - public string Name { get; set; } - public string HostName { get; set; } - public string Statistic { get; set; } - public string StatValue { get; set; } - public bool IsDelta { get; set; } - public string Time { get; set; } - public DateTime UtcDateTime { get; set; } - - public override string ToString() => $"StatsTableEntry[ Identity={Identity} DeploymentId={DeploymentId} Name={Name} HostName={HostName} Statistic={Statistic} StatValue={StatValue} IsDelta={IsDelta} Time={Time} ]"; - } -} \ No newline at end of file diff --git a/test/TestHost/OrleansHostWrapper.cs b/test/TestHost/OrleansHostWrapper.cs index 761a1c0..8babf59 100644 --- a/test/TestHost/OrleansHostWrapper.cs +++ b/test/TestHost/OrleansHostWrapper.cs @@ -36,7 +36,7 @@ public OrleansHostWrapper() /// https://gist.github.com/jeoffman/91082bfe7d30ae2f74c07fac7db5e53b /// and run docker-compose.exe in the same dir - var elasticSearchURL = new Uri("http://elasticsearch:9200"); + var elasticSearchURL = new Uri("http://localhost:9200"); var esTeleM = new ElasticSearchTelemetryConsumer(elasticSearchURL, "orleans-telemetry"); LogManager.TelemetryConsumers.Add(esTeleM);