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 aggregationInterval = DetermineMetricAggregationInterval(metricDefinition); var aggregationType = metricDefinition.AzureMetricConfiguration.Aggregation.Type; var resourceGroupName = string.IsNullOrEmpty(metricDefinition.ResourceGroupName) ? AzureMetadata.ResourceGroupName : metricDefinition.ResourceGroupName; var foundMetricValue = await ScrapeResourceAsync(AzureMetadata.SubscriptionId, resourceGroupName, castedMetricDefinition, aggregationType, aggregationInterval); _logger.LogInformation("Found value '{MetricValue}' for metric '{MetricName}' with aggregation interval '{AggregationInterval}'", foundMetricValue, metricDefinition.Name, aggregationInterval); var metricsTimestampFeatureFlag = FeatureFlag.IsActive("METRICSTIMESTAMP", defaultFlagState: true); var gauge = Metrics.CreateGauge(metricDefinition.Name, metricDefinition.Description, includeTimestamp: metricsTimestampFeatureFlag); gauge.Set(foundMetricValue); } catch (Exception exception) { _exceptionTracker.Track(exception); } }
public void FeatureFlag_FeatureIsNotConfigured_ReturnsOnByDefault() { // Act var flagStatus = FeatureFlag.IsActive("TestFlag"); // Assert Assert.True(flagStatus); }
/// <summary> /// Sets a new value for a measurement on a gauge /// </summary> /// <param name="name">Name of the metric</param> /// <param name="description">Description of the metric</param> /// <param name="value">New measured value</param> /// <param name="labels">Labels that are applicable for this measurement</param> public void SetGaugeMeasurement(string name, string description, double value, Dictionary <string, string> labels) { var metricsTimestampFeatureFlag = FeatureFlag.IsActive(FeatureFlag.Names.MetricsTimestamp); var gauge = Prometheus.Client.Metrics.CreateGauge($"promitor_{name}", help: description, includeTimestamp: metricsTimestampFeatureFlag, labelNames: labels.Keys.ToArray()); gauge.WithLabels(labels.Values.ToArray()).Set(value); }
public void FeatureFlag_FeatureIsNotConfiguredButDefaultStateIsOff_Returns0ff() { // Arrange const bool defaultFlagState = false; // Act var flagStatus = FeatureFlag.IsActive("TestFlag", defaultFlagState: defaultFlagState); // Assert Assert.False(flagStatus); }
public void FeatureFlag_FeatureIsConfiguredToBeOff_ReturnsOff() { // Arrange const bool flagState = false; Environment.SetEnvironmentVariable("PROMITOR_FEATURE_TestFlag", flagState.ToString()); // Act var flagStatus = FeatureFlag.IsActive("TestFlag"); // Assert Assert.False(flagStatus); }