Skip to content

Commit

Permalink
fix: Provide case invarient lookups for resource group filtering (#1498)
Browse files Browse the repository at this point in the history
* Provide case invarient lookups for resource group filtering #1492

Signed-off-by: Tom Kerkhove <kerkhove.tom@gmail.com>

* Update changelog

Signed-off-by: Tom Kerkhove <kerkhove.tom@gmail.com>

* Revert

Signed-off-by: Tom Kerkhove <kerkhove.tom@gmail.com>

* Fix bad changelog

Signed-off-by: Tom Kerkhove <kerkhove.tom@gmail.com>
  • Loading branch information
tomkerkhove authored Feb 8, 2021
1 parent 69ebb6e commit 403426c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/content/experimental/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ version:
- {{% tag added %}} Support for discovering Azure Front Door resources ([docs](https://promitor.io/configuration/v2.x/metrics/front-door)
| [#343](https://github.com/tomkerkhove/promitor/issues/343))
- {{% tag changed %}} Provide better usability in terms of startup and configuration insights ([#1474](https://github.com/tomkerkhove/promitor/issues/1474))
- {{% tag fixed %}} Provide case-invarient lookups for resource group filtering ([#1492](https://github.com/tomkerkhove/promitor/issues/1492))
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ resourceDiscoveryGroups:
regions:
- northeurope
- westeurope
- name: web-apps-filtered
- name: web-apps-in-resource-group
type: WebApp
criteria:
include:
Expand All @@ -86,6 +86,12 @@ resourceDiscoveryGroups:
include:
resourceGroups:
- promitor-testing-resource-discovery-eu
- name: one-resource-group-scenario-wiht-other-casing
type: LogicApp
criteria:
include:
resourceGroups:
- PROMITOR-testing-resource-discovery-eu
- name: two-resource-group-scenario
type: LogicApp
criteria:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public GraphQueryBuilder(string[] resourceTypes)

_queryBuilder = new StringBuilder();
_queryBuilder.AppendLine("Resources");
_queryBuilder.AppendLine($"| where type == tolower('{resourceTypes.First()}')");
_queryBuilder.AppendLine($"| where type =~ '{resourceTypes.First()}'");

foreach (var resourceType in resourceTypes.Skip(1))
{
_queryBuilder.AppendLine($" or type == '{resourceType}'");
_queryBuilder.AppendLine($" or type =~ '{resourceType}'");
}
}

Expand Down Expand Up @@ -145,10 +145,10 @@ private void FilterByField(string fieldName, List<string> allowedValues)
_queryBuilder.Append("| where ");
for (int counter = 0; counter < allowedValues.Count - 1; counter++)
{
_queryBuilder.Append($"{fieldName} == '{allowedValues[counter]}' or ");
_queryBuilder.Append($"{fieldName} =~ '{allowedValues[counter]}' or ");
}

_queryBuilder.AppendLine($"{fieldName} == '{allowedValues.Last()}'");
_queryBuilder.AppendLine($"{fieldName} =~ '{allowedValues.Last()}'");
}

private void FilterByTags(Dictionary<string,string> allowedTags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ public async Task ResourceDiscovery_GetWithFilterOnOneResourceGroup_ReturnsExpec
Assert.Equal(expectedResourceCount, resources.Count);
}

[Fact]
public async Task ResourceDiscovery_GetWithFilterOnOneResourceGroupWithDifferentCasing_ReturnsExpectedAmount()
{
// Arrange
const string resourceDiscoveryGroupName = "one-resource-group-scenario-wiht-other-casing";
const int expectedResourceCount = 3;
var resourceDiscoveryClient = new ResourceDiscoveryClient(Configuration, Logger);

// Act
var response = await resourceDiscoveryClient.GetDiscoveredResourcesAsync(resourceDiscoveryGroupName);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var rawResponseBody = await response.Content.ReadAsStringAsync();
Assert.NotEmpty(rawResponseBody);
var resources = JsonConvert.DeserializeObject<List<Resource>>(rawResponseBody);
Assert.NotNull(resources);
Assert.Equal(expectedResourceCount, resources.Count);
}

[Fact]
public async Task ResourceDiscovery_GetWithFilterOnTwoResourceGroups_ReturnsExpectedAmount()
{
Expand Down

0 comments on commit 403426c

Please sign in to comment.