public async void EntityInvoker_TestSupportTopicAttributeResolution() { Definition definitonAttribute = new Definition() { Id = "TestId", Name = "Test", Author = "User" }; SupportTopic topic1 = new SupportTopic() { Id = "1234", PesId = "14878" }; SupportTopic topic2 = new SupportTopic() { Id = "5678", PesId = "14878" }; EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata(); metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScriptWithMultipleSupportTopics(definitonAttribute, false, topic1, topic2); using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports())) { await invoker.InitializeEntryPointAsync(); Assert.True(invoker.IsCompilationSuccessful); Assert.Contains <SupportTopic>(topic1, invoker.EntryPointDefinitionAttribute.SupportTopicList); Assert.Contains <SupportTopic>(topic2, invoker.EntryPointDefinitionAttribute.SupportTopicList); } }
public async void EntityInvoker_InvalidSupportTopicId(string supportTopicId, string pesId, bool isInternal) { Definition definitonAttribute = new Definition() { Id = "TestId", Name = "Test", Author = "User" }; SupportTopic topic1 = new SupportTopic() { Id = supportTopicId, PesId = pesId }; SupportTopic topic2 = new SupportTopic() { Id = "5678", PesId = "14878" }; EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata(); metadata.ScriptText = await ScriptTestDataHelper.GetDetectorScriptWithMultipleSupportTopics(definitonAttribute, isInternal, topic1, topic2); using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports())) { await invoker.InitializeEntryPointAsync(); Assert.False(invoker.IsCompilationSuccessful); Assert.NotEmpty(invoker.CompilationOutput); } }
public OperationContext(TResource resource, string startTimeStr, string endTimeStr, bool isInternalCall, string requestId, string timeGrain = "5", SupportTopic supportTopic = null) { Resource = resource; StartTime = startTimeStr; EndTime = endTimeStr; IsInternalCall = isInternalCall; RequestId = requestId; TimeGrain = timeGrain; SupportTopic = supportTopic; }
public OperationContext(TResource resource, string startTimeStr, string endTimeStr, bool isInternalCall, string requestId, string timeGrain = "5", SupportTopic supportTopic = null, Form form = null, string cloudDomain = null) { Resource = resource; StartTime = startTimeStr; EndTime = endTimeStr; IsInternalCall = isInternalCall; RequestId = requestId; TimeGrain = timeGrain; SupportTopic = supportTopic; Form = form; CloudDomain = cloudDomain; QueryParams = new Dictionary <string, string>(); }
public async Task <List <SupportTopic> > GetSupportTopicsAsync(string productId) { if (string.IsNullOrWhiteSpace(productId)) { throw new ArgumentNullException("productId"); } string kustoQuery = _supportTopicsQuery .Replace("{PRODUCTID}", productId); DataTable dt = await _kustoQueryService.ExecuteQueryAsync("azsupportfollower.westus2", "AzureSupportability", kustoQuery); List <SupportTopic> supportTopicsList = new List <SupportTopic>(); if (dt == null || dt.Rows == null || dt.Rows.Count == 0) { return(supportTopicsList); } foreach (DataRow row in dt.Rows) { SupportTopic supportTopic = new SupportTopic { ProductId = row["ProductId"].ToString(), SupportTopicId = row["SupportTopicId"].ToString(), ProductName = row["ProductName"].ToString(), SupportTopicL2Name = row["SupportTopicL2Name"].ToString(), SupportTopicL3Name = row["SupportTopicL3Name"].ToString(), SupportTopicPath = row["SupportTopicPath"].ToString() }; supportTopicsList.Add(supportTopic); } return(supportTopicsList); }
/// <summary> /// Additional operations to be performed when cloning an instance of <see cref="SupportTopic "/> to an instance of <see cref="PSSupportTopic" />. /// </summary> /// <param name="topic">The product being cloned.</param> private void CloneAdditionalOperations(SupportTopic topic) { SupportTopicId = topic.Id.ToString(CultureInfo.CurrentCulture); }
/// <summary> /// Initializes a new instance of the <see cref="PSSupportTopic" /> class. /// </summary> /// <param name="topic">The base offer for this instance.</param> public PSSupportTopic(SupportTopic topic) { this.CopyFrom(topic, CloneAdditionalOperations); }
public static async Task <string> GetDetectorScriptWithMultipleSupportTopics(Definition def, bool isInternal, SupportTopic topic1, SupportTopic topic2) { string template = await File.ReadAllTextAsync(@"TestData/TestDetectorWithSupportTopic.csx"); return(template.Replace("<YOUR_DETECTOR_ID>", def.Id) .Replace("<YOUR_DETECTOR_NAME>", def.Name) .Replace("<YOUR_ALIAS>", def.Author) .Replace("<SUPPORT_TOPIC_ID_1>", topic1.Id.ToString()) .Replace("<SUPPORT_TOPIC_ID_2>", topic2.Id.ToString()) .Replace("<PES_ID_1>", topic1.PesId.ToString()) .Replace("<PES_ID_2>", topic2.PesId.ToString()) .Replace("\"<INTERNAL_FLAG>\"", isInternal ? "true" : "false")); }
private RuntimeContext <TResource> PrepareContext(TResource resource, DateTime startTime, DateTime endTime, bool forceInternal = false, SupportTopic supportTopic = null) { this.Request.Headers.TryGetValue(HeaderConstants.RequestIdHeaderName, out StringValues requestIds); this.Request.Headers.TryGetValue(HeaderConstants.InternalClientHeader, out StringValues internalCallHeader); bool isInternalClient = false; bool internalViewRequested = false; if (internalCallHeader.Any()) { bool.TryParse(internalCallHeader.First(), out isInternalClient); } if (isInternalClient) { this.Request.Headers.TryGetValue(HeaderConstants.InternalViewHeader, out StringValues internalViewHeader); if (internalViewHeader.Any()) { bool.TryParse(internalViewHeader.First(), out internalViewRequested); } } var operationContext = new OperationContext <TResource>( resource, DateTimeHelper.GetDateTimeInUtcFormat(startTime).ToString(DataProviderConstants.KustoTimeFormat), DateTimeHelper.GetDateTimeInUtcFormat(endTime).ToString(DataProviderConstants.KustoTimeFormat), internalViewRequested || forceInternal, requestIds.FirstOrDefault(), supportTopic: supportTopic ); return(new RuntimeContext <TResource>() { ClientIsInternal = isInternalClient || forceInternal, OperationContext = operationContext }); }
protected async Task <IActionResult> GetInsights(TResource resource, string pesId, string supportTopicId, string startTime, string endTime, string timeGrain) { if (!DateTimeHelper.PrepareStartEndTimeWithTimeGrain(startTime, endTime, timeGrain, out DateTime startTimeUtc, out DateTime endTimeUtc, out TimeSpan timeGrainTimeSpan, out string errorMessage)) { return(BadRequest(errorMessage)); } supportTopicId = ParseCorrectSupportTopicId(supportTopicId); var supportTopic = new SupportTopic() { Id = supportTopicId, PesId = pesId }; RuntimeContext <TResource> cxt = PrepareContext(resource, startTimeUtc, endTimeUtc, true, supportTopic); List <AzureSupportCenterInsight> insights = null; string error = null; List <Definition> detectorsRun = new List <Definition>(); IEnumerable <Definition> allDetectors = null; try { allDetectors = (await ListDetectorsInternal(cxt)).Select(detectorResponse => detectorResponse.Metadata); var applicableDetectors = allDetectors .Where(detector => string.IsNullOrWhiteSpace(supportTopicId) || detector.SupportTopicList.FirstOrDefault(st => st.Id == supportTopicId) != null); var insightGroups = await Task.WhenAll(applicableDetectors.Select(detector => GetInsightsFromDetector(cxt, detector, detectorsRun))); insights = insightGroups.Where(group => group != null).SelectMany(group => group).ToList(); } catch (Exception ex) { error = ex.GetType().ToString(); DiagnosticsETWProvider.Instance.LogRuntimeHostHandledException(cxt.OperationContext.RequestId, "GetInsights", cxt.OperationContext.Resource.SubscriptionId, cxt.OperationContext.Resource.ResourceGroup, cxt.OperationContext.Resource.Name, ex.GetType().ToString(), ex.ToString()); } var correlationId = Guid.NewGuid(); bool defaultInsightReturned = false; // Detectors Ran but no insights if (!insights.Any() && detectorsRun.Any()) { defaultInsightReturned = true; insights.Add(AzureSupportCenterInsightUtilites.CreateDefaultInsight(cxt.OperationContext, detectorsRun)); } // No detectors matched this support topic else if (!detectorsRun.Any()) { var defaultDetector = allDetectors.FirstOrDefault(detector => detector.Id.StartsWith("default_insights")); if (defaultDetector != null) { var defaultDetectorInsights = await GetInsightsFromDetector(cxt, defaultDetector, new List <Definition>()); defaultInsightReturned = defaultDetectorInsights.Any(); insights.AddRange(defaultDetectorInsights); } } var insightInfo = new { Total = insights.Count, Critical = insights.Count(insight => insight.ImportanceLevel == ImportanceLevel.Critical), Warning = insights.Count(insight => insight.ImportanceLevel == ImportanceLevel.Warning), Info = insights.Count(insight => insight.ImportanceLevel == ImportanceLevel.Info), Default = defaultInsightReturned ? 1 : 0 }; DiagnosticsETWProvider.Instance.LogRuntimeHostInsightCorrelation(cxt.OperationContext.RequestId, "ControllerBase.GetInsights", cxt.OperationContext.Resource.SubscriptionId, cxt.OperationContext.Resource.ResourceGroup, cxt.OperationContext.Resource.Name, correlationId.ToString(), JsonConvert.SerializeObject(insightInfo)); var response = new AzureSupportCenterInsightEnvelope() { CorrelationId = correlationId, ErrorMessage = error, TotalInsightsFound = insights != null?insights.Count() : 0, Insights = insights }; return(Ok(response)); }