Exemple #1
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));
        }
Exemple #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 = await CreateEnvironmentResourcesAsync(context, configuration.Environments);

            context.Token.ThrowIfCancellationRequested();
            return(new Monitor(
                       configuration,
                       kustoIngestClient,
                       icmClient,
                       SystemClock.Instance,
                       environmentResources,
                       context.TracingContext.Logger));
        }
Exemple #3
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));
        }