Пример #1
0
        private static async Task <EnvironmentResources> CreateEnvironmentResourcesAsync(OperationContext context, EnvironmentConfiguration configuration)
        {
            var azure = ExternalDependenciesFactory.CreateAzureClient(
                configuration.AzureTenantId,
                configuration.AzureSubscriptionId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailure();

            var monitorManagementClient = await ExternalDependenciesFactory.CreateAzureMetricsClientAsync(
                configuration.AzureTenantId,
                configuration.AzureSubscriptionId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailureAsync();

            var redisCaches =
                (await azure
                 .RedisCaches
                 .ListAsync(cancellationToken: context.Token))
                .ToDictionary(cache => cache.Name, cache => cache);

            var kustoClient = ExternalDependenciesFactory.CreateKustoQueryClient(
                configuration.KustoClusterUrl,
                configuration.AzureTenantId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailure();

            context.Token.ThrowIfCancellationRequested();
            return(new EnvironmentResources(azure, monitorManagementClient, redisCaches, kustoClient));
        }
Пример #2
0
        public static async Task <Result <Monitor> > CreateAsync(OperationContext context, Configuration configuration)
        {
            Tracer.Info(context, "Creating Kusto ingest client");
            var kustoIngestClient = ExternalDependenciesFactory.CreateKustoIngestClient(configuration.KustoIngestionCredentials).ThrowIfFailure();

            IIcmClient icmClient;

            if (!configuration.ReadOnly)
            {
                Tracer.Info(context, "Creating KeyVault client");
                var keyVaultClient = new KeyVaultClient(
                    configuration.KeyVaultUrl,
                    configuration.KeyVaultCredentials.TenantId,
                    configuration.KeyVaultCredentials.AppId,
                    configuration.KeyVaultCredentials.AppKey,
                    SystemClock.Instance,
                    Constants.IcmCertificateCacheTimeToLive);

                Tracer.Info(context, "Creating IcM client");
                icmClient = new IcmClient(
                    keyVaultClient,
                    configuration.IcmUrl,
                    configuration.IcmConnectorId,
                    configuration.IcmCertificateName,
                    SystemClock.Instance);
            }
            else
            {
                Tracer.Info(context, "Using mock ICM client");
                icmClient = new MockIcmClient();
            }

            var environmentResources = new Dictionary <MonitorEnvironment, EnvironmentResources>();

            // This does a bunch of Azure API calls, which are really slow. Making them a bit faster by doing them
            // concurrently.
            await configuration.Environments.ParallelForEachAsync(async (keyValuePair) =>
            {
                var environment = keyValuePair.Key;
                var environmentConfiguration = keyValuePair.Value;

                Tracer.Info(context, $"Loading resources for environment `{environment}`");
                var resources = await CreateEnvironmentResourcesAsync(context, environmentConfiguration);

                lock (environmentResources)
                {
                    environmentResources[environment] = resources;
                }
            });

            context.Token.ThrowIfCancellationRequested();
            return(new Monitor(
                       configuration,
                       kustoIngestClient,
                       icmClient,
                       SystemClock.Instance,
                       environmentResources,
                       context.TracingContext.Logger));
        }
Пример #3
0
        private static async Task <EnvironmentResources> CreateEnvironmentResourcesAsync(Configuration configuration, EnvironmentConfiguration environmentConfiguration)
        {
            var azure = ExternalDependenciesFactory.CreateAzureClient(
                configuration.AzureTenantId,
                environmentConfiguration.AzureSubscriptionId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailure();

            var monitorManagementClient = await ExternalDependenciesFactory.CreateAzureMetricsClientAsync(
                configuration.AzureTenantId,
                environmentConfiguration.AzureSubscriptionId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailureAsync();

            var redisCaches = (await azure.RedisCaches.ListAsync()).ToDictionary(cache => cache.Name, cache => cache);

            return(new EnvironmentResources(azure, monitorManagementClient, redisCaches));
        }
Пример #4
0
        public static async Task <Result <Monitor> > CreateAsync(OperationContext context, Configuration configuration)
        {
            Tracer.Info(context, "Creating Kusto ingest client");
            var kustoIngestClient = ExternalDependenciesFactory.CreateKustoIngestClient(configuration.KustoIngestionCredentials).ThrowIfFailure();

            IIcmClient icmClient;

            if (!configuration.ReadOnly)
            {
                Tracer.Info(context, "Creating KeyVault client");
                var keyVaultClient = new KeyVaultClient(
                    configuration.KeyVaultUrl,
                    configuration.KeyVaultCredentials.TenantId,
                    configuration.KeyVaultCredentials.AppId,
                    configuration.KeyVaultCredentials.AppKey,
                    SystemClock.Instance,
                    Constants.IcmCertificateCacheTimeToLive);

                Tracer.Info(context, "Creating IcM client");
                icmClient = new IcmClient(
                    keyVaultClient,
                    configuration.IcmUrl,
                    configuration.IcmConnectorId,
                    configuration.IcmCertificateName,
                    SystemClock.Instance);
            }
            else
            {
                Tracer.Info(context, "Using mock ICM client");
                icmClient = new MockIcmClient();
            }

            var environmentResources = await CreateEnvironmentResourcesAsync(context, configuration.Environments);

            context.Token.ThrowIfCancellationRequested();
            return(new Monitor(
                       configuration,
                       kustoIngestClient,
                       icmClient,
                       SystemClock.Instance,
                       environmentResources,
                       context.TracingContext.Logger));
        }
Пример #5
0
        public static async Task <Result <Monitor> > CreateAsync(Configuration configuration, ILogger logger)
        {
            logger.Info("Creating Kusto ingest client");
            var kustoIngestClient = ExternalDependenciesFactory.CreateKustoIngestClient(
                configuration.KustoIngestionClusterUrl,
                configuration.AzureTenantId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailure();

            logger.Info("Creating Kusto query client");
            var cslQueryProvider = ExternalDependenciesFactory.CreateKustoQueryClient(
                configuration.KustoClusterUrl,
                configuration.AzureTenantId,
                configuration.AzureAppId,
                configuration.AzureAppKey).ThrowIfFailure();

            var environmentResources = new Dictionary <CloudBuildEnvironment, EnvironmentResources>();

            // This does a bunch of Azure API calls, which are really slow. Making them a bit faster by doing them
            // concurrently.
            await configuration.Environments.ParallelForEachAsync(async (keyValuePair) =>
            {
                var environment = keyValuePair.Key;
                var environmentConfiguration = keyValuePair.Value;

                logger.Info($"Loading resources for environment `{environment}`");
                var resources = await CreateEnvironmentResourcesAsync(configuration, environmentConfiguration);

                lock (environmentResources)
                {
                    environmentResources[environment] = resources;
                }
            });

            return(new Monitor(configuration, kustoIngestClient, cslQueryProvider, SystemClock.Instance, environmentResources, logger));
        }