Exemplo n.º 1
0
        private void OnMessage(object sender, EventSource.MessageReceivedEventArgs e)
        {
            try
            {
                HandleMessage(e.EventName, e.Message.Data);
            }
            catch (JsonReadException ex)
            {
                _log.Error("LaunchDarkly service request failed or received invalid data: {0}",
                           LogValues.ExceptionSummary(ex));

                var errorInfo = new DataSourceStatus.ErrorInfo
                {
                    Kind    = DataSourceStatus.ErrorKind.InvalidData,
                    Message = ex.Message,
                    Time    = DateTime.Now
                };
                _updateSink.UpdateStatus(DataSourceState.Interrupted, errorInfo);

                _eventSource.Restart(false);
            }
            catch (Exception ex)
            {
                LogHelpers.LogException(_log, "Unexpected error in stream processing", ex);
            }
        }
Exemplo n.º 2
0
        private string DescribeErrorCount(DataSourceStatus.ErrorInfo errorInfo, int count)
        {
            var errorDesc = errorInfo.StatusCode > 0 ?
                            string.Format("{0}({1})", errorInfo.Kind.Identifier(), errorInfo.StatusCode) :
                            errorInfo.Kind.Identifier();

            return(string.Format("{0} ({1} {2})", errorDesc, count, count == 1 ? "time" : "times"));
        }
        private void OnMessage(object sender, EventSource.MessageReceivedEventArgs e)
        {
            try
            {
                HandleMessage(e.EventName, e.Message.DataUtf8Bytes.Data);
                // The way the PreferDataAsUtf8Bytes option works in EventSource is that if the
                // stream really is using UTF-8 encoding, the event data is passed to us directly
                // in Message.DataUtf8Bytes as a byte array and does not need to be converted to
                // a string. If the stream is for some reason using a different encoding, then
                // EventSource reads the data as a string (automatically converted by .NET from
                // whatever the encoding was), and then calling Message.DataUtf8Bytes converts
                // that to UTF-8 bytes.
            }
            catch (JsonReadException ex)
            {
                _log.Error("LaunchDarkly service request failed or received invalid data: {0}",
                           LogValues.ExceptionSummary(ex));

                var errorInfo = new DataSourceStatus.ErrorInfo
                {
                    Kind    = DataSourceStatus.ErrorKind.InvalidData,
                    Message = ex.Message,
                    Time    = DateTime.Now
                };
                _dataSourceUpdates.UpdateStatus(DataSourceState.Interrupted, errorInfo);

                _es.Restart(false);
            }
            catch (StreamStoreException)
            {
                if (!_storeStatusMonitoringEnabled)
                {
                    if (!_lastStoreUpdateFailed)
                    {
                        _log.Warn("Restarting stream to ensure that we have the latest data");
                    }
                    _es.Restart(false);
                }
                _lastStoreUpdateFailed = true;
            }
            catch (Exception ex)
            {
                LogHelpers.LogException(_log, "Unexpected error in stream processing", ex);
                _es.Restart(false);
            }
        }
Exemplo n.º 4
0
        private void RecordError(DataSourceStatus.ErrorInfo?newError)
        {
            if (!newError.HasValue)
            {
                return;
            }
            // Accumulate how many times each kind of error has occurred during the outage - use just the basic
            // properties as the key so the map won't expand indefinitely
            var basicErrorInfo = new DataSourceStatus.ErrorInfo
            {
                Kind       = newError.Value.Kind,
                StatusCode = newError.Value.StatusCode
            };

            if (_errorCounts.TryGetValue(basicErrorInfo, out var count))
            {
                _errorCounts[basicErrorInfo] = count + 1;
            }
            else
            {
                _errorCounts[basicErrorInfo] = 1;
            }
        }