Exemplo n.º 1
0
        public async void TestMdmGetDimensionValuesAsync()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<IEnumerable<string>> Run(DataProviders dataProviders) {
                    var filter = new List<Tuple<string, IEnumerable<string>>>
                    {
                        new Tuple<string, IEnumerable<string>>(""StampName"", new List<string>())
                    };

                    return await dataProviders.Mdm.GetDimensionValuesAsync(""Microsoft/Web/WebApps"", ""CpuTime"", filter, ""ServerName"", DateTime.UtcNow.AddMinutes(-30), DateTime.UtcNow);
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                var result = await invoker.Invoke(new object[] { dataProviders }) as IEnumerable <string>;

                Assert.NotNull(result);
                Assert.True(result.Count() == 3);
            }
        }
Exemplo n.º 2
0
        public async void E2E_Test_RuntimeSlotMapData()
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            //read a sample csx file from local directory
            metadata.ScriptText = await File.ReadAllTextAsync("GetRuntimeSiteSlotMapData.csx");

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                var appResource = new App(string.Empty, string.Empty, "my-api")
                {
                    Stamp = new HostingEnvironment(string.Empty, string.Empty, "waws-prod-bn1-71717c45")
                    {
                        Name = "waws-prod-bn1-71717c45"
                    }
                };

                var operationContext = new OperationContext <App>(appResource, string.Empty, string.Empty, true, string.Empty);
                var response         = new Response();

                Response result = (Response)await invoker.Invoke(new object[] { dataProviders, operationContext, response });

                Assert.Equal("my-api__a88nf", result.Dataset.First().Table.Rows[1][1]);
            }
        }
Exemplo n.º 3
0
        public async void TestBadObserverUrl()
        {
            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();
            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

            try
            {
                var data = await dataProviders.Observer.GetResource("https://not-wawsobserver.azurewebsites.windows.net/Sites/thor-api");
            }catch (Exception ex)
            {
                Assert.Contains("Please use a URL that points to one of the hosts", ex.Message);
            }

            await Assert.ThrowsAsync <FormatException>(async() => await dataProviders.Observer.GetResource("/sites/hawfor-site"));

            try
            {
                var data3 = await dataProviders.Observer.GetResource("/not-a-route/hawfor-site/not-resource");
            }catch (FormatException ex)
            {
                Assert.Contains("Please use a URL that points to one of the hosts", ex.Message);
            }

            await Assert.ThrowsAsync <ArgumentNullException>(async() => await dataProviders.Observer.GetResource(null));
        }
        public async void TestDetectorWithMDMConfigurationGists()
        {
            var references = new Dictionary <string, string>
            {
                { "mdm", GetMDMConfigurationGist() },
            };

            var metadata = new EntityMetadata(GetMDMDetector(), EntityType.Detector);

            var dataSourceConfiguration = new MockDataProviderConfigurationFactory();

            var config = dataSourceConfiguration.LoadConfigurations();

            ArmResource resource = new ArmResource("751A8C1D-EA9D-4FE7-8574-3096A81C2C08", "testResourceGroup", "Microsoft.AppPlatform", "Spring", "testResource", "FakeLocation");
            OperationContext <ArmResource> context = new OperationContext <ArmResource>(resource, "2019-12-09T00:10", "2019-12-09T23:54", true, "A9854948-807B-4371-B834-3EC78BB6635C");
            Response response = new Response();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, incomingHeaders: new HeaderDictionary()
            {
                [HeaderConstants.LocationHeader] = resource.Location
            }));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports(), references.ToImmutableDictionary()))
            {
                await invoker.InitializeEntryPointAsync().ConfigureAwait(false);

                await invoker.Invoke(new object[] { dataProviders, context, response }).ConfigureAwait(false);

                Assert.Equal("Diagnostics.DataProviders.MdmLogDecorator", response.Insights[0].Message);
            }
        }
Exemplo n.º 5
0
        public async void DataProvders_TestKustoFailover()
        {
            var configFactory         = new MockDataProviderConfigurationFactory();
            var config                = configFactory.LoadConfigurations();
            var kustoHeartBeatService = new KustoHeartBeatService(config.KustoConfiguration);

            MockKustoClient.ShouldHeartbeatSucceed = true;
            int startingHeartBeatRuns = MockKustoClient.HeartBeatRuns;

            do
            {
                await Task.Delay(100);
            } while (startingHeartBeatRuns == MockKustoClient.HeartBeatRuns);
            Assert.Equal(config.KustoConfiguration.KustoClusterNameGroupings, await kustoHeartBeatService.GetClusterNameFromStamp("waws-prod-mockstamp"));


            MockKustoClient.ShouldHeartbeatSucceed = false;
            startingHeartBeatRuns = MockKustoClient.HeartBeatRuns;
            do
            {
                await Task.Delay(100);
            } while (startingHeartBeatRuns == MockKustoClient.HeartBeatRuns);
            Assert.Equal(config.KustoConfiguration.KustoClusterFailoverGroupings, await kustoHeartBeatService.GetClusterNameFromStamp("waws-prod-mockstamp"));

            MockKustoClient.ShouldHeartbeatSucceed = true;
            startingHeartBeatRuns = MockKustoClient.HeartBeatRuns;
            do
            {
                await Task.Delay(100);
            } while (startingHeartBeatRuns == MockKustoClient.HeartBeatRuns);
            Assert.Equal(config.KustoConfiguration.KustoClusterNameGroupings, await kustoHeartBeatService.GetClusterNameFromStamp("waws-prod-mockstamp"));
        }
Exemplo n.º 6
0
        public async void TestChangeSetsRequest()
        {
            var dataSourceConfiguration = new MockDataProviderConfigurationFactory();
            var config = dataSourceConfiguration.LoadConfigurations();

            config.ChangeAnalysisDataProviderConfiguration = new ChangeAnalysisDataProviderConfiguration
            {
                AppKey   = string.Empty,
                ClientId = string.Empty,
            };
            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

            // Throws exception when querying for changes beyond last 14 days.
            await Assert.ThrowsAsync <ArgumentException>(async() =>
                                                         await dataProviders.ChangeAnalysis.GetChangeSetsForResource("/sites/test-site", DateTime.Now.AddDays(-15), DateTime.Now));
        }
Exemplo n.º 7
0
        public async Task E2E_Test_WAWSObserverAsync()
        {
            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            //read a sample csx file from local directory
            metadata.ScriptText = await File.ReadAllTextAsync("BackupCheckDetector.csx");

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                var appResource = new App(string.Empty, string.Empty, "my-api")
                {
                    Stamp = new HostingEnvironment(string.Empty, string.Empty, "waws-prod-bn1-71717c45")
                };

                appResource.Stamp.TenantIdList = new List <string>()
                {
                    Guid.NewGuid().ToString()
                };

                var operationContext = new OperationContext <App>(appResource, null, null, true, null);

                var response = new Response();

                try
                {
                    Response result = (Response)await invoker.Invoke(new object[] { dataProviders, operationContext, response });
                }
                catch (ScriptCompilationException ex)
                {
                    foreach (var output in ex.CompilationOutput)
                    {
                        Trace.WriteLine(output);
                    }
                }
            }
        }
        public void TestGenericSystemMdmAccount()
        {
            var dataSourceConfiguration = new MockDataProviderConfigurationFactory();

            var config = dataSourceConfiguration.LoadConfigurations();

            var mdmConfig = new GenericMdmDataProviderConfiguration
            {
                CertificateName   = "mock.azurewebsites.windows.net",
                Endpoint          = "http://0.0.0.0",
                MonitoringAccount = "Mock"
            };

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

            var mdmDataProvider = dataProviders.MdmGeneric(mdmConfig);

            Assert.NotNull(mdmDataProvider);
        }
Exemplo n.º 9
0
        public async void DataProvders_TestKusto()
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = GetDataProviderScript("TestA");

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                DataTable result = (DataTable)await invoker.Invoke(new object[] { dataProviders });

                Assert.NotNull(result);
            }
        }
        internal async void TestObserver()
        {
            var dataSourceConfiguration = new MockDataProviderConfigurationFactory();
            var config = dataSourceConfiguration.LoadConfigurations();

            config.SupportObserverConfiguration = new SupportObserverDataProviderConfiguration()
            {
                AppKey           = "",
                ClientId         = "",
                IsMockConfigured = false
            };

            var dataProviders    = new DataProviders.DataProviders(new DataProviderContext(config));
            var wawsObserverData = await dataProviders.Observer.GetResource("https://wawsobserver.azurewebsites.windows.net/sites/highcpuscenario");

            var supportBayData = await dataProviders.Observer.GetResource("https://support-bay-api.azurewebsites.net/observer/stamps/waws-prod-bay-073/sites/highcpuscenario/postbody");

            Assert.True(wawsObserverData != null);
            Assert.True(supportBayData != null);
        }
Exemplo n.º 11
0
        public async void TestRouteMatchLogic()
        {
            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();
            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config));

            //basic test
            var site123Data = await dataProviders.Observer.GetResource("https://wawsobserver.azurewebsites.windows.net/stamps/stamp123/sites/site123");

            //basic test with different resource
            var certData = await dataProviders.Observer.GetResource("https://wawsobserver.azurewebsites.windows.net/certificates/123456789");

            //test where parameter value is middle of url and not end of url
            var domainData = await dataProviders.Observer.GetResource("https://wawsobserver.azurewebsites.windows.net/subscriptions/1111-2222-3333-4444-5555/domains");

            //test with multiple parameter values
            var storageVolumeData = await dataProviders.Observer.GetResource("https://wawsobserver.azurewebsites.windows.net/stamps/waws-prod-mock1-001/storagevolumes/volume-19");

            Assert.Equal("site123", (string)site123Data.siteName);
            Assert.Equal("IPSSL", (string)certData.type);
            Assert.Equal("foo_bar.com", (string)domainData[0].name);
            Assert.Equal("volume-19", (string)storageVolumeData.name);
        }
Exemplo n.º 12
0
        public async void DataProvders_TestKusto()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<DataTable> Run(DataProviders dataProviders) {
                    return await dataProviders.Kusto.ExecuteQuery(""TestA"", ""waws-prod-mockstamp"");
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                var result = (DataTable)await invoker.Invoke(new object[] { dataProviders });

                Assert.NotNull(result);
            }
        }
Exemplo n.º 13
0
        public async void TestMdmGetMetricNamesAsync()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<IEnumerable<string>> Run(DataProviders dataProviders) {
                    return await dataProviders.Mdm.GetMetricNamesAsync(""Microsoft/Web/WebApps"");
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                var result = await invoker.Invoke(new object[] { dataProviders }) as IEnumerable <string>;

                Assert.NotNull(result);
                Assert.True(result.Count() == 3);
            }
        }
Exemplo n.º 14
0
        public async void TestMdmGetTimeSeriesValuesAsync()
        {
            var metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = @"
                public async static Task<IEnumerable<DataTable>> Run(DataProviders dataProviders) {
                    var dimensions = new Dictionary<string, string> { { ""StampName"", ""kudu1"" } };
                    return await dataProviders.Mdm.GetTimeSeriesAsync(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow, Sampling.Average | Sampling.Max | Sampling.Count, ""Microsoft/Web/WebApps"", ""CpuTime"", dimensions);
                }";

            var configFactory = new MockDataProviderConfigurationFactory();
            var config        = configFactory.LoadConfigurations();

            var dataProviders = new DataProviders.DataProviders(new DataProviderContext(config, Guid.NewGuid().ToString()));

            using (EntityInvoker invoker = new EntityInvoker(metadata, ScriptHelper.GetFrameworkReferences(), ScriptHelper.GetFrameworkImports()))
            {
                await invoker.InitializeEntryPointAsync();

                var result = await invoker.Invoke(new object[] { dataProviders }) as IEnumerable <DataTable>;

                Assert.NotNull(result);
            }
        }