/// <summary>
        /// Initializes a new instance of the <see cref="TelemetryDataClientBase"/> 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="queryUri">The query URI</param>
        /// <param name="queryTimeout">The query timeout</param>
        /// <param name="telemetryDbType">The type of telemetry DB that this data client accesses</param>
        /// <param name="mainTelemetryDbId">The main telemetry DB ID - the ID of the DB on which all queries will run</param>
        /// <param name="telemetryResourceIds">the telemetry resource IDs - the IDs of the resources that store the telemetry that this data client accesses</param>
        protected TelemetryDataClientBase(
            ITracer tracer,
            IHttpClientWrapper httpClientWrapper,
            ICredentialsFactory credentialsFactory,
            Uri queryUri,
            TimeSpan queryTimeout,
            TelemetryDbType telemetryDbType,
            string mainTelemetryDbId,
            IEnumerable <string> telemetryResourceIds)
        {
            this.tracer               = Diagnostics.EnsureArgumentNotNull(() => tracer);
            this.httpClientWrapper    = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper);
            this.Timeout              = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2));
            this.queryUri             = queryUri;
            this.TelemetryDbType      = telemetryDbType;
            this.MainTelemetryDbId    = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => mainTelemetryDbId);
            this.TelemetryResourceIds = telemetryResourceIds?.ToList() ?? new List <string>();
            this.retryPolicy          = PolicyExtensions.CreateDefaultPolicy(this.tracer, this.TelemetryDbType.ToString());

            // Extract the host part of the URI as the credentials resource
            UriBuilder builder = new UriBuilder()
            {
                Scheme = this.queryUri.Scheme,
                Host   = this.queryUri.Host
            };

            Diagnostics.EnsureArgumentNotNull(() => credentialsFactory);
            this.credentials = credentialsFactory.Create(builder.Uri.ToString());
        }
        /// <summary>
        /// Perform basic validations on the specified query run information.
        /// </summary>
        /// <param name="runInfo">The query run information</param>
        /// <param name="expectedType">The expected telemetry DB type</param>
        private void VerifyRunInfo(QueryRunInfo runInfo, TelemetryDbType expectedType)
        {
            // Verify the telemetry DB type
            if (runInfo.Type != expectedType)
            {
                throw new TelemetryDataClientCreationException($"Telemetry client creation failed - telemetry resource type is {runInfo.Type}");
            }

            // Verify that the resource IDs are not empty
            if (!runInfo.ResourceIds.Any())
            {
                throw new TelemetryDataClientCreationException("Telemetry client creation failed - no resources found");
            }
        }
예제 #3
0
 private void SetupTest(List <ResourceIdentifier> resources, TelemetryDbType telemetryDbType, string id)
 {
     this.queryRunInfoProviderMock
     .Setup(x => x.GetQueryRunInfoAsync(It.Is <IReadOnlyList <ResourceIdentifier> >(y => y.SequenceEqual(resources)), It.IsAny <CancellationToken>()))
     .ReturnsAsync(() => new SmartSignalResultItemQueryRunInfo(telemetryDbType, resources.Select(r => r.ToResourceId()).ToList()));
     if (telemetryDbType == TelemetryDbType.ApplicationInsights)
     {
         this.azureResourceManagerClientMock
         .Setup(x => x.GetApplicationInsightsAppIdAsync(It.Is <ResourceIdentifier>(r => r == resources[0]), It.IsAny <CancellationToken>()))
         .ReturnsAsync(() => id);
     }
     else
     {
         this.azureResourceManagerClientMock
         .Setup(x => x.GetLogAnalyticsWorkspaceIdAsync(It.Is <ResourceIdentifier>(r => r == resources[0]), It.IsAny <CancellationToken>()))
         .ReturnsAsync(() => id);
     }
 }
예제 #4
0
        protected TelemetryDataClientBase(
            IExtendedTracer tracer,
            IHttpClientWrapper httpClientWrapper,
            ICredentialsFactory credentialsFactory,
            IExtendedAzureResourceManagerClient azureResourceManagerClient,
            string queryUriFormat,
            TimeSpan queryTimeout,
            TelemetryDbType 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.ToString());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartSignalResultItemQueryRunInfo"/> class.
 /// </summary>
 /// <param name="type">The telemetry database type</param>
 /// <param name="resourceIds">The telemetry resource Ids</param>
 public SmartSignalResultItemQueryRunInfo(TelemetryDbType type, IReadOnlyList <string> resourceIds)
 {
     this.Type        = type;
     this.ResourceIds = resourceIds;
 }