Exemplo n.º 1
0
    void Initialize()
    {
        var light = GameObject.Find("Directional Light");

        if (light == null)
        {
            return;
        }

        m_LightingInfoDefinition = DatasetCapture.RegisterMetricDefinition("lighting info", "Per-frame light color and orientation", id: k_LightingInfoGuid);
        m_Light = light.GetComponent <Light>();
        // To simulate phong shading we turn off shadows
        m_Light.shadows = LightShadows.None;
        m_IsInitialized = true;


        // Try to find game object here because scene may not be initialized on Create()
        if (m_InitParams == null)
        {
            m_InitParams = GameObject.Find("Management")?.GetComponentInChildren <ProjectInitialization>();
            if (m_InitParams == null)
            {
                Debug.LogWarning("Unable to find Management object. Will not randomize lighting.");
                return;
            }
        }
    }
        private static void AssertRedisCacheMetricDefinition(MetricDefinition deserializedRedisCacheMetricDefinition, RedisCacheMetricDefinitionV1 redisCacheMetricDefinition)
        {
            var deserializedResource = deserializedRedisCacheMetricDefinition.Resources.Single() as RedisCacheResourceDefinition;

            Assert.NotNull(deserializedResource);
            Assert.Equal(redisCacheMetricDefinition.CacheName, deserializedResource.CacheName);
        }
Exemplo n.º 3
0
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefinition metricDefinitionDefinition)
        {
            _logger.LogInformation("Scraping '{metricName}' for resource type '{resourceType}'", metricDefinitionDefinition.Name, metricDefinitionDefinition.ResourceType);

            var scraper = MetricScraperFactory.CreateScraper(azureMetadata, metricDefinitionDefinition.ResourceType, _logger, _exceptionTracker);
            await scraper.ScrapeAsync(metricDefinitionDefinition);
        }
        private static void AssertNetworkInterfaceMetricDefinition(MetricDefinition deserializedNetworkInterfaceMetricDefinition, NetworkInterfaceMetricDefinitionV1 networkInterfaceMetricDefinition)
        {
            var deserializedResource = deserializedNetworkInterfaceMetricDefinition.Resources.Single() as NetworkInterfaceResourceDefinition;

            Assert.NotNull(deserializedResource);
            Assert.Equal(networkInterfaceMetricDefinition.NetworkInterfaceName, deserializedResource.NetworkInterfaceName);
        }
        private static void AssertContainerRegistryMetricDefinition(MetricDefinition deserializedContainerRegistryMetricDefinition, ContainerRegistryMetricDefinitionV1 containerRegistryMetricDefinition)
        {
            var deserializedResource = deserializedContainerRegistryMetricDefinition.Resources.Single() as ContainerRegistryResourceDefinition;

            Assert.NotNull(deserializedResource);
            Assert.Equal(containerRegistryMetricDefinition.RegistryName, deserializedResource.RegistryName);
        }
        public ResourceDiscoveryGroupScrapingJob(string jobName, string resourceDiscoveryGroupName, AzureMetadata azureMetadata, MetricDefinition metricDefinition, ResourceDiscoveryRepository resourceDiscoveryRepository,
                                                 MetricSinkWriter metricSinkWriter,
                                                 MetricScraperFactory metricScraperFactory,
                                                 AzureMonitorClientFactory azureMonitorClientFactory, IRuntimeMetricsCollector runtimeMetricCollector, IConfiguration configuration, IOptions <AzureMonitorLoggingConfiguration> azureMonitorLoggingConfiguration, ILoggerFactory loggerFactory,
                                                 ILogger <ResourceDiscoveryGroupScrapingJob> logger)
            : base(jobName, logger)
        {
            Guard.NotNullOrWhitespace(resourceDiscoveryGroupName, nameof(resourceDiscoveryGroupName));
            Guard.NotNull(resourceDiscoveryRepository, nameof(resourceDiscoveryRepository));
            Guard.NotNull(metricDefinition, nameof(metricDefinition));
            Guard.NotNull(azureMetadata, nameof(azureMetadata));
            Guard.NotNullOrWhitespace(jobName, nameof(jobName));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(azureMonitorClientFactory, nameof(azureMonitorClientFactory));
            Guard.NotNull(runtimeMetricCollector, nameof(runtimeMetricCollector));
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(azureMonitorLoggingConfiguration, nameof(azureMonitorLoggingConfiguration));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(metricSinkWriter, nameof(metricSinkWriter));

            ResourceDiscoveryGroupName = resourceDiscoveryGroupName;

            _azureMetadata               = azureMetadata;
            _metricDefinition            = metricDefinition;
            _resourceDiscoveryRepository = resourceDiscoveryRepository;
            _metricSinkWriter            = metricSinkWriter;

            _runtimeMetricCollector           = runtimeMetricCollector;
            _azureMonitorClientFactory        = azureMonitorClientFactory;
            _configuration                    = configuration;
            _azureMonitorLoggingConfiguration = azureMonitorLoggingConfiguration;
            _loggerFactory                    = loggerFactory;

            _metricScraperFactory = metricScraperFactory;
        }
        public IEnumerable <string> Validate(MetricDefinition metricDefinition)
        {
            Guard.NotNull(metricDefinition, nameof(metricDefinition));

            var errorMessages = new List <string>();

            var configuredDimension = metricDefinition.AzureMetricConfiguration?.Dimension?.Name;

            if (string.IsNullOrWhiteSpace(configuredDimension) == false &&
                configuredDimension.Equals(UnsupportedEntityDimension, StringComparison.InvariantCultureIgnoreCase))
            {
                errorMessages.Add($"Dimension '{UnsupportedEntityDimension}' is not supported for now");
            }

            foreach (var resourceDefinition in metricDefinition.Resources.Cast <ServiceBusQueueResourceDefinition>())
            {
                if (string.IsNullOrWhiteSpace(resourceDefinition.Namespace))
                {
                    errorMessages.Add("No Service Bus Namespace is configured");
                }

                if (string.IsNullOrWhiteSpace(resourceDefinition.QueueName))
                {
                    errorMessages.Add("No queue name is configured");
                }
            }

            return(errorMessages);
        }
        private static void AssertPostgreSqlMetricDefinition(MetricDefinition deserializedPostgreSqlMetricDefinition, PostgreSqlMetricDefinitionV1 postgreSqlMetricDefinition)
        {
            var deserializedResource = deserializedPostgreSqlMetricDefinition.Resources.Single() as PostgreSqlResourceDefinition;

            Assert.NotNull(deserializedResource);
            Assert.Equal(postgreSqlMetricDefinition.ServerName, deserializedResource.ServerName);
        }
Exemplo n.º 9
0
        private static void AssertCosmosDbMetricDefinition(MetricDefinition deserializedCosmosDbMetricDefinition, CosmosDbMetricDefinitionV1 cosmosDbMetricDefinition)
        {
            var deserializedResource = deserializedCosmosDbMetricDefinition.Resources.Single() as CosmosDbResourceDefinition;

            Assert.NotNull(deserializedResource);
            Assert.Equal(cosmosDbMetricDefinition.DbName, deserializedResource.DbName);
        }
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefinition metricDefinitionDefinition)
        {
            Console.WriteLine($"\t> Scraping {metricDefinitionDefinition.Name} of type {metricDefinitionDefinition.ResourceType}");

            var scraper = MetricScraperFactory.CreateScraper(azureMetadata, metricDefinitionDefinition.ResourceType);
            await scraper.ScrapeAsync(metricDefinitionDefinition);
        }
        public IEnumerable <string> Validate(MetricDefinition metricDefinition)
        {
            Guard.NotNull(metricDefinition, nameof(metricDefinition));

            var errorMessages = new List <string>();

            var configuredDimension             = metricDefinition.AzureMetricConfiguration?.Dimension?.Name;
            var isEntityNameDimensionConfigured = string.IsNullOrWhiteSpace(configuredDimension) == false && configuredDimension.Equals(EntityNameDimension, StringComparison.InvariantCultureIgnoreCase);

            foreach (var resourceDefinition in metricDefinition.Resources.Cast <ServiceBusNamespaceResourceDefinition>())
            {
                if (string.IsNullOrWhiteSpace(resourceDefinition.Namespace))
                {
                    errorMessages.Add("No Service Bus Namespace is configured");
                }

                if (isEntityNameDimensionConfigured && string.IsNullOrWhiteSpace(resourceDefinition.QueueName) == false)
                {
                    errorMessages.Add($"Queue name is configured while '{EntityNameDimension}' dimension is configured as well. We only support one or the other.");
                }

                if (isEntityNameDimensionConfigured && string.IsNullOrWhiteSpace(resourceDefinition.TopicName) == false)
                {
                    errorMessages.Add($"Topic name is configured while '{EntityNameDimension}' dimension is configured as well. We only support one or the other.");
                }

                if (string.IsNullOrWhiteSpace(resourceDefinition.QueueName) == false && string.IsNullOrWhiteSpace(resourceDefinition.TopicName) == false)
                {
                    errorMessages.Add("Queue & topic name are both configured while we only support one or the other.");
                }
            }

            return(errorMessages);
        }
Exemplo n.º 12
0
        protected void AssertMetricDefinition(MetricDefinition deserializedMetricDefinition, MetricDefinitionV1 metricDefinition)
        {
            Assert.NotNull(deserializedMetricDefinition);
            Assert.NotNull(deserializedMetricDefinition.PrometheusMetricDefinition);
            Assert.Equal(metricDefinition.Name, deserializedMetricDefinition.PrometheusMetricDefinition.Name);
            Assert.Equal(metricDefinition.Description, deserializedMetricDefinition.PrometheusMetricDefinition.Description);
            Assert.Equal(metricDefinition.ResourceType, deserializedMetricDefinition.ResourceType);
            Assert.NotNull(deserializedMetricDefinition.PrometheusMetricDefinition.Labels);
            Assert.Equal(metricDefinition.Labels, deserializedMetricDefinition.PrometheusMetricDefinition.Labels);
            Assert.NotEmpty(deserializedMetricDefinition.Resources);
            Assert.Equal(deserializedMetricDefinition.Resources.Single().ResourceGroupName, metricDefinition.ResourceGroupName);

            foreach (var label in metricDefinition.Labels)
            {
                var deserializedLabel = deserializedMetricDefinition.PrometheusMetricDefinition.Labels[label.Key];
                Assert.NotNull(deserializedLabel);
                Assert.Equal(label.Value, deserializedLabel);
            }

            Assert.NotNull(deserializedMetricDefinition.AzureMetricConfiguration);
            Assert.Equal(metricDefinition.AzureMetricConfiguration.MetricName, deserializedMetricDefinition.AzureMetricConfiguration.MetricName);
            Assert.NotNull(deserializedMetricDefinition.AzureMetricConfiguration.Aggregation);
            Assert.Equal(metricDefinition.AzureMetricConfiguration.Aggregation.Type, deserializedMetricDefinition.AzureMetricConfiguration.Aggregation.Type);
            Assert.Equal(metricDefinition.AzureMetricConfiguration.Aggregation.Interval, deserializedMetricDefinition.AzureMetricConfiguration.Aggregation.Interval);
        }
Exemplo n.º 13
0
        private IList <string> Validate(MetricDefinition metric)
        {
            Guard.NotNull(metric, nameof(metric));

            var errorMessages = new List <string>();

            if (metric == null)
            {
                errorMessages.Add("Invalid metric is configured");
                return(errorMessages);
            }

            if (metric.ResourceType == ResourceType.NotSpecified)
            {
                errorMessages.Add($"{metric.ResourceType} '{nameof(ResourceType.NotSpecified)}' is not supported");
            }

            if (string.IsNullOrWhiteSpace(metric.Name))
            {
                errorMessages.Add("No metric name is configured");
            }

            var metricDefinitionValidationErrors = MetricValidatorFactory
                                                   .GetValidatorFor(metric.ResourceType)
                                                   .Validate(metric);

            errorMessages.AddRange(metricDefinitionValidationErrors);

            var metricAggregationValidator        = new AzureMetricConfigurationValidator(_metricDefaults);
            var metricsConfigurationErrorMessages = metricAggregationValidator.Validate(metric.AzureMetricConfiguration);

            errorMessages.AddRange(metricsConfigurationErrorMessages);

            return(errorMessages);
        }
Exemplo n.º 14
0
        public async Task ScrapeAsync(MetricDefinition metricDefinition)
        {
            try
            {
                if (metricDefinition == null)
                {
                    throw new ArgumentNullException(nameof(metricDefinition));
                }

                if (!(metricDefinition is TMetricDefinition castedMetricDefinition))
                {
                    throw new ArgumentException($"Could not cast metric definition of type '{metricDefinition.ResourceType}' to {typeof(TMetricDefinition)}. Payload: {JsonConvert.SerializeObject(metricDefinition)}");
                }

                var azureMonitorClient = new AzureMonitorClient(AzureMetadata.TenantId, AzureMetadata.SubscriptionId, AzureCredentials.ApplicationId, AzureCredentials.Secret);
                var foundMetricValue   = await ScrapeResourceAsync(azureMonitorClient, castedMetricDefinition);

                var gauge = Metrics.CreateGauge(metricDefinition.Name, metricDefinition.Description);
                gauge.Set(foundMetricValue);
            }
            catch (Exception exception)
            {
                _exceptionTracker.Track(exception);
            }
        }
Exemplo n.º 15
0
        private bool SupportsRequestedDimensions(MetricDefinition definition, MetricFilter filter)
        {
            MetricDimension metric = filter.DimensionFilters.FirstOrDefault(df => string.Equals(df.Name, definition.Name.Value, StringComparison.OrdinalIgnoreCase));
            var             supportedDimensionNames  = definition.Dimensions.Select(dim => dim.Name);
            var             supportedDimensionValues = definition.Dimensions.ToDictionary(dim => dim.Name.Value, dim => dim.Values.Select(v => v.Value));

            // No dimensions specified for this metric
            if (metric == null || metric.Dimensions == null)
            {
                return(true);
            }

            foreach (MetricFilterDimension dimension in metric.Dimensions)
            {
                // find dimension in definition
                Dimension d = definition.Dimensions.FirstOrDefault(dim => string.Equals(dim.Name.Value, dimension.Name));

                // Dimension name does't show up in definition
                if (d == null)
                {
                    return(false);
                }

                // Requested dimension has any value that don't show up in the values list for the definiton
                if (dimension.Values.Any(value => !d.Values.Select(v => v.Value).Contains(value, StringComparer.OrdinalIgnoreCase)))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 16
0
        public IEnumerable <string> Validate(MetricDefinition metricDefinition)
        {
            Guard.NotNull(metricDefinition, nameof(metricDefinition));

            foreach (var resourceDefinition in metricDefinition.Resources.Cast <StorageQueueResourceDefinition>())
            {
                if (string.IsNullOrWhiteSpace(resourceDefinition.AccountName))
                {
                    yield return("No Azure Storage Account Name is configured");
                }

                if (string.IsNullOrWhiteSpace(resourceDefinition.QueueName))
                {
                    yield return("No Azure Storage Queue Name is configured");
                }

                var configuredSasToken = resourceDefinition.SasToken?.GetSecretValue();
                if (string.IsNullOrWhiteSpace(configuredSasToken))
                {
                    yield return("No Azure Storage SAS Token is configured");
                }

                if (!_validMetricNames.Any(metricName => metricName.Equals(metricDefinition.AzureMetricConfiguration.MetricName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    yield return($"Invalid metric name {metricDefinition.AzureMetricConfiguration.MetricName}");
                }
            }
        }
        public async Task Should_NOT_get_AssetDefinition()
        {
            //Arrange
            // Build the AssetDefinition
            var assetDefinition = new AssetDefinition()
            {
                Name = AssetDefinitionName,
                Url  = AssetDefinitionUrl,
            };

            var metricDefinitions = new MetricDefinition[]
            {
                new MetricDefinition {
                    Name = "Assay", Default = "0.9999", UnitOfMeasure = "Fineness", Description = "A Bar of Gold", SampleValue = "0.9999", Regex = @"^0([.,])\d+"
                },
                new MetricDefinition {
                    Name = "Bar Serial #", Description = "The serial number of the bar of gold", SampleValue = "123456", UnitOfMeasure = "Identifier"
                }
            };

            assetDefinition.MetricDefinitions = metricDefinitions;

            await InsertAsync(assetDefinition);

            var getAssetDefinitionRequest = new GetAssetDefinitionRequest
            {
                AssetDefinitionId = assetDefinition.AssetDefinitionId + 1
            };

            //Act
            GetAssetDefinitionResponse getAssetDefinitionResponse = await SendAsync(getAssetDefinitionRequest);

            //Assert
            getAssetDefinitionResponse.AssetDefinition.ShouldBeNull();
        }
        public void MetricCollectionFindByIndex()
        {
            MetricDefinition testMetricDefinition = GetTestMetricDefinition();
            IMetric          testMetric           = testMetricDefinition.Metrics[0];

            Assert.IsNotNull(testMetric);
        }
Exemplo n.º 19
0
        private static void AssertServiceBusQueueMetricDefinition(MetricDefinition deserializedServiceBusMetricDefinition, ServiceBusQueueMetricDefinitionV1 serviceBusMetricDefinition)
        {
            var deserializedResource = deserializedServiceBusMetricDefinition.Resources.Single() as ServiceBusQueueResourceDefinition;

            Assert.NotNull(deserializedResource);
            Assert.Equal(serviceBusMetricDefinition.Namespace, deserializedResource.Namespace);
            Assert.Equal(serviceBusMetricDefinition.QueueName, deserializedResource.QueueName);
        }
 public void MetricCollectionStringKeyMiss()
 {
     Assert.Throws <KeyNotFoundException>(() =>
     {
         MetricDefinition testMetricDefinition = GetTestMetricDefinition();
         IMetric testMetric = testMetricDefinition.Metrics["ThisKeyShouldNeverBeHere"];
     });
 }
 public void MetricCollectionOverrun()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         MetricDefinition testMetricDefinition = GetTestMetricDefinition();
         IMetric testMetric = testMetricDefinition.Metrics[-1];
     });
 }
        public void MetricCollectionFindByGuidKey()
        {
            MetricDefinition testMetricDefinition = GetTestMetricDefinition();
            IMetric          lookupMetric         = testMetricDefinition.Metrics[0]; //this test we already passed, so now we use it to do the rest of our tests.
            IMetric          testMetric           = testMetricDefinition.Metrics[lookupMetric.Id];

            Assert.IsNotNull(testMetric);
        }
 public void MetricCollectionGuidKeyMiss()
 {
     Assert.Throws <KeyNotFoundException>(() =>
     {
         MetricDefinition testMetricDefinition = GetTestMetricDefinition();
         IMetric testMetric = testMetricDefinition.Metrics[Guid.NewGuid()];
     });
 }
Exemplo n.º 24
0
        private IEnumerable <Metrics> GetManagerMetrics(MetricDefinition metricDefinition)
        {
            var managerMetrics = this.Client.Managers.ListMetrics(
                GenerateOdataFilterForMetric(metricDefinition),
                this.ResourceGroupName,
                this.ManagerName);

            return(managerMetrics);
        }
Exemplo n.º 25
0
        private void SanitizeStorageQueueDeclaration(MetricDefinition metricDefinition)
        {
            var storageQueueDeclaration = metricDefinition as StorageQueueMetricDefinition;

            if (storageQueueDeclaration != null && string.IsNullOrWhiteSpace(storageQueueDeclaration.SasToken.RawValue) == false)
            {
                storageQueueDeclaration.SasToken.RawValue = "***";
            }
        }
Exemplo n.º 26
0
        public void MetricDefinition_WithoutUnit_Returns_ValidJson()
        {
            MetricDefinition metricDefinition = new MetricDefinition("Time");

            string metricString = JsonConvert.SerializeObject(metricDefinition);

            Assert.Equal("{\"Name\":\"Time\",\"Unit\":\"None\"}", metricString);
            Assert.Empty(metricDefinition.Values);
        }
Exemplo n.º 27
0
        private string[] GetInstanceNames(MetricDefinition def)
        {
            if (!string.IsNullOrEmpty(def.InstanceFilter))
            {
                return(new string[] { def.InstanceFilter });
            }

            return(null);
        }
Exemplo n.º 28
0
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefinition metricDefinitionDefinition)
        {
            _logger.LogInformation("Scraping '{MetricName}' for resource type '{ResourceType}'", metricDefinitionDefinition.Name, metricDefinitionDefinition.ResourceType);

            var scraper = MetricScraperFactory.CreateScraper(metricDefinitionDefinition.ResourceType, azureMetadata, _logger, _exceptionTracker);
            int subscriptionReadLimit = await scraper.ScrapeAsync(metricDefinitionDefinition);

            HealthMonitor.Instance.setSubscriptionLimitCount(subscriptionReadLimit);
        }
        public void MetricDefinitionObjectLookup()
        {
            MetricDefinition lookupMetricDefinition = GetTestMetricDefinition();

            //look it up by GUID
            Assert.AreSame(lookupMetricDefinition, Log.Metrics[lookupMetricDefinition.Id], "Failed to find same object when looking by Id");
            Assert.AreSame(lookupMetricDefinition, Log.Metrics[lookupMetricDefinition.Name], "Failed to find same object when looking by Name");
            Assert.AreSame(lookupMetricDefinition, Log.Metrics[lookupMetricDefinition.MetricTypeName, lookupMetricDefinition.CategoryName, lookupMetricDefinition.CounterName], "Failed to find same object when looking by Key Components");
        }
        /// <summary>
        /// Initializes an new instance of the PSMetricDefinitionNoDetails class
        /// </summary>
        /// <param name="metricDefinition">The MetricDefinition</param>
        public PSMetricDefinitionNoDetails(MetricDefinition metricDefinition)
        {
            // Keep the original value (localized string, Dictionary, List) in the base
            base.Name = metricDefinition.Name;

            this.MetricAvailabilities = metricDefinition.MetricAvailabilities;
            this.Name = metricDefinition.Name == null ? null : metricDefinition.Name.Value;
            this.PrimaryAggregationType = metricDefinition.PrimaryAggregationType;
            this.Unit = metricDefinition.Unit;
        }
        public void MetricObjectLookup()
        {
            MetricDefinition lookupMetricDefinition = GetTestMetricDefinition();
            Metric           lookupMetric           = GetTestMetric();

            Assert.AreSame(lookupMetric, Log.Metrics.Metric(lookupMetric.Id), "Failed to find metric in Log.Metrics Metric cache");
            Assert.AreSame(lookupMetric, lookupMetricDefinition.Metrics[lookupMetric.Id], "Failed to find same object when looking by Id");
            Assert.AreSame(lookupMetric, lookupMetricDefinition.Metrics[lookupMetric.InstanceName], "Failed to find same object when looking by Instance Name");
            Assert.AreSame(lookupMetric, lookupMetricDefinition.Metrics[lookupMetric.Name], "Failed to find same object when looking by Full Name");
        }
 /// <summary>
 /// Initializes an new instance of the PSMetricDefinition class
 /// </summary>
 /// <param name="metricDefinition">The MetricDefinition</param>
 public PSMetricDefinition(MetricDefinition metricDefinition) : base(metricDefinition)
 {
     this.MetricAvailabilities = new PSAvailabilityCollection(metricDefinition.MetricAvailabilities);
 }
        private string[] GetInstanceNames(MetricDefinition def)
        {
            if (!string.IsNullOrEmpty(def.InstanceFilter))
            {
                return new string[] { def.InstanceFilter };
            }

            return null;
        }