public void MTTREliteTest() { //Arrange MeanTimeToRestore metrics = new MeanTimeToRestore(); int numberOfDays = 7; List <KeyValuePair <DateTime, TimeSpan> > meanTimeToRestoreList = new List <KeyValuePair <DateTime, TimeSpan> > { new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-3), new TimeSpan(0, 40, 0)), new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-4), new TimeSpan(0, 50, 0)), }; //Act float result = metrics.ProcessMeanTimeToRestore(meanTimeToRestoreList, numberOfDays); MeanTimeToRestoreModel model = new MeanTimeToRestoreModel { MTTRAverageDurationInHours = result, MTTRAverageDurationDescription = metrics.GetMeanTimeToRestoreRating(result), IsProjectView = false, ItemOrder = 1 }; //Assert Assert.IsTrue(model != null); Assert.AreEqual(0.75f, model.MTTRAverageDurationInHours); Assert.AreEqual("Elite", model.MTTRAverageDurationDescription); Assert.AreEqual(false, model.IsProjectView); Assert.AreEqual(1, model.ItemOrder); }
public void MTTRNoneTest() { //Arrange MeanTimeToRestore metrics = new MeanTimeToRestore(); int numberOfDays = 1; List <KeyValuePair <DateTime, TimeSpan> > meanTimeToRestoreList = null; //Act float result = metrics.ProcessMeanTimeToRestore(meanTimeToRestoreList, numberOfDays); string rating = metrics.GetMeanTimeToRestoreRating(result); //Assert Assert.AreEqual(0f, result); Assert.AreEqual("None", rating); }
public void MTTRLowTest() { //Arrange MeanTimeToRestore metrics = new MeanTimeToRestore(); int numberOfDays = 1; List <KeyValuePair <DateTime, TimeSpan> > meanTimeToRestoreList = new List <KeyValuePair <DateTime, TimeSpan> > { new KeyValuePair <DateTime, TimeSpan>(DateTime.Now, new TimeSpan(170, 0, 0)) }; //Act float result = metrics.ProcessMeanTimeToRestore(meanTimeToRestoreList, numberOfDays); string rating = metrics.GetMeanTimeToRestoreRating(result); //Assert Assert.AreEqual(170f, result); Assert.AreEqual("Low", rating); }
public void MTTRHighTest() { //Arrange MeanTimeToRestore metrics = new MeanTimeToRestore(); int numberOfDays = 7; List <KeyValuePair <DateTime, TimeSpan> > meanTimeToRestoreList = new List <KeyValuePair <DateTime, TimeSpan> > { new KeyValuePair <DateTime, TimeSpan>(DateTime.Now, new TimeSpan(2, 0, 0)), new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-1), new TimeSpan(0, 45, 0)), new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-2), new TimeSpan(1, 0, 0)), new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-3), new TimeSpan(0, 40, 0)), new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-4), new TimeSpan(0, 50, 0)), new KeyValuePair <DateTime, TimeSpan>(DateTime.Now.AddDays(-14), new TimeSpan(12, 0, 0)) //this record should be out of range }; //Act float result = metrics.ProcessMeanTimeToRestore(meanTimeToRestoreList, numberOfDays); string rating = metrics.GetMeanTimeToRestoreRating(result); //Assert Assert.AreEqual(1.05f, result); Assert.AreEqual("High", rating); }
public MeanTimeToRestoreModel GetAzureMeanTimeToRestore(bool getSampleData, TableStorageConfiguration tableStorageConfig, DevOpsPlatform targetDevOpsPlatform, string resourceGroup, int numberOfDays, int maxNumberOfItems) { ListUtility <MeanTimeToRestoreEvent> utility = new ListUtility <MeanTimeToRestoreEvent>(); if (getSampleData == false) { //If the user didn't specify a resource group, it comes in as null and causes havoc. Setting it as "" helps, it if (resourceGroup == null) { resourceGroup = ""; } //Pull the events from the table storage AzureTableStorageDA daTableStorage = new AzureTableStorageDA(); Newtonsoft.Json.Linq.JArray list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableMTTR, resourceGroup); List <AzureAlert> alerts = new List <AzureAlert>(); foreach (JToken item in list) { alerts.Add( new AzureAlert { name = item["data"]["context"]["name"].ToString(), resourceGroupName = item["data"]["context"]["resourceGroupName"].ToString(), resourceName = item["data"]["context"]["resourceName"].ToString(), status = item["data"]["status"].ToString(), timestamp = DateTime.Parse(item["data"]["context"]["timestamp"].ToString()) }); } //sort the events by timestamp alerts = alerts.OrderBy(o => o.timestamp).ToList(); //Compile the events, looking for pairs, using the ordered data, and name, resource group name and resource name List <MeanTimeToRestoreEvent> events = new List <MeanTimeToRestoreEvent>(); //Loop through first finding the activated alerts int i = 0; List <AzureAlert> startingAlerts = alerts.Where(o => o.status == "Activated").ToList(); foreach (AzureAlert item in startingAlerts) { if (item.timestamp > DateTime.Now.AddDays(-numberOfDays)) { i++; MeanTimeToRestoreEvent newEvent = new MeanTimeToRestoreEvent { Name = item.name, Resource = item.resourceName, ResourceGroup = item.resourceGroupName, StartTime = item.timestamp, Status = "inProgress", ItemOrder = i }; events.Add(newEvent); } } //Now loop through again, looking for the deactivated matching pair float maxEventDuration = 0; List <AzureAlert> endingAlerts = alerts.Where(o => o.status == "Deactivated").ToList(); foreach (MeanTimeToRestoreEvent item in events) { //Search for the next matching deactivated alert int foundItemIndex = -1; for (int j = 0; j <= endingAlerts.Count - 1; j++) { if (endingAlerts[j].name == item.Name && endingAlerts[j].resourceName == item.Resource && endingAlerts[j].resourceGroupName == item.ResourceGroup && endingAlerts[j].timestamp > item.StartTime) { item.EndTime = endingAlerts[j].timestamp; item.Status = "completed"; foundItemIndex = j; break; } } if (foundItemIndex >= 0) { //Remove the found item from the list, so we don't use it again. endingAlerts.RemoveAt(foundItemIndex); if (item.MTTRDurationInHours > maxEventDuration) { maxEventDuration = item.MTTRDurationInHours; } } } //Calculate the MTTR metric MeanTimeToRestore mttr = new MeanTimeToRestore(); List <KeyValuePair <DateTime, TimeSpan> > dateList = ConvertEventsToDateList(events); float averageMTTR = mttr.ProcessMeanTimeToRestore(dateList, numberOfDays); //Calculate the SLA metric SLA slaMetric = new SLA(); float sla = slaMetric.ProcessSLA(dateList, numberOfDays); //Filter the list for the UI, and sort the final list (May not be needed due to the initial sort on the starting alerts) List <MeanTimeToRestoreEvent> uiEvents = utility.GetLastNItems(events, maxNumberOfItems); uiEvents = uiEvents.OrderBy(o => o.StartTime).ToList(); //Finally, process the percent calculation foreach (MeanTimeToRestoreEvent item in uiEvents) { float interiumResult = ((item.MTTRDurationInHours / maxEventDuration) * 100f); item.MTTRDurationPercent = Scaling.ScaleNumberToRange(interiumResult, 0, 100, 20, 100); } //Pull together the results into a single model MeanTimeToRestoreModel model = new MeanTimeToRestoreModel { TargetDevOpsPlatform = targetDevOpsPlatform, ResourceGroup = resourceGroup, MeanTimeToRestoreEvents = uiEvents, MTTRAverageDurationInHours = averageMTTR, MTTRAverageDurationDescription = mttr.GetMeanTimeToRestoreRating(averageMTTR), NumberOfDays = numberOfDays, MaxNumberOfItems = uiEvents.Count, TotalItems = events.Count, SLA = sla, SLADescription = slaMetric.GetSLARating(sla) }; return(model); } else { //Get sample data MeanTimeToRestore mttr = new MeanTimeToRestore(); List <MeanTimeToRestoreEvent> sampleEvents = GetSampleMTTREvents(resourceGroup); List <KeyValuePair <DateTime, TimeSpan> > dateList = ConvertEventsToDateList(sampleEvents); float averageMTTR = mttr.ProcessMeanTimeToRestore(dateList, numberOfDays); SLA slaMetric = new SLA(); float sla = slaMetric.ProcessSLA(dateList, numberOfDays); MeanTimeToRestoreModel model = new MeanTimeToRestoreModel { TargetDevOpsPlatform = targetDevOpsPlatform, ResourceGroup = resourceGroup, MeanTimeToRestoreEvents = sampleEvents, MTTRAverageDurationInHours = averageMTTR, MTTRAverageDurationDescription = mttr.GetMeanTimeToRestoreRating(averageMTTR), NumberOfDays = numberOfDays, MaxNumberOfItems = sampleEvents.Count, TotalItems = sampleEvents.Count, SLA = sla, SLADescription = slaMetric.GetSLARating(sla) }; return(model); } }