Пример #1
0
        public async Task DataFeedSourceSendsSecretDuringCreation(DataFeedSource dataSource, string secretPropertyName)
        {
            MockResponse createResponse = new MockResponse(201);

            createResponse.AddHeader(new HttpHeader("Location", $"https://fakeresource.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/{FakeGuid}"));

            MockResponse getResponse = new MockResponse(200);

            getResponse.SetContent(DataFeedResponseContent);

            MockTransport mockTransport = new MockTransport(createResponse, getResponse);
            MetricsAdvisorAdministrationClient adminClient = CreateInstrumentedAdministrationClient(mockTransport);
            DataFeed dataFeed = new DataFeed()
            {
                Name              = "name",
                DataSource        = dataSource,
                Granularity       = new DataFeedGranularity(DataFeedGranularityType.Daily),
                Schema            = new DataFeedSchema(),
                IngestionSettings = new DataFeedIngestionSettings(DateTimeOffset.UtcNow)
            };

            dataFeed.Schema.MetricColumns.Add(new DataFeedMetric("metric"));

            await adminClient.CreateDataFeedAsync(dataFeed);

            MockRequest request = mockTransport.Requests.First();
            string      content = ReadContent(request);

            Assert.That(content, ContainsJsonString(secretPropertyName, "secret"));
        }
        /// <summary>
        /// Creates a data feed using the specified <see cref="MetricsAdvisorAdministrationClient"/>.
        /// A <see cref="DisposableDataFeed"/> instance is returned, from which the ID of the created
        /// data feed can be obtained. Upon disposal, the associated data feed will be deleted.
        /// </summary>
        /// <param name="adminClient">The client to use for creating and for deleting the data feed.</param>
        /// <param name="hook">Specifies how the created <see cref="DataFeed"/> should be configured.</param>
        /// <returns>A <see cref="DisposableDataFeed"/> instance from which the ID of the created data feed can be obtained.</returns>
        public static async Task <DisposableDataFeed> CreateDataFeedAsync(MetricsAdvisorAdministrationClient adminClient, DataFeed dataFeed)
        {
            string dataFeedId = await adminClient.CreateDataFeedAsync(dataFeed);

            Assert.That(dataFeedId, Is.Not.Null.And.Not.Empty);

            return(new DisposableDataFeed(adminClient, dataFeedId));
        }
Пример #3
0
        public void CreateDataFeedValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.CreateDataFeedAsync(null), Throws.InstanceOf <ArgumentNullException>());

            Assert.That(() => adminClient.CreateDataFeed(null), Throws.InstanceOf <ArgumentNullException>());
        }
        public async Task CreateAndDeleteDataFeedAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            string sqlServerConnectionString = SqlServerConnectionString;
            string sqlServerQuery            = SqlServerQuery;

            #region Snippet:CreateDataFeedAsync
            //@@ string sqlServerConnectionString = "<connectionString>";
            //@@ string sqlServerQuery = "<query>";

            var dataFeedName        = "Sample data feed";
            var dataFeedSource      = new SqlServerDataFeedSource(sqlServerConnectionString, sqlServerQuery);
            var dataFeedGranularity = new DataFeedGranularity(DataFeedGranularityType.Daily);

            var dataFeedMetrics = new List <DataFeedMetric>()
            {
                new DataFeedMetric("cost"),
                new DataFeedMetric("revenue")
            };
            var dataFeedDimensions = new List <DataFeedDimension>()
            {
                new DataFeedDimension("category"),
                new DataFeedDimension("city")
            };
            var dataFeedSchema = new DataFeedSchema(dataFeedMetrics)
            {
                DimensionColumns = dataFeedDimensions
            };

            var ingestionStartTime        = DateTimeOffset.Parse("2020-01-01T00:00:00Z");
            var dataFeedIngestionSettings = new DataFeedIngestionSettings(ingestionStartTime);

            var dataFeed = new DataFeed(dataFeedName, dataFeedSource, dataFeedGranularity, dataFeedSchema, dataFeedIngestionSettings);

            Response <string> response = await adminClient.CreateDataFeedAsync(dataFeed);

            string dataFeedId = response.Value;

            Console.WriteLine($"Data feed ID: {dataFeedId}");
            #endregion

            // Only the ID of the data feed is known at this point. You can perform another service
            // call to GetDataFeedAsync or GetDataFeed to get more information, such as status, created
            // time, the list of administrators, or the metric IDs.

            // Delete the created data feed to clean up the Metrics Advisor resource. Do not perform this
            // step if you intend to keep using the data feed.

            await adminClient.DeleteDataFeedAsync(dataFeedId);
        }
Пример #5
0
        public void CreateDataFeedValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var name        = "dataFeedName";
            var dataSource  = new AzureTableDataFeedSource("connectionString", "table", "query");
            var granularity = new DataFeedGranularity(DataFeedGranularityType.Daily);
            var schema      = new DataFeedSchema()
            {
                MetricColumns = { new("metricName") }
            };
            var ingestionSettings = new DataFeedIngestionSettings(DateTimeOffset.UtcNow);

            var dataFeed = new DataFeed()
            {
                Name              = null,
                DataSource        = dataSource,
                Granularity       = granularity,
                Schema            = schema,
                IngestionSettings = ingestionSettings
            };

            Assert.That(() => adminClient.CreateDataFeedAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDataFeed(null), Throws.InstanceOf <ArgumentNullException>());

            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed), Throws.InstanceOf <ArgumentNullException>());

            dataFeed.Name = "";
            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed), Throws.InstanceOf <ArgumentException>());

            dataFeed.Name       = name;
            dataFeed.DataSource = null;
            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed), Throws.InstanceOf <ArgumentNullException>());

            dataFeed.DataSource  = dataSource;
            dataFeed.Granularity = null;
            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed), Throws.InstanceOf <ArgumentNullException>());

            dataFeed.Granularity = granularity;
            dataFeed.Schema      = null;
            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed), Throws.InstanceOf <ArgumentNullException>());

            dataFeed.Schema            = schema;
            dataFeed.IngestionSettings = null;
            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed), Throws.InstanceOf <ArgumentNullException>());
        }
Пример #6
0
        public void CreateDataFeedRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var dataSource  = new AzureTableDataFeedSource("connectionString", "table", "query");
            var granularity = new DataFeedGranularity(DataFeedGranularityType.Daily);
            var schema      = new DataFeedSchema(new List <DataFeedMetric>()
            {
                new DataFeedMetric("metricName")
            });
            var ingestionSettings = new DataFeedIngestionSettings(DateTimeOffset.UtcNow);
            var dataFeed          = new DataFeed("dataFeedName", dataSource, granularity, schema, ingestionSettings);

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            Assert.That(() => adminClient.CreateDataFeedAsync(dataFeed, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.CreateDataFeed(dataFeed, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Пример #7
0
        public async Task CreateAndDeleteDataFeedAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            #region Snippet:CreateDataFeedAsync
#if SNIPPET
            string sqlServerConnectionString = "<connectionString>";
            string sqlServerQuery            = "<query>";
#else
            string sqlServerConnectionString = SqlServerConnectionString;
            string sqlServerQuery            = SqlServerQuery;
#endif

            var dataFeed = new DataFeed();

#if SNIPPET
            dataFeed.Name = "<dataFeedName>";
#else
            dataFeed.Name = GetUniqueName();
#endif
            dataFeed.DataSource  = new SqlServerDataFeedSource(sqlServerConnectionString, sqlServerQuery);
            dataFeed.Granularity = new DataFeedGranularity(DataFeedGranularityType.Daily);

            dataFeed.Schema = new DataFeedSchema();
            dataFeed.Schema.MetricColumns.Add(new DataFeedMetric("cost"));
            dataFeed.Schema.MetricColumns.Add(new DataFeedMetric("revenue"));
            dataFeed.Schema.DimensionColumns.Add(new DataFeedDimension("category"));
            dataFeed.Schema.DimensionColumns.Add(new DataFeedDimension("city"));

            dataFeed.IngestionSettings = new DataFeedIngestionSettings(DateTimeOffset.Parse("2020-01-01T00:00:00Z"));

            Response <DataFeed> response = await adminClient.CreateDataFeedAsync(dataFeed);

            DataFeed createdDataFeed = response.Value;

            Console.WriteLine($"Data feed ID: {createdDataFeed.Id}");
            Console.WriteLine($"Data feed status: {createdDataFeed.Status.Value}");
            Console.WriteLine($"Data feed created time: {createdDataFeed.CreatedTime.Value}");

            Console.WriteLine($"Data feed administrators:");
            foreach (string admin in createdDataFeed.AdministratorsEmails)
            {
                Console.WriteLine($" - {admin}");
            }

            Console.WriteLine($"Metric IDs:");
            foreach (DataFeedMetric metric in createdDataFeed.Schema.MetricColumns)
            {
                Console.WriteLine($" - {metric.Name}: {metric.Id}");
            }

            Console.WriteLine($"Dimension columns:");
            foreach (DataFeedDimension dimension in createdDataFeed.Schema.DimensionColumns)
            {
                Console.WriteLine($" - {dimension.Name}");
            }
            #endregion

            // Delete the created data feed to clean up the Metrics Advisor resource. Do not perform this
            // step if you intend to keep using the data feed.

            await adminClient.DeleteDataFeedAsync(createdDataFeed.Id);
        }
Пример #8
0
        /// <summary>
        /// Creates a data feed using the specified <see cref="MetricsAdvisorAdministrationClient"/>.
        /// A <see cref="DisposableDataFeed"/> instance is returned, from which the created data feed
        /// can be obtained. Upon disposal, the associated data feed will be deleted.
        /// </summary>
        /// <param name="adminClient">The client to use for creating and for deleting the data feed.</param>
        /// <param name="dataFeed">Specifies how the created <see cref="Models.DataFeed"/> should be configured.</param>
        /// <returns>A <see cref="DisposableDataFeed"/> instance from which the created data feed can be obtained.</returns>
        public static async Task <DisposableDataFeed> CreateDataFeedAsync(MetricsAdvisorAdministrationClient adminClient, DataFeed dataFeed)
        {
            DataFeed createdDataFeed = await adminClient.CreateDataFeedAsync(dataFeed);

            return(new DisposableDataFeed(adminClient, createdDataFeed));
        }