Skip to content

Commit

Permalink
fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfgo committed Sep 25, 2024
1 parent 8a0e380 commit d88c53b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private async Task ScrapeMetrics(IEnumerable<ScrapeDefinition<IAzureResourceDefi
Logger.LogInformation("Logging individual definitions batch: Azure Metric {AzureMetricName} and resource type {ResourceType}.", azureMetricName, resourceType);
foreach (ScrapeDefinition<IAzureResourceDefinition> definition in batchScrapeDefinition.ScrapeDefinitions)
{
Logger.LogInformation("ResourceID: {ResoureceID}, ResourceGroup: {ResourceGroup}, Prometheus metric name: {MetricName}, Batch Key: {BatchKey}", definition.Resource.ResourceName, definition.ResourceGroupName, definition.PrometheusMetricDefinition.Name, definition.buildPropertiesForBatch().BuildBatchHashKey());
Logger.LogInformation("ResourceID: {ResoureceID}, ResourceGroup: {ResourceGroup}, Prometheus metric name: {MetricName}, Batch Key: {BatchKey}", definition.Resource.ResourceName, definition.ResourceGroupName, definition.PrometheusMetricDefinition.Name, definition.BuildPropertiesForBatch().BuildBatchHashKey());
}
await ScheduleLimitedConcurrencyAsyncTask(tasks, () => ScrapeMetricBatched(batchScrapeDefinition), cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Promitor.Core.Scraping/AzureMonitorScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected override async Task<List<ScrapeResult>> BatchScrapeResourceAsync(strin
{
Logger.LogWarning("No metric information found for metric {MetricName} with dimensions {MetricDimensions}. Details: {Details}", metricsNotFoundException.Name, metricsNotFoundException.Dimensions, metricsNotFoundException.Details);

var measuredMetric = dimensionNames.Any()
var measuredMetric = dimensionNames.Count > 0
? MeasuredMetric.CreateForDimensions(dimensionNames)
: MeasuredMetric.CreateWithoutDimensions(null);
resourceIdTaggedMeasuredMetrics.Add(measuredMetric.WithResourceIdAssociation(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class AzureResourceDefinitionBatching
/// </summary>
public static List<BatchScrapeDefinition<IAzureResourceDefinition>> GroupScrapeDefinitions(IEnumerable<ScrapeDefinition<IAzureResourceDefinition>> allScrapeDefinitions, int maxBatchSize, CancellationToken cancellationToken)
{
return allScrapeDefinitions.GroupBy(def => def.buildPropertiesForBatch())
return allScrapeDefinitions.GroupBy(def => def.BuildPropertiesForBatch())
.ToDictionary(group => group.Key, group => group.ToList()) // first pass to build batches that could exceed max
.ToDictionary(group => group.Key, group => SplitScrapeDefinitionBatch(group.Value, maxBatchSize, cancellationToken)) // split to right-sized batches
.SelectMany(group => group.Value.Select(batch => new BatchScrapeDefinition<IAzureResourceDefinition>(group.Key, batch)))
Expand All @@ -29,7 +29,7 @@ public static List<BatchScrapeDefinition<IAzureResourceDefinition>> GroupScrapeD
/// </summary>
private static List<List<ScrapeDefinition<IAzureResourceDefinition>>> SplitScrapeDefinitionBatch(List<ScrapeDefinition<IAzureResourceDefinition>> batchToSplit, int maxBatchSize, CancellationToken cancellationToken)

Check warning on line 30 in src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[UnusedParameter.Local] Parameter 'cancellationToken' is never used" on /home/runner/work/promitor/promitor/src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs(30,1862)
{
int numNewGroups = (batchToSplit.Count - 1) / maxBatchSize + 1;
int numNewGroups = ((batchToSplit.Count - 1) / maxBatchSize) + 1;

return Enumerable.Range(0, numNewGroups)
.Select(i => batchToSplit.Skip(i * maxBatchSize).Take(maxBatchSize).ToList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public string ToUniqueStringRepresentation()
sb.Append(MetricName);
if (Dimension != null)
{
sb.Append("_");
sb.Append('_');
sb.Append(Dimension.Name);
}
else if (Dimensions != null)
{
foreach (var dimension in Dimensions)
{
sb.Append("_");
sb.Append('_');
sb.Append(dimension.Name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@ namespace Promitor.Core.Scraping.Configuration.Model.Metrics
/// 1. The same resource type
/// 2. The same Azure metric scrape target with identical dimensions
/// 3. The same time granularity
/// 4. The same filters
/// </summary>
public class BatchScrapeDefinition<TResourceDefinition> where TResourceDefinition : class, IAzureResourceDefinition
{
/// <summary>
/// Creates a new instance of the <see cref="ScrapeDefinition{TResourceDefinition}"/> class.
/// Creates a new instance of the <see cref="BatchScrapeDefinition{TResourceDefinition}"/> class.
/// </summary>
/// <param name="azureMetricConfiguration">Configuration about the Azure Monitor metric to scrape</param>
/// <param name="azureMetricConfiguration">Configuration about the Azure Monitor metric to scrape</param>
/// <param name="scraping">The scraping model.</param>
/// <param name="subscriptionId">Specify a subscription to scrape that defers from the default subscription.</param>
/// <param name="resourceGroupName">
/// The name of the resource group containing the resource to scrape. This should contain the global
/// resource group name if none is overridden at the resource level.
/// </param>
/// <param name="scrapeDefinitionBatchProperties">Shared Properties Among ScrapeDefinition's in the batch</param>
/// <param name="groupedScrapeDefinitions">Scape definitions in the batch</param>
public BatchScrapeDefinition(ScrapeDefinitionBatchProperties scrapeDefinitionBatchProperties, List<ScrapeDefinition<TResourceDefinition>> groupedScrapeDefinitions)
{
Guard.NotNull(groupedScrapeDefinitions, nameof(scrapeDefinitionBatchProperties));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ScrapeDefinition(
return AzureMetricConfiguration?.Aggregation?.Interval;
}

public ScrapeDefinitionBatchProperties buildPropertiesForBatch() {
public ScrapeDefinitionBatchProperties BuildPropertiesForBatch() {
return new ScrapeDefinitionBatchProperties(
this.AzureMetricConfiguration,
this.LogAnalyticsConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ namespace Promitor.Core.Scraping.Configuration.Model.Metrics
public class ScrapeDefinitionBatchProperties : IEquatable<ScrapeDefinitionBatchProperties>
{
/// <param name="azureMetricConfiguration">Configuration about the Azure Monitor metric to scrape</param>
/// <param name="logAnalyticsConfiguration">Configuration about the LogAnalytics resource to scrape</param>
/// <param name="prometheusMetricDefinition">The details of the prometheus metric that will be created.</param>
/// <param name="scraping">The scraping model.</param>
/// <param name="resource">The resource to scrape.</param>
/// <param name="resourceType">Resource type of the batch</param>
/// <param name="subscriptionId">Specify a subscription to scrape that defers from the default subscription.</param>
/// <param name="resourceGroupName">
/// The name of the resource group containing the resource to scrape. This should contain the global
/// resource group name if none is overridden at the resource level.
/// </param>
public ScrapeDefinitionBatchProperties(
AzureMetricConfiguration azureMetricConfiguration,
LogAnalyticsConfiguration logAnalyticsConfiguration,
Expand Down Expand Up @@ -61,9 +58,7 @@ public ScrapeDefinitionBatchProperties(
public Scraping Scraping { get; }

/// <summary>
/// The Azure subscription to get the metric from. This should be used instead of using
/// the SubscriptionId from <see cref="Resource"/> because this property will contain
/// the global subscription id if none is overridden at the resource level.
/// The Azure subscription to get the metric from.
/// </summary>
public string SubscriptionId { get; }

Expand Down Expand Up @@ -106,6 +101,5 @@ public bool Equals(ScrapeDefinitionBatchProperties obj)
ScrapeDefinitionBatchProperties other = obj;
return ResourceType == other.ResourceType && AzureMetricConfiguration.ToUniqueStringRepresentation() == other.AzureMetricConfiguration.ToUniqueStringRepresentation() && SubscriptionId == other.SubscriptionId && GetAggregationInterval().Equals(other.GetAggregationInterval());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,8 @@ namespace Promitor.Integrations.AzureMonitor.Extensions
public static class MetricResultExtension
{
// hacky to to get resource ID since it's not available directly through the SDK model
static string resourceIdPattern = @"^([\/]?subscriptions\/[^\/]+\/resourceGroups\/[^\/]+\/providers\/[^\/]+\/[^\/]+\/[^\/]+)";
static Regex resourceIdRegex = new Regex(resourceIdPattern, RegexOptions.Compiled);

public static string ParseResourceIdFromResultId(this MetricResult metricResult)
{
// Match match = resourceIdRegex.Match(metricResult.Id);
// if (!match.Success || string.IsNullOrEmpty(match.Groups[1].Value))
// {
// throw new InvalidOperationException($"The expected resource ID pattern was not found in the input string {metricResult.Id}");
// }

// string resourceId = match.Groups[1].Value;
// return resourceId;
return ExtractResourceId(metricResult.Id);
}

Expand All @@ -32,12 +21,11 @@ private static string ExtractResourceId(string fullId)
// If the second "/providers/" is found, slice the string up to that point
if (secondIndex != -1)
{
return fullId.Substring(0, secondIndex);
return fullId[..secondIndex];
}

// If not found, return the full string
return fullId;
}

}
}

0 comments on commit d88c53b

Please sign in to comment.