public void GetDataFeedValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.GetDataFeedAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.GetDataFeedAsync(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.GetDataFeedAsync("dataFeedId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));

            Assert.That(() => adminClient.GetDataFeed(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.GetDataFeed(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.GetDataFeed("dataFeedId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
        }
        public async Task UpdateDataFeedAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

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

            string dataFeedId = DataFeedId;

            Response <DataFeed> response = await adminClient.GetDataFeedAsync(dataFeedId);

            DataFeed dataFeed = response.Value;

            string originalDescription = dataFeed.Description;

            dataFeed.Description = "This description was generated by a sample.";

            await adminClient.UpdateDataFeedAsync(dataFeedId, dataFeed);

            // Undo the changes to leave the data feed unaltered. Skip this step if you intend to keep
            // the changes.

            dataFeed.Description = originalDescription;
            await adminClient.UpdateDataFeedAsync(dataFeedId, dataFeed);
        }
Example #3
0
        public async Task DataFeedSourceUpdatesUnknownDataFeed()
        {
            MockResponse getResponse = new MockResponse(200);

            getResponse.SetContent(UnknownDataFeedContent);

            MockResponse updateResponse = new MockResponse(200);

            updateResponse.SetContent(UnknownDataFeedContent);

            MockTransport mockTransport = new MockTransport(getResponse, updateResponse);
            MetricsAdvisorAdministrationClient adminClient = CreateInstrumentedAdministrationClient(mockTransport);
            DataFeed dataFeed = await adminClient.GetDataFeedAsync(FakeGuid);

            dataFeed.Name = "newDataFeedName";
            dataFeed.MissingDataPointFillSettings = new DataFeedMissingDataPointFillSettings(DataFeedMissingDataPointFillType.PreviousValue);
            dataFeed.Description = "new description";

            await adminClient.UpdateDataFeedAsync(dataFeed);

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

            Assert.That(request.Uri.Path, Contains.Substring(FakeGuid));
            Assert.That(content, ContainsJsonString("dataFeedName", "newDataFeedName"));
            Assert.That(content, ContainsJsonString("dataSourceType", "unknownType"));
            Assert.That(content, ContainsJsonString("fillMissingPointType", "PreviousValue"));
            Assert.That(content, ContainsJsonString("dataFeedDescription", "new description"));
        }
        public void GetDataFeedRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

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

            Assert.That(() => adminClient.GetDataFeedAsync(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.GetDataFeed(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Example #5
0
        public async Task DataFeedSourceGetsUnknownDataFeed()
        {
            MockResponse getResponse = new MockResponse(200);

            getResponse.SetContent(UnknownDataFeedContent);

            MetricsAdvisorAdministrationClient adminClient = CreateInstrumentedAdministrationClient(getResponse);
            DataFeed dataFeed = await adminClient.GetDataFeedAsync(FakeGuid);

            Assert.That(dataFeed.Id, Is.EqualTo(FakeGuid));
            Assert.That(dataFeed.Name, Is.EqualTo("unknownDataFeedName"));
            Assert.That(dataFeed.MissingDataPointFillSettings.FillType, Is.EqualTo(DataFeedMissingDataPointFillType.NoFilling));
            Assert.That(dataFeed.Description, Is.EqualTo("unknown data feed description"));

            DataFeedMetric metric = dataFeed.Schema.MetricColumns.Single();

            Assert.That(metric.Id, Is.EqualTo(FakeGuid));
            Assert.That(metric.Name, Is.EqualTo("cost"));
        }
Example #6
0
        public async Task UpdateDataFeedAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

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

            string dataFeedId = DataFeedId;

            Response <DataFeed> response = await adminClient.GetDataFeedAsync(dataFeedId);

            DataFeed dataFeed = response.Value;

            string originalDescription = dataFeed.Description;

            dataFeed.Description = "This description was generated by a sample.";

            // Some properties, such as IngestionStartOffset, can be reset to their default value
            // when set to null during an Update operation. Check the API documentation to verify
            // when a property supports this feature.

            TimeSpan?originalStartOffset = dataFeed.IngestionSettings.IngestionStartOffset;

            dataFeed.IngestionSettings.IngestionStartOffset = null;

            response = await adminClient.UpdateDataFeedAsync(dataFeed);

            DataFeed updatedDataFeed = response.Value;

            Console.WriteLine($"Updated description: {updatedDataFeed.Description}");
            Console.WriteLine($"Updated ingestion start offset: {updatedDataFeed.IngestionSettings.IngestionStartOffset}");

            // Undo the changes to leave the data feed unaltered. Skip this step if you intend to keep
            // the changes.

            dataFeed.Description = originalDescription;
            dataFeed.IngestionSettings.IngestionStartOffset = originalStartOffset;

            await adminClient.UpdateDataFeedAsync(dataFeed);
        }
        public async Task GetDataFeedAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

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

            string dataFeedId = DataFeedId;

            #region Snippet:GetDataFeedAsync
            //@@ string dataFeedId = "<dataFeedId>";

            Response <DataFeed> response = await adminClient.GetDataFeedAsync(dataFeedId);

            DataFeed dataFeed = response.Value;

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

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

            Console.WriteLine($"Metric IDs:");
            foreach (DataFeedMetric metric in dataFeed.Schema.MetricColumns)
            {
                Console.WriteLine($" - {metric.MetricName}: {metric.MetricId}");
            }
            #endregion

            Console.WriteLine($"Dimension columns:");
            foreach (DataFeedDimension dimension in dataFeed.Schema.DimensionColumns)
            {
                Console.WriteLine($" - {dimension.DimensionName}");
            }
        }
Example #8
0
        public async Task MetricsAdvisorNotFound()
        {
            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:MetricsAdvisorNotFound
            string dataFeedId = "00000000-0000-0000-0000-000000000000";

            try
            {
                Response <DataFeed> response = await adminClient.GetDataFeedAsync(dataFeedId);
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            #endregion
        }
        public async Task CreateDataFeedFromDataSource()
        {
            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:CreateDataFeedFromDataSource
            //@@ string sqlServerConnectionString = "<connectionString>";
            //@@ string sqlServerQuery = "<query>";

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

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

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

            Response <DataFeed> response = await adminClient.CreateDataFeedAsync(dataFeedName, dataFeedSource,
                                                                                 dataFeedGranularity, dataFeedSchema, dataFeedIngestionSettings);

            DataFeed dataFeed = response.Value;

            Console.WriteLine($"Data feed ID: {dataFeed.Id}");

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

            response = await adminClient.GetDataFeedAsync(dataFeed.Id);

            dataFeed = response.Value;

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

            Console.WriteLine($"Data feed administrators:");
            foreach (string admin in dataFeed.Options.Administrators)
            {
                Console.WriteLine($" - {admin}");
            }

            Console.WriteLine($"Metric IDs:");
            foreach (DataFeedMetric metric in dataFeed.Schema.MetricColumns)
            {
                Console.WriteLine($" - {metric.MetricName}: {metric.MetricId}");
            }

            #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(dataFeed.Id);
        }