Ejemplo n.º 1
0
        protected void RecordTelemetry(string method, int statusCode, string content, ResourceEnum resource, Util.SplitStopwatch clock)
        {
            if (statusCode >= (int)HttpStatusCode.OK && statusCode < (int)HttpStatusCode.Ambiguous)
            {
                _telemetryRuntimeProducer.RecordSyncLatency(resource, Util.Metrics.Bucket(clock.ElapsedMilliseconds));
                _telemetryRuntimeProducer.RecordSuccessfulSync(resource, CurrentTimeHelper.CurrentTimeMillis());
            }
            else
            {
                _log.Error($"Http status executing {method}: {statusCode.ToString()} - {content}");

                _telemetryRuntimeProducer.RecordSyncError(resource, statusCode);
            }
        }
Ejemplo n.º 2
0
        public async Task <AuthenticationResponse> AuthenticateAsync()
        {
            using (var clock = new Util.SplitStopwatch())
            {
                clock.Start();

                try
                {
                    var response = await _splitioHttpClient.GetAsync(_url);

                    if (response.statusCode == HttpStatusCode.OK)
                    {
                        _log.Debug($"Success connection to: {_url}");

                        _telemetryRuntimeProducer.RecordSyncLatency(ResourceEnum.TokenSync, Util.Metrics.Bucket(clock.ElapsedMilliseconds));
                        _telemetryRuntimeProducer.RecordSuccessfulSync(ResourceEnum.TokenSync, CurrentTimeHelper.CurrentTimeMillis());

                        return(GetSuccessResponse(response.content));
                    }
                    else if (response.statusCode >= HttpStatusCode.BadRequest && response.statusCode < HttpStatusCode.InternalServerError)
                    {
                        _log.Debug($"Problem to connect to : {_url}. Response status: {response.statusCode}");

                        _telemetryRuntimeProducer.RecordAuthRejections();
                        return(new AuthenticationResponse {
                            PushEnabled = false, Retry = false
                        });
                    }

                    _telemetryRuntimeProducer.RecordSyncError(ResourceEnum.TokenSync, (int)response.statusCode);
                    return(new AuthenticationResponse {
                        PushEnabled = false, Retry = true
                    });
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message);

                    return(new AuthenticationResponse {
                        PushEnabled = false, Retry = false
                    });
                }
            }
        }
Ejemplo n.º 3
0
        private async Task ExecutePost(string url, object data, string method)
        {
            var jsonData = JsonConvert.SerializeObject(data, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            var response = await _splitioHttpClient.PostAsync($"{_telemetryURL}{url}", jsonData);

            if ((int)response.statusCode >= (int)HttpStatusCode.OK && (int)response.statusCode < (int)HttpStatusCode.Ambiguous)
            {
                _telemetryRuntimeProducer.RecordSuccessfulSync(ResourceEnum.TelemetrySync, CurrentTimeHelper.CurrentTimeMillis());
                _log.Debug($"Telemetry post success. {method}");
            }
            else
            {
                _log.Error($"Http status executing {method}: {response.statusCode} - {response.content}");
                _telemetryRuntimeProducer.RecordSyncError(ResourceEnum.TelemetrySync, (int)response.statusCode);
            }
        }