public static IEnumerable <BicepTelemetryEvent> GetTelemetryEventsForBicepConfigChange(RootConfiguration prevConfiguration, RootConfiguration curConfiguration, ILinterRulesProvider linterRulesProvider) { bool prevLinterEnabledSettingValue = prevConfiguration.Analyzers.GetValue(LinterEnabledSetting, true); bool curLinterEnabledSettingValue = curConfiguration.Analyzers.GetValue(LinterEnabledSetting, true); if (!prevLinterEnabledSettingValue && !curLinterEnabledSettingValue) { return(Enumerable.Empty <BicepTelemetryEvent>()); } List <BicepTelemetryEvent> telemetryEvents = new(); if (prevLinterEnabledSettingValue != curLinterEnabledSettingValue) { var telemetryEvent = BicepTelemetryEvent.CreateOverallLinterStateChangeInBicepConfig(prevLinterEnabledSettingValue.ToString().ToLowerInvariant(), curLinterEnabledSettingValue.ToString().ToLowerInvariant()); telemetryEvents.Add(telemetryEvent); } else { foreach (var kvp in linterRulesProvider.GetLinterRules()) { string prevLinterRuleDiagnosticLevelValue = prevConfiguration.Analyzers.GetValue(kvp.Value, "warning"); string curLinterRuleDiagnosticLevelValue = curConfiguration.Analyzers.GetValue(kvp.Value, "warning"); if (prevLinterRuleDiagnosticLevelValue != curLinterRuleDiagnosticLevelValue) { var telemetryEvent = BicepTelemetryEvent.CreateLinterRuleStateChangeInBicepConfig(kvp.Key, prevLinterRuleDiagnosticLevelValue, curLinterRuleDiagnosticLevelValue); telemetryEvents.Add(telemetryEvent); } } } return(telemetryEvents); }
private void PostDeployResultTelemetryEvent(string deployId, bool isSuccess) { var telemetryEvent = BicepTelemetryEvent.CreateDeployStartOrWaitForCompletionResult( TelemetryConstants.EventNames.DeployResult, deployId, isSuccess); telemetryProvider.PostEvent(telemetryEvent); }
public void PostEvent(BicepTelemetryEvent telemetryEvent) { if (string.IsNullOrWhiteSpace(telemetryEvent.EventName) || telemetryEvent.Properties?.Count == 0) { throw new ArgumentException("Invalid telemetryEvent. Event name is either null, empty, consists only " + "of white-space characters or no properties are set on the event"); } server.Window.SendTelemetryEvent(telemetryEvent); }
public async Task VerifyTopLevelDeclarationSnippetInsertionFiresTelemetryEvent() { IDictionary <string, string> properties = new Dictionary <string, string> { { "name", "res-aks-cluster" } }; BicepTelemetryEvent bicepTelemetryEvent = await ResolveCompletionAsync(string.Empty, "res-aks-cluster", new Position(0, 0)); bicepTelemetryEvent.EventName.Should().Be(TelemetryConstants.EventNames.TopLevelDeclarationSnippetInsertion); bicepTelemetryEvent.Properties.Should().Equal(properties); }
public async Task VerifyModuleBodySnippetInsertionFiresTelemetryEvent() { string text = "module foo 'test.bicep' = "; IDictionary <string, string> properties = new Dictionary <string, string> { { "name", "{}" } }; BicepTelemetryEvent bicepTelemetryEvent = await ResolveCompletionAsync(text, "{}", new Position(0, text.Length)); bicepTelemetryEvent.EventName.Should().Be(TelemetryConstants.EventNames.ModuleBodySnippetInsertion); bicepTelemetryEvent.Properties.Should().Equal(properties); }
public async Task VerifyResourceBodySnippetInsertionFiresTelemetryEvent(string prefix) { string text = "resource aksCluster 'Microsoft.ContainerService/managedClusters@2021-03-01' = "; IDictionary <string, string> properties = new Dictionary <string, string> { { "name", prefix }, { "type", "Microsoft.ContainerService/managedClusters@2021-03-01" } }; BicepTelemetryEvent bicepTelemetryEvent = await ResolveCompletionAsync(text, prefix, new Position(0, text.Length)); bicepTelemetryEvent.EventName.Should().Be(TelemetryConstants.EventNames.ResourceBodySnippetInsertion); bicepTelemetryEvent.Properties.Should().Equal(properties); }
public override async Task <Unit> Handle(DocumentUri documentUri, string ruleCode, string bicepConfigFilePath, CancellationToken cancellationToken) { string?error = "unknown"; bool newConfigFile = false; bool newRuleAdded = false; try { // bicepConfigFilePath will be empty string if no current configuration file was found if (string.IsNullOrEmpty(bicepConfigFilePath)) { // There is no configuration file currently - create one in the default location var targetFolder = await BicepGetRecommendedConfigLocationHandler.GetRecommendedConfigFileLocation(this.server, documentUri.GetFileSystemPath()); bicepConfigFilePath = Path.Combine(targetFolder, LanguageConstants.BicepConfigurationFileName); } try { if (!File.Exists(bicepConfigFilePath)) { newConfigFile = true; File.WriteAllText(bicepConfigFilePath, DefaultBicepConfig); } } catch (Exception ex) { error = ex.GetType().Name; server.Window.ShowError($"Unable to create configuration file \"{bicepConfigFilePath}\": {ex.Message}"); return(Unit.Value); } newRuleAdded = await AddAndSelectRuleLevel(bicepConfigFilePath, ruleCode); error = null; return(Unit.Value); } catch (Exception ex) { error = ex.GetType().Name; server.Window.ShowError(ex.Message); return(Unit.Value); } finally { telemetryProvider.PostEvent(BicepTelemetryEvent.EditLinterRule(ruleCode, newConfigFile, newRuleAdded, error)); } }
public async Task VerifyObjectBodySnippetInsertionFiresTelemetryEvent(string prefix) { string text = @"resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2021-03-15' = { name: 'name' properties: }"; IDictionary <string, string> properties = new Dictionary <string, string> { { "name", prefix } }; BicepTelemetryEvent bicepTelemetryEvent = await ResolveCompletionAsync(text, prefix, new Position(2, 13)); bicepTelemetryEvent.EventName.Should().Be(TelemetryConstants.EventNames.ObjectBodySnippetInsertion); bicepTelemetryEvent.Properties.Should().Equal(properties); }
public async Task VerifyNestedResourceDeclarationSnippetInsertionFiresTelemetryEvent() { string text = @"resource automationAccount 'Microsoft.Automation/automationAccounts@2019-06-01' = { name: 'name' location: resourceGroup().location }"; IDictionary <string, string> properties = new Dictionary <string, string> { { "name", "res-automation-cert" } }; BicepTelemetryEvent bicepTelemetryEvent = await ResolveCompletionAsync(text, "res-automation-cert", new Position(3, 0)); bicepTelemetryEvent.EventName.Should().Be(TelemetryConstants.EventNames.NestedResourceDeclarationSnippetInsertion); bicepTelemetryEvent.Properties.Should().Equal(properties); }
public BicepTelemetryEvent?GetTelemetryAboutSourceFiles(SemanticModel semanticModel, Uri uri, ImmutableHashSet <ISourceFile> sourceFiles, IEnumerable <Diagnostic> diagnostics) { var mainFile = sourceFiles.First(x => x.FileUri == uri) as BicepFile; if (mainFile is null) { return(null); } Dictionary <string, string> properties = GetTelemetryPropertiesForMainFile(semanticModel, mainFile, diagnostics); var referencedFiles = sourceFiles.Where(x => x.FileUri != uri); var propertiesFromReferencedFiles = GetTelemetryPropertiesForReferencedFiles(referencedFiles); properties = properties.Concat(propertiesFromReferencedFiles).ToDictionary(s => s.Key, s => s.Value); return(BicepTelemetryEvent.CreateBicepFileOpen(properties)); }
public BicepTelemetryEvent GetLinterStateTelemetryOnBicepFileOpen(RootConfiguration configuration) { bool linterEnabledSettingValue = configuration.Analyzers.GetValue(LinterEnabledSetting, true); Dictionary <string, string> properties = new(); properties.Add("enabled", linterEnabledSettingValue.ToString().ToLowerInvariant()); if (linterEnabledSettingValue) { foreach (var kvp in LinterRulesProvider.GetLinterRules()) { string linterRuleDiagnosticLevelValue = configuration.Analyzers.GetValue(kvp.Value, "warning"); properties.Add(kvp.Key, linterRuleDiagnosticLevelValue); } } return(BicepTelemetryEvent.CreateLinterStateOnBicepFileOpen(properties)); }
public async Task VerifyObjectBodySnippetInsertionInsideExistingArrayOfObjectsFiresTelemetryEvent(string prefix) { string text = @"resource applicationGatewayFirewall 'Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies@2020-11-01' = { name: 'name' properties: { managedRules: { managedRuleSets: [ ] } } }"; IDictionary <string, string> properties = new Dictionary <string, string> { { "name", prefix } }; BicepTelemetryEvent bicepTelemetryEvent = await ResolveCompletionAsync(text, prefix, new Position(5, 0)); bicepTelemetryEvent.EventName.Should().Be(TelemetryConstants.EventNames.ObjectBodySnippetInsertion); bicepTelemetryEvent.Properties.Should().Equal(properties); }