public void BacktraceMetricsSummedEvents_ShoulOverrideDefaultSubmissionUrl_SendEventToValidUrl() { var expectedSubmissionUrl = string.Format("{0}/summed-events/unit-test/submit?token={1}&universe={2}", _defaultSubmissionUrl, _token, _universeName); var jsonString = string.Empty; var submissionUrl = string.Empty; var requestHandler = new BacktraceHttpClientMock() { OnInvoke = (string url, BacktraceJObject json) => { jsonString = json.ToJson(); submissionUrl = url; } }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl) { SummedEventsSubmissionUrl = expectedSubmissionUrl }; backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.Send(); Assert.IsNotEmpty(jsonString); Assert.AreEqual(expectedSubmissionUrl, submissionUrl); Assert.IsEmpty(backtraceMetrics.SummedEvents); }
public IEnumerator MetricsSubmission_ShouldTry3TimesOn503AndDropSummedEventsOnMaximumNumberOfEvents_DataWasDeleted() { const int expectedNumberOfEventsAfterFailure = 1; // unique events and we have enough place for session event so also session event var requestHandler = new BacktraceHttpClientMock() { StatusCode = 503 }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); for (int i = 0; i < backtraceMetrics.MaximumSummedEvents; i++) { backtraceMetrics.AddSummedEvent(MetricsEventName); } backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++) { yield return(new WaitForSeconds(1)); // immidiately run next update var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1; backtraceMetrics.Tick(time); } yield return(new WaitForSeconds(1)); Assert.AreEqual(expectedNumberOfEventsAfterFailure, backtraceMetrics.Count()); Assert.AreEqual(BacktraceMetrics.MaxNumberOfAttempts * 2, requestHandler.NumberOfRequests); }
public IEnumerator MetricsSubmission_ShouldTry3TimesOn502BeforeDroppingEvents_DataWasntSendToBacktrace() { const int expectedNumberOfEventsAfterFailure = 2; var requestHandler = new BacktraceHttpClientMock() { StatusCode = 502 }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++) { yield return(new WaitForSeconds(1)); // immidiately run next update var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1; backtraceMetrics.Tick(time); } yield return(new WaitForSeconds(1)); Assert.AreEqual(BacktraceMetrics.MaxNumberOfAttempts * 2, requestHandler.NumberOfRequests); Assert.AreEqual(backtraceMetrics.Count(), expectedNumberOfEventsAfterFailure); }
public IEnumerator MaximumNumberOfEvents_ShouldntDropEventsWhenSpaceIsAvailable_DataShouldBeAvailable() { var requestHandler = new BacktraceHttpClientMock() { IsHttpError = true }; const int expectedMaximumNumberOfSummedEvents = 10; const int expectedNumberOfSummedEvents = 3; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.MaximumSummedEvents = expectedMaximumNumberOfSummedEvents; for (int i = 0; i < expectedMaximumNumberOfSummedEvents - expectedNumberOfSummedEvents; i++) { backtraceMetrics.AddSummedEvent(MetricsEventName); } backtraceMetrics.Send(); for (int i = 0; i < expectedNumberOfSummedEvents; i++) { backtraceMetrics.AddSummedEvent(MetricsEventName); } for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++) { yield return(new WaitForSeconds(1)); // immidiately run next update var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1; backtraceMetrics.Tick(time); } yield return(new WaitForSeconds(1)); Assert.AreEqual(expectedNumberOfSummedEvents, backtraceMetrics.Count()); }
public void BacktraceMetricsUniqueEvents_ShouldBeAbleToOverrideDefaultSubmissionUrl_CorrectSubmissionUrl() { string expectedSubmissionUrl = $"{_defaultSubmissionUrl}/unit-test/unique-events/submit?token={_token}&universe={_universeName}"; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, expectedSubmissionUrl, _defaultSummedEventsSubmissionUrl); Assert.AreEqual(expectedSubmissionUrl, backtraceMetrics.UniqueEventsSubmissionUrl); }
public void BacktraceMetricsSummedEvents_ShouldntAddNullableSUmmedEvent_SummedEventsAreEmpty() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.AddSummedEvent(null); Assert.AreEqual(backtraceMetrics.SummedEvents.Count, 0); }
public void BacktraceMetricsSummedEvents_ShouldBeAbleToOverrideDefaultSubmissionUrl_CorrectSubmissionUrl() { string expectedSubmissionUrl = string.Format("{0}/unit-test/summed-events/submit?token={1}&universe={2}", _defaultSubmissionUrl, _token, _universeName); var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, expectedSubmissionUrl); Assert.AreEqual(expectedSubmissionUrl, backtraceMetrics.SummedEventsSubmissionUrl); }
public void BacktraceMetricsUniqueEvents_ShouldntAddEmptyUniqueEvent_UniqueEventsAreEmpty() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); var added = backtraceMetrics.AddUniqueEvent(string.Empty); Assert.IsFalse(added); Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 0); }
public void BacktraceMetricsUniqueEvents_ShouldPreventFromAddingEventIfThereIsNoAttribute_StoreValidUniqueEvent() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); var added = backtraceMetrics.AddUniqueEvent($"{UniqueAttributeName}-not-existing"); Assert.IsFalse(added); Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 0); }
public void BacktraceMetricsDefaultEvent_ShouldSendDefaultEventOnTheApplicationStartup_DataWasSendToBacktrace() { var requestHandler = new BacktraceHttpClientMock(); var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 10, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.SendStartupEvent(); Assert.AreEqual(2, requestHandler.NumberOfRequests); }
public void BacktraceMetrics_ShouldntTriggerUploadWhenDataIsNotAvailable_DataWasntSendToBacktrace() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); var requestHandler = new BacktraceHttpClientMock(); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.Send(); Assert.IsFalse(requestHandler.Called); }
public void EnableMetrics(string uniqueAttributeName = BacktraceMetrics.DefaultUniqueAttributeName) { var universeName = Configuration.GetUniverseName(); var token = Configuration.GetToken(); EnableMetrics( BacktraceMetrics.GetDefaultUniqueEventsUrl(universeName, token), BacktraceMetrics.GetDefaultSummedEventsUrl(universeName, token), Configuration.GetEventAggregationIntervalTimerInMs(), uniqueAttributeName); }
public void BacktraceMetricsSummedEvents_ShouldAddCorrectlySummedEvent_StoreValidSummedEvent() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.AddSummedEvent(MetricsEventName); Assert.AreEqual(backtraceMetrics.SummedEvents.Count, 1); var summedEvent = backtraceMetrics.SummedEvents.First.Value; Assert.AreEqual(summedEvent.Name, MetricsEventName); Assert.AreNotEqual(summedEvent.Timestamp, 0); }
public void BacktraceMetricsUniqueEvents_ShouldAddCorrectlyUniqueEventWithoutAttributes_StoreValidUniqueEvent() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 1); var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value; Assert.AreEqual(uniqueEvent.Name, UniqueAttributeName); Assert.AreNotEqual(uniqueEvent.Timestamp, 0); Assert.AreEqual(uniqueEvent.Attributes.Count, _attributeProvider.GenerateAttributes().Count); }
public void BacktraceMetricsUniqueEvents_ShouldAddEventIfAttributeIsDefinedInCustomAttributes_StoreValidUniqueEvents() { var expectedAttributeName = "foo"; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); var added = backtraceMetrics.AddUniqueEvent(expectedAttributeName, new Dictionary <string, string>() { { expectedAttributeName, expectedAttributeName } }); Assert.IsTrue(added); Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 1); }
public void BacktraceMetrics_ShouldTryOnlyOnceOnHttpFailure_DataWasntSendToBacktrace() { var requestHandler = new BacktraceHttpClientMock() { IsHttpError = true }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); Assert.AreEqual(2, requestHandler.NumberOfRequests); }
public void BacktraceMetricsUniqueEvents_UniqueEventAttributeExistsAfterDeletingItFromAttributeProvider_UniqueEventAttributesStayTheSame() { const string initializationValue = "foo"; _attributeProvider[UniqueAttributeName] = initializationValue; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); _attributeProvider[UniqueAttributeName] = string.Empty; var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value; Assert.AreEqual(initializationValue, uniqueEvent.Attributes[UniqueAttributeName]); }
public void BacktraceMetrics_ShouldTriggerUploadProcessWhenTimeIntervalIsEqualToZero_DataWasntSendToTheService() { var requestHandler = new BacktraceHttpClientMock(); var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); for (int i = 0; i < 1000; i++) { backtraceMetrics.Tick(i); } Assert.AreEqual(0, requestHandler.NumberOfRequests); }
public void BacktraceMetricsUniqueEvents_UniqueEventAttributeValueDontChangeOverTime_UniqueEventAttributesStayTheSame() { const string initializationValue = "foo"; const string updatedValue = "bar"; _attributeProvider[UniqueAttributeName] = initializationValue; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); _attributeProvider[UniqueAttributeName] = updatedValue; var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value; Assert.AreEqual(initializationValue, uniqueEvent.Attributes[UniqueAttributeName]); }
public void NativeCrashUploadAttributesReading_ShouldReadCorrecSessionIdFromPreviousSession_SessionIdIsValid() { var backtraceApi = new BacktraceApiMock(); var attributeProvider = new AttributeProvider(); var backtraceMetrics = new BacktraceMetrics(attributeProvider, 100, "https://unique-event-url.com", "https://summed-event-url.com"); attributeProvider.AddScopedAttributeProvider(backtraceMetrics); // simulate first session new NativeCrashUploader(attributeProvider, backtraceApi); // second session var nativeCrashUploader = new NativeCrashUploader(attributeProvider, backtraceApi); Assert.AreEqual(attributeProvider.ApplicationSessionKey, nativeCrashUploader.SessionId); }
public void BacktraceMetrics_ShouldSkipMoreSummedEventsWhenHitTheLimit_DataWasntSendToBacktrace() { const int maximumNumberOfEvents = 3; const int numberOfTestEvents = 10; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl) { MaximumSummedEvents = maximumNumberOfEvents }; for (int i = 0; i < numberOfTestEvents; i++) { backtraceMetrics.AddSummedEvent(string.Format("{0} {1}", MetricsEventName, i)); } Assert.AreEqual(maximumNumberOfEvents, backtraceMetrics.Count()); }
public void BacktraceMetrics_ShouldntTriggerDownloadBeforeTimeIntervalHit_DataWasSendToBacktrace() { const int timeInterval = 10; const int numberOfAddedEvents = 2; var requestHandler = new BacktraceHttpClientMock(); var backtraceMetrics = new BacktraceMetrics(_attributeProvider, timeInterval, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Tick(timeInterval - 1); Assert.AreEqual(numberOfAddedEvents, backtraceMetrics.Count()); Assert.AreEqual(0, requestHandler.NumberOfRequests); }
public void BacktraceMetrics_ShouldTriggerUploadAfterTimeIntervalHit_DataWasSendToBacktrace() { const int timeInterval = 10; const int expectedNumberOfEvents = 1; // we send successfully session event so we have one unique event const int expectedNumberOfRequests = 2; var requestHandler = new BacktraceHttpClientMock(); var backtraceMetrics = new BacktraceMetrics(_attributeProvider, timeInterval, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Tick(timeInterval + 1); Assert.AreEqual(expectedNumberOfEvents, backtraceMetrics.Count()); Assert.AreEqual(expectedNumberOfRequests, requestHandler.NumberOfRequests); }
private void EnableMetrics(bool enableIfConfigurationIsDisabled = true) { if (!Configuration.EnableMetricsSupport) { if (!enableIfConfigurationIsDisabled) { return; } Debug.LogWarning("Event aggregation configuration was disabled. Enabling it manually via API"); } var universeName = Configuration.GetUniverseName(); var token = Configuration.GetToken(); EnableMetrics( BacktraceMetrics.GetDefaultUniqueEventsUrl(universeName, token), BacktraceMetrics.GetDefaultSummedEventsUrl(universeName, token), Configuration.GetEventAggregationIntervalTimerInMs()); }
public void BacktraceMetrics_ShouldSkipMoreUniqueEventsWhenHitTheLimit_DataWasntSendToBacktrace() { const int maximumNumberOfEvents = 3; const int numberOfTestEvents = 10; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl) { MaximumUniqueEvents = maximumNumberOfEvents }; for (int i = 0; i < numberOfTestEvents; i++) { backtraceMetrics.AddUniqueEvent($"{UniqueAttributeName} {i}", new Dictionary <string, string>() { { $"{UniqueAttributeName} {i}", "value" } }); } Assert.AreEqual(maximumNumberOfEvents, backtraceMetrics.Count()); }
public void EnableMetrics(string uniqueEventsSubmissionUrl, string summedEventsSubmissionUrl, uint timeIntervalInSec = BacktraceMetrics.DefaultTimeIntervalInSec, string uniqueEventName = BacktraceMetrics.DefaultUniqueEventName) { if (_metrics != null) { Debug.LogWarning("Backtrace metrics support is enabled. Please use BacktraceClient.Metrics."); return; } _metrics = new BacktraceMetrics( attributeProvider: AttributeProvider, timeIntervalInSec: timeIntervalInSec, uniqueEventsSubmissionUrl: uniqueEventsSubmissionUrl, summedEventsSubmissionUrl: summedEventsSubmissionUrl ) { StartupUniqueEventName = uniqueEventName, IgnoreSslValidation = Configuration.IgnoreSslValidation }; StartupMetrics(); }
public void BacktraceMetricsUniqueEvents_ShouldAddCorrectlyUniqueEventWithAttributes_StoreValidUniqueEvent() { const string expectedAttributeName = "foo"; const string expectedAttributeValue = "bar"; var attributes = new Dictionary <string, string>() { { expectedAttributeName, expectedAttributeValue } }; int expectedNumberOfAttributes = _attributeProvider.GenerateAttributes().Count + attributes.Count; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.AddUniqueEvent(UniqueAttributeName, attributes); Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 1); var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value; Assert.AreEqual(uniqueEvent.Name, UniqueAttributeName); Assert.AreNotEqual(uniqueEvent.Timestamp, 0); Assert.AreEqual(uniqueEvent.Attributes.Count, expectedNumberOfAttributes); }
public void BacktraceMetricsSummedEvents_ShouldAddCorrectlySummedEventWithAttributes_StoreValidSummedEvent() { const string metricsEventName = "scene-changed"; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); const string expectedAttributeName = "foo"; const string expectedAttributeValue = "bar"; var metricsAttributes = new Dictionary <string, string>() { { expectedAttributeName, expectedAttributeValue } }; backtraceMetrics.AddSummedEvent(metricsEventName, metricsAttributes); Assert.AreEqual(backtraceMetrics.SummedEvents.Count, 1); var summedEvent = backtraceMetrics.SummedEvents.First.Value; Assert.AreEqual(summedEvent.Name, metricsEventName); Assert.AreNotEqual(summedEvent.Timestamp, 0); Assert.IsTrue(summedEvent.Attributes.ContainsKey(expectedAttributeName)); Assert.AreEqual(expectedAttributeValue, summedEvent.Attributes[expectedAttributeName]); }
public void BacktraceMetrics_ShouldntTriggerDownloadViaTickMethodWhenDidntReachMaximumNumberOfEvents_DataWasSendToBacktrace() { const int maximumNumberOfEvents = 3; const int expectedNumberOfEvents = 2; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl) { MaximumSummedEvents = maximumNumberOfEvents }; var requestHandler = new BacktraceHttpClientMock(); backtraceMetrics.OverrideHttpClient(requestHandler); for (int i = 0; i < expectedNumberOfEvents; i++) { backtraceMetrics.AddSummedEvent(string.Format("{0} {1}", MetricsEventName, i)); } backtraceMetrics.Tick(0); Assert.AreEqual(expectedNumberOfEvents, backtraceMetrics.Count()); Assert.AreEqual(0, requestHandler.NumberOfRequests); }
public void BacktraceMetrics_ShouldTriggerUploadViaTickMethodWhenReachedMaximumNumberOfEvents_DataWasSendToBacktrace() { const int maximumNumberOfEvents = 3; const int defaultTimeIntervalInSec = 10; var requestHandler = new BacktraceHttpClientMock(); var backtraceMetrics = new BacktraceMetrics(_attributeProvider, defaultTimeIntervalInSec, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl) { MaximumSummedEvents = maximumNumberOfEvents }; backtraceMetrics.OverrideHttpClient(requestHandler); for (int i = 0; i < maximumNumberOfEvents; i++) { backtraceMetrics.AddSummedEvent(string.Format("{0} {1}", MetricsEventName, i)); } backtraceMetrics.Tick(defaultTimeIntervalInSec + 1); Assert.AreEqual(0, backtraceMetrics.Count()); Assert.AreEqual(1, requestHandler.NumberOfRequests); }