Skip to content

Commit

Permalink
use different string matching
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfgo committed Sep 19, 2024
1 parent 3760629 commit 4853b3e
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,31 @@ public static class MetricResultExtension

public static string ParseResourceIdFromResultId(this MetricResult metricResult)
{
Match match = resourceIdRegex.Match(metricResult.Id);
if (!match.Success || string.IsNullOrEmpty(match.Groups[1].Value))
// 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);
}

private static string ExtractResourceId(string fullId)
{
// Find the index of the second occurrence of "/providers/"
int firstIndex = fullId.IndexOf("/providers/");
int secondIndex = fullId.IndexOf("/providers/", firstIndex + 1);

// If the second "/providers/" is found, slice the string up to that point
if (secondIndex != -1)
{
throw new InvalidOperationException($"The expected resource ID pattern was not found in the input string {metricResult.Id}");
return fullId.Substring(0, secondIndex);
}

string resourceId = match.Groups[1].Value;
return resourceId;
// If not found, return the full string
return fullId;
}

}
Expand Down

0 comments on commit 4853b3e

Please sign in to comment.