Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions KustoSchemaTools.Tests/Changes/ClusterChangesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void GenerateChanges_WithWorkloadGroupDeletion_ShouldDetectDeletion()
Assert.NotNull(deletionChange);
Assert.Equal("test-group", deletionChange.Entity);
Assert.Equal("workload_group", deletionChange.EntityType);
Assert.Contains("Drop test-group", deletionChange.Markdown);
Assert.Contains("Drop Workload Group test-group", deletionChange.Markdown);
}

[Fact]
Expand Down Expand Up @@ -452,7 +452,7 @@ private WorkloadGroup CreateComplexWorkloadGroup(string name, long maxMemoryPerQ
MaxExecutionTime = new PolicyValue<TimeSpan> { Value = maxExecutionTime, IsRelaxable = true },
MaxResultRecords = new PolicyValue<long> { Value = 10000, IsRelaxable = false }
},
RequestRateLimitPolicies = new List<RequestRateLimitPolicy>
RequestRateLimitPolicies = new PolicyList<RequestRateLimitPolicy>
{
new RequestRateLimitPolicy
{
Expand Down
3 changes: 1 addition & 2 deletions KustoSchemaTools/Changes/ClusterChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public static ClusterChangeSet GenerateChanges(Cluster oldCluster, Cluster newCl
{
var oldValue = oldPolicy != null ? prop.GetValue(oldPolicy) : null;
var newValue = prop.GetValue(newPolicy);

if (newValue != null && !object.Equals(oldValue, newValue))
{
var oldValueStr = oldValue?.ToString() ?? "Not Set";
Expand Down Expand Up @@ -156,7 +155,7 @@ private static void HandleWorkloadGroupChanges(Cluster oldCluster, Cluster newCl

// Replace the header in the deletion markdown
var originalMarkdown = deletionChange.Markdown;
var modifiedMarkdown = originalMarkdown.Replace($"## {workloadGroupName}", $"#### :heavy_minus_sign: Drop {workloadGroupName}");
var modifiedMarkdown = originalMarkdown.Replace($"## {workloadGroupName}", $"### Drop Workload Group {workloadGroupName}");
deletionChange.Markdown = modifiedMarkdown;

changeSet.Changes.Add(deletionChange);
Expand Down
52 changes: 41 additions & 11 deletions KustoSchemaTools/Model/WorkloadGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class WorkloadGroupPolicy : IEquatable<WorkloadGroupPolicy>
public RequestLimitsPolicy? RequestLimitsPolicy { get; set; }

[JsonProperty("RequestRateLimitPolicies")]
public List<RequestRateLimitPolicy>? RequestRateLimitPolicies { get; set; }
public PolicyList<RequestRateLimitPolicy>? RequestRateLimitPolicies { get; set; }

[JsonProperty("RequestRateLimitsEnforcementPolicy")]
public RequestRateLimitsEnforcementPolicy? RequestRateLimitsEnforcementPolicy { get; set; }
Expand All @@ -107,9 +107,7 @@ public bool Equals(WorkloadGroupPolicy? other)
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;
return EqualityComparer<RequestLimitsPolicy?>.Default.Equals(RequestLimitsPolicy, other.RequestLimitsPolicy) &&
(RequestRateLimitPolicies == null && other.RequestRateLimitPolicies == null ||
RequestRateLimitPolicies != null && other.RequestRateLimitPolicies != null &&
RequestRateLimitPolicies.SequenceEqual(other.RequestRateLimitPolicies)) &&
EqualityComparer<PolicyList<RequestRateLimitPolicy>?>.Default.Equals(RequestRateLimitPolicies, other.RequestRateLimitPolicies) &&
EqualityComparer<RequestRateLimitsEnforcementPolicy?>.Default.Equals(RequestRateLimitsEnforcementPolicy, other.RequestRateLimitsEnforcementPolicy) &&
EqualityComparer<QueryConsistencyPolicy?>.Default.Equals(QueryConsistencyPolicy, other.QueryConsistencyPolicy);
}
Expand All @@ -120,15 +118,9 @@ public override int GetHashCode()
{
var hc = new HashCode();
hc.Add(RequestLimitsPolicy);
hc.Add(RequestRateLimitPolicies);
hc.Add(RequestRateLimitsEnforcementPolicy);
hc.Add(QueryConsistencyPolicy);
if (RequestRateLimitPolicies != null)
{
foreach (var policy in RequestRateLimitPolicies)
{
hc.Add(policy);
}
}
return hc.ToHashCode();
}

Expand Down Expand Up @@ -397,4 +389,42 @@ public override string ToString()
});
}
}

public class PolicyList<T> : List<T> where T : IEquatable<T>
{
public override bool Equals(object? obj)
{
if (obj is not List<T> other)
{
return false;
}
if (Count != other.Count)
{
return false;
}
// Use HashSet for efficient, order-independent comparison
return new HashSet<T>(this).SetEquals(other);
}

public override int GetHashCode()
{
int hashCode = 0;
// Order-independent hash code calculation
foreach (T item in this.OrderBy(i => i.GetHashCode()))
{
// XORing hash codes is a common technique for order-independent hashing
hashCode ^= item.GetHashCode();
}
return hashCode;
}

public override string ToString()
{
return JsonConvert.SerializeObject(this, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.None
});
}
}
}
Loading