/// <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());
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivityLogClient"/> class.
        /// </summary>
        /// <param name="credentialsFactory">The credentials factory</param>
        /// <param name="httpClientWrapper">The HTTP client wrapper</param>
        /// <param name="tracer">The tracer</param>
        public ActivityLogClient(ICredentialsFactory credentialsFactory, IHttpClientWrapper httpClientWrapper, IExtendedTracer tracer)
        {
            this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper);
            this.tracer            = Diagnostics.EnsureArgumentNotNull(() => tracer);
            this.baseUri           = new Uri(ConfigurationManager.AppSettings["ResourceManagerBaseUri"] ?? "https://management.azure.com/");
            Diagnostics.EnsureArgumentNotNull(() => credentialsFactory);
            this.credentials = credentialsFactory.Create(ConfigurationManager.AppSettings["ResourceManagerCredentialsResource"] ?? "https://management.azure.com/");

            this.httpRetryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, DependencyName);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MdmClient"/> class
        /// </summary>
        /// <param name="tracer">The tracer</param>
        /// <param name="credentialsFactory">The credentials factory</param>
        /// <param name="resourceIdentifier">The resource for which we want to fetch data from MDM</param>
        /// /// <param name="monitorManagementClient">Monitor management client to use to fetch data from MDM</param>
        public MdmClient(ITracer tracer, ICredentialsFactory credentialsFactory, ResourceIdentifier resourceIdentifier, IMonitorManagementClient monitorManagementClient)
        {
            this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer);
            Diagnostics.EnsureArgumentNotNull(() => credentialsFactory);
            this.resourceIdentifier = resourceIdentifier;

            this.credentials             = credentialsFactory.Create("https://management.azure.com/");
            this.monitorManagementClient = monitorManagementClient;
            this.monitorManagementClient.SubscriptionId = resourceIdentifier.SubscriptionId;
            this.tracer      = tracer;
            this.retryPolicy = PolicyExtensions.CreateDefaultPolicy(this.tracer, DependencyName);
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendedAzureResourceManagerClient"/> class
 /// </summary>
 /// <param name="credentialsFactory">The credentials factory</param>
 /// <param name="tracer">The tracer</param>
 public ExtendedAzureResourceManagerClient(ICredentialsFactory credentialsFactory, IExtendedTracer tracer)
 {
     Diagnostics.EnsureArgumentNotNull(() => credentialsFactory);
     this.baseUri     = new Uri(ConfigurationManager.AppSettings["ResourceManagerBaseUri"] ?? "https://management.azure.com/");
     this.credentials = credentialsFactory.Create(ConfigurationManager.AppSettings["ResourceManagerCredentialsResource"] ?? "https://management.azure.com/");
     this.tracer      = Diagnostics.EnsureArgumentNotNull(() => tracer);
     this.tracer      = tracer;
     this.retryPolicy = Policy
                        .Handle <CloudException>(ex => ex.Request != null && (ex.Response.StatusCode >= HttpStatusCode.InternalServerError || ex.Response.StatusCode == HttpStatusCode.RequestTimeout))
                        .WaitAndRetryAsync(
         3,
         (i) => TimeSpan.FromSeconds(Math.Pow(2, i)),
         (exception, span, context) => tracer.TraceError($"Failed accessing DependencyName on {exception.Message}, retry {Math.Log(span.Seconds, 2)} out of 3"));
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class
 /// </summary>
 /// <param name="credentialsFactory">The credentials factory</param>
 /// <param name="tracer">The tracer</param>
 public AzureResourceManagerClient(ICredentialsFactory credentialsFactory, ITracer tracer)
 {
     this.credentials = credentialsFactory.Create("https://management.azure.com/");
     this.tracer      = tracer;
     this.retryPolicy = PolicyExtensions.CreateDefaultPolicy(this.tracer, DependencyName);
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MdmClient"/> class
 /// </summary>
 /// <param name="tracer">The tracer</param>
 /// <param name="credentialsFactory">The credentials factory</param>
 /// <param name="resourceIdentifier">The resource for which we want to fetch data from MDM</param>
 public MdmClient(ITracer tracer, ICredentialsFactory credentialsFactory, ResourceIdentifier resourceIdentifier) :
     this(tracer, credentialsFactory, resourceIdentifier, new MonitorManagementClient(credentialsFactory.Create("https://management.azure.com/")))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationInsightsClient"/> class.
 /// We are using this constructor for UTs.
 /// </summary>
 /// <param name="applicationId">The AI application id.</param>
 /// <param name="httpClient">The HTTP client.</param>
 /// <param name="credentialsFactory">The credentials factory (for AI authentication)</param>
 internal ApplicationInsightsClient(string applicationId, IHttpClientWrapper httpClient, ICredentialsFactory credentialsFactory)
 {
     this.applicationId = applicationId;
     this.httpClient    = httpClient;
     this.credentials   = credentialsFactory.Create(ApplicationInsightsResource);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationInsightsClient"/> class.
 /// </summary>
 /// <param name="applicationId">The AI application id.</param>
 /// <param name="credentialsFactory">The credentials factory (for AI authentication)</param>
 public ApplicationInsightsClient(string applicationId, ICredentialsFactory credentialsFactory)
 {
     this.applicationId = applicationId;
     this.credentials   = credentialsFactory.Create(ApplicationInsightsResource);
     this.httpClient    = new HttpClientWrapper();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MetricClient"/> class
 /// </summary>
 /// <param name="tracer">The tracer</param>
 /// <param name="credentialsFactory">The credentials factory</param>
 /// <param name="subscriptionId">The subscription Id</param>
 public MetricClient(IExtendedTracer tracer, ICredentialsFactory credentialsFactory, string subscriptionId)
     : this(tracer, subscriptionId, new MonitorManagementClient(credentialsFactory.Create("https://management.azure.com/")))
 {
 }