public void TestInitialize()
 {
     this.tracerMock             = new Mock <ITracer>();
     this.credentialsFactoryMock = new Mock <ICredentialsFactory>();
     this.credentialsFactoryMock.Setup(x => x.CreateServiceClientCredentials(It.IsAny <string>())).Returns(() => new EmptyCredentials());
     this.httpClientWrapperMock      = new Mock <IHttpClientWrapper>();
     this.azureResourceManagerClient = new ExtendedAzureResourceManagerClient(this.httpClientWrapperMock.Object, this.credentialsFactoryMock.Object, this.tracerMock.Object);
 }
        public SmartDetectorConfigurationControlViewModel(
            IExtendedAzureResourceManagerClient azureResourceManagerClient,
            ITracer tracer,
            SmartDetectorManifest smartDetectorManifest,
            IEmulationSmartDetectorRunner smartDetectorRunner,
            UserSettings userSettings)
        {
            this.azureResourceManagerClient = azureResourceManagerClient;
            this.smartDetectorManifest      = smartDetectorManifest;
            this.tracer = tracer;
            this.smartDetectorManifest = smartDetectorManifest;
            this.userSettings          = userSettings;

            this.SmartDetectorRunner     = smartDetectorRunner;
            this.SmartDetectorName       = this.smartDetectorManifest.Name;
            this.ShouldShowStatusControl = false;

            // Create dummy resource identifier for initialization purposes
            this.dummyResourceIdentifier = new ResourceIdentifier(ResourceType.ApplicationInsights, "dummy-subscription-id", "dummy-resource-group-name", "dummy-resource-name");

            // Initialize cadences combo box
            IEnumerable <SmartDetectorCadence> cadences = this.smartDetectorManifest.SupportedCadencesInMinutes
                                                          .Select(cadence => new SmartDetectorCadence(TimeSpan.FromMinutes(cadence)));

            this.Cadences = new ObservableCollection <SmartDetectorCadence>(cadences);

            // Set selected cadence to be the first one. If non, pick 10 minutes cadence as default
            this.SelectedCadence = this.Cadences.Any() ?
                                   this.Cadences.First() :
                                   new SmartDetectorCadence(TimeSpan.FromMinutes(10));

            this.IterativeRunModeEnabled = false;
            this.IterativeStartTime      = DateTime.UtcNow;
            this.IterativeEndTime        = DateTime.UtcNow;

            // In case there is no subscription to select from user settings, skip the entire phase of re-loading resources from user settings
            if (this.userSettings.SelectedSubscription != null)
            {
                this.ShouldSelectResourcesAccordingToUserSettings = true;
            }

            this.SupportedResourceTypes = this.GetSupportedResourceTypes();

            this.ReadResourcesTask = new ObservableTask <List <ResourceIdentifier> >(
                Task.FromResult(new List <ResourceIdentifier>()),
                this.tracer);

            this.ReadSubscriptionsTask = new ObservableTask <ObservableCollection <HierarchicalResource> >(
                this.GetSubscriptionsAsync(),
                this.tracer,
                this.LoadPreviousSelectedSubscription);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartDetectorRunner"/> class
 /// </summary>
 /// <param name="smartDetectorRepository">The Smart Detector repository</param>
 /// <param name="smartDetectorLoader">The Smart Detector loader</param>
 /// <param name="analysisServicesFactory">The analysis services factory</param>
 /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param>
 /// <param name="stateRepositoryFactory">The state repository factory</param>
 /// <param name="tracer">The tracer</param>
 public SmartDetectorRunner(
     ISmartDetectorRepository smartDetectorRepository,
     ISmartDetectorLoader smartDetectorLoader,
     IInternalAnalysisServicesFactory analysisServicesFactory,
     IExtendedAzureResourceManagerClient azureResourceManagerClient,
     IStateRepositoryFactory stateRepositoryFactory,
     ITracer tracer)
 {
     this.smartDetectorRepository    = Diagnostics.EnsureArgumentNotNull(() => smartDetectorRepository);
     this.smartDetectorLoader        = Diagnostics.EnsureArgumentNotNull(() => smartDetectorLoader);
     this.analysisServicesFactory    = Diagnostics.EnsureArgumentNotNull(() => analysisServicesFactory);
     this.azureResourceManagerClient = Diagnostics.EnsureArgumentNotNull(() => azureResourceManagerClient);
     this.stateRepositoryFactory     = Diagnostics.EnsureArgumentNotNull(() => stateRepositoryFactory);
     this.tracer = tracer;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AnalysisServicesFactory"/> class.
        /// </summary>
        /// <param name="tracer">The tracer</param>
        /// <param name="httpClientWrapper">The HTTP client wrapper.</param>
        /// <param name="credentialsFactory">The credentials factory.</param>
        /// <param name="azureResourceManagerClient">The Azure Resource Manager client.</param>
        public AnalysisServicesFactory(ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IExtendedAzureResourceManagerClient azureResourceManagerClient)
        {
            this.tracer                     = tracer;
            this.httpClientWrapper          = httpClientWrapper;
            this.credentialsFactory         = credentialsFactory;
            this.azureResourceManagerClient = azureResourceManagerClient;

            // string timeoutString = ConfigurationReader.ReadConfig("AnalyticsQueryTimeoutInMinutes", required: true);
            string timeoutString = "15";

            this.queryTimeout = TimeSpan.FromMinutes(int.Parse(timeoutString, CultureInfo.InvariantCulture));

            this.UsedLogAnalysisClient = false;
            this.UsedMetricClient      = false;
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartDetectorRunner"/> class.
 /// </summary>
 /// <param name="smartDetector">The Smart Detector.</param>
 /// <param name="analysisServicesFactory">The analysis services factory.</param>
 /// <param name="smartDetectorManifest">The Smart Detector manifest.</param>
 /// <param name="stateRepositoryFactory">The state repository factory</param>
 /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param>
 /// <param name="logArchive">The log archive.</param>
 public SmartDetectorRunner(
     ISmartDetector smartDetector,
     IInternalAnalysisServicesFactory analysisServicesFactory,
     SmartDetectorManifest smartDetectorManifest,
     IStateRepositoryFactory stateRepositoryFactory,
     IExtendedAzureResourceManagerClient azureResourceManagerClient,
     IPageableLogArchive logArchive)
 {
     this.smartDetector           = smartDetector;
     this.analysisServicesFactory = analysisServicesFactory;
     this.smartDetectorManifest   = smartDetectorManifest;
     this.logArchive             = logArchive;
     this.IsSmartDetectorRunning = false;
     this.Alerts = new ObservableCollection <EmulationAlert>();
     this.stateRepositoryFactory     = stateRepositoryFactory;
     this.azureResourceManagerClient = azureResourceManagerClient;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationInsightsTelemetryDataClient"/> class.
 /// </summary>
 /// <param name="tracer">The tracer</param>
 /// <param name="httpClientWrapper">The HTTP client wrapper</param>
 /// <param name="credentialsFactory">The credentials factory</param>
 /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param>
 /// <param name="applicationsResourceIds">The resource IDs of the applications on which the queries will run.</param>
 /// <param name="queryTimeout">The query timeout.</param>
 public ApplicationInsightsTelemetryDataClient(
     ITracer tracer,
     IHttpClientWrapper httpClientWrapper,
     ICredentialsFactory credentialsFactory,
     IExtendedAzureResourceManagerClient azureResourceManagerClient,
     IEnumerable <string> applicationsResourceIds,
     TimeSpan queryTimeout)
     : base(
         tracer,
         httpClientWrapper,
         credentialsFactory,
         azureResourceManagerClient,
         ConfigurationManager.AppSettings["ApplicationInsightsUriFormat"] ?? UriFormat,
         queryTimeout,
         "ApplicationInsights",
         applicationsResourceIds)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogAnalyticsTelemetryDataClient"/> class.
 /// </summary>
 /// <param name="tracer">The tracer</param>
 /// <param name="httpClientWrapper">The HTTP client wrapper</param>
 /// <param name="credentialsFactory">The credentials factory</param>
 /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param>
 /// <param name="workspacesResourceIds">The resource IDs of the workspaces on which the queries will run.</param>
 /// <param name="queryTimeout">The query timeout.</param>
 public LogAnalyticsTelemetryDataClient(
     IExtendedTracer tracer,
     IHttpClientWrapper httpClientWrapper,
     ICredentialsFactory credentialsFactory,
     IExtendedAzureResourceManagerClient azureResourceManagerClient,
     IEnumerable <string> workspacesResourceIds,
     TimeSpan queryTimeout)
     : base(
         tracer,
         httpClientWrapper,
         credentialsFactory,
         azureResourceManagerClient,
         ConfigurationManager.AppSettings["LogAnalyticsUriFormat"] ?? UriFormat,
         queryTimeout,
         TelemetryDbType.LogAnalytics,
         workspacesResourceIds)
 {
 }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartDetectorRunner"/> class.
 /// </summary>
 /// <param name="smartDetector">The Smart Detector.</param>
 /// <param name="analysisServicesFactory">The analysis services factory.</param>
 /// <param name="queryRunInfoProvider">The query run information provider.</param>
 /// <param name="smartDetectorManifes">The Smart Detector manifest.</param>
 /// <param name="stateRepositoryFactory">The state repository factory</param>
 /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param>
 /// <param name="tracer">The tracer.</param>
 public SmartDetectorRunner(
     ISmartDetector smartDetector,
     IInternalAnalysisServicesFactory analysisServicesFactory,
     IQueryRunInfoProvider queryRunInfoProvider,
     SmartDetectorManifest smartDetectorManifes,
     IStateRepositoryFactory stateRepositoryFactory,
     IExtendedAzureResourceManagerClient azureResourceManagerClient,
     ITracer tracer)
 {
     this.smartDetector           = smartDetector;
     this.analysisServicesFactory = analysisServicesFactory;
     this.queryRunInfoProvider    = queryRunInfoProvider;
     this.smartDetectorManifest   = smartDetectorManifes;
     this.Tracer = tracer;
     this.IsSmartDetectorRunning = false;
     this.Alerts = new ObservableCollection <EmulationAlert>();
     this.stateRepositoryFactory     = stateRepositoryFactory;
     this.azureResourceManagerClient = azureResourceManagerClient;
 }
Beispiel #9
0
        protected TelemetryDataClientBase(
            ITracer tracer,
            IHttpClientWrapper httpClientWrapper,
            ICredentialsFactory credentialsFactory,
            IExtendedAzureResourceManagerClient azureResourceManagerClient,
            string queryUriFormat,
            TimeSpan queryTimeout,
            string telemetryDbType,
            IEnumerable <string> telemetryResourceIds)
        {
            this.tracer                     = Diagnostics.EnsureArgumentNotNull(() => tracer);
            this.httpClientWrapper          = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper);
            this.credentialsFactory         = Diagnostics.EnsureArgumentNotNull(() => credentialsFactory);
            this.AzureResourceManagerClient = Diagnostics.EnsureArgumentNotNull(() => azureResourceManagerClient);
            this.queryUriFormat             = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => queryUriFormat);
            this.Timeout                    = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2));
            this.telemetryDbType            = telemetryDbType;

            int maximumNumberOfTelemetryResources = int.Parse(ConfigurationManager.AppSettings["MaximumNumberOfTelemetryResources"] ?? "300", CultureInfo.InvariantCulture);

            this.TelemetryResourceIds = telemetryResourceIds?.Take(maximumNumberOfTelemetryResources).ToList() ?? new List <string>();

            this.retryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, this.telemetryDbType);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryRunInfoProvider"/> class
 /// </summary>
 /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param>
 public QueryRunInfoProvider(IExtendedAzureResourceManagerClient azureResourceManagerClient)
 {
     this.azureResourceManagerClient = azureResourceManagerClient;
 }