Skip to content

Commit 6823a19

Browse files
authored
Fix workload group markdown formatting (#114)
1 parent ec25e7d commit 6823a19

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

KustoSchemaTools.Tests/Changes/ClusterChangesTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void GenerateChanges_WithWorkloadGroupDeletion_ShouldDetectDeletion()
219219
Assert.NotNull(deletionChange);
220220
Assert.Equal("test-group", deletionChange.Entity);
221221
Assert.Equal("workload_group", deletionChange.EntityType);
222-
Assert.Contains("Drop test-group", deletionChange.Markdown);
222+
Assert.Contains("Drop Workload Group test-group", deletionChange.Markdown);
223223
}
224224

225225
[Fact]
@@ -452,7 +452,7 @@ private WorkloadGroup CreateComplexWorkloadGroup(string name, long maxMemoryPerQ
452452
MaxExecutionTime = new PolicyValue<TimeSpan> { Value = maxExecutionTime, IsRelaxable = true },
453453
MaxResultRecords = new PolicyValue<long> { Value = 10000, IsRelaxable = false }
454454
},
455-
RequestRateLimitPolicies = new List<RequestRateLimitPolicy>
455+
RequestRateLimitPolicies = new PolicyList<RequestRateLimitPolicy>
456456
{
457457
new RequestRateLimitPolicy
458458
{

KustoSchemaTools/Changes/ClusterChanges.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public static ClusterChangeSet GenerateChanges(Cluster oldCluster, Cluster newCl
8282
{
8383
var oldValue = oldPolicy != null ? prop.GetValue(oldPolicy) : null;
8484
var newValue = prop.GetValue(newPolicy);
85-
8685
if (newValue != null && !object.Equals(oldValue, newValue))
8786
{
8887
var oldValueStr = oldValue?.ToString() ?? "Not Set";
@@ -156,7 +155,7 @@ private static void HandleWorkloadGroupChanges(Cluster oldCluster, Cluster newCl
156155

157156
// Replace the header in the deletion markdown
158157
var originalMarkdown = deletionChange.Markdown;
159-
var modifiedMarkdown = originalMarkdown.Replace($"## {workloadGroupName}", $"#### :heavy_minus_sign: Drop {workloadGroupName}");
158+
var modifiedMarkdown = originalMarkdown.Replace($"## {workloadGroupName}", $"### Drop Workload Group {workloadGroupName}");
160159
deletionChange.Markdown = modifiedMarkdown;
161160

162161
changeSet.Changes.Add(deletionChange);

KustoSchemaTools/Model/WorkloadGroup.cs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class WorkloadGroupPolicy : IEquatable<WorkloadGroupPolicy>
9494
public RequestLimitsPolicy? RequestLimitsPolicy { get; set; }
9595

9696
[JsonProperty("RequestRateLimitPolicies")]
97-
public List<RequestRateLimitPolicy>? RequestRateLimitPolicies { get; set; }
97+
public PolicyList<RequestRateLimitPolicy>? RequestRateLimitPolicies { get; set; }
9898

9999
[JsonProperty("RequestRateLimitsEnforcementPolicy")]
100100
public RequestRateLimitsEnforcementPolicy? RequestRateLimitsEnforcementPolicy { get; set; }
@@ -107,9 +107,7 @@ public bool Equals(WorkloadGroupPolicy? other)
107107
if (other is null) return false;
108108
if (ReferenceEquals(this, other)) return true;
109109
return EqualityComparer<RequestLimitsPolicy?>.Default.Equals(RequestLimitsPolicy, other.RequestLimitsPolicy) &&
110-
(RequestRateLimitPolicies == null && other.RequestRateLimitPolicies == null ||
111-
RequestRateLimitPolicies != null && other.RequestRateLimitPolicies != null &&
112-
RequestRateLimitPolicies.SequenceEqual(other.RequestRateLimitPolicies)) &&
110+
EqualityComparer<PolicyList<RequestRateLimitPolicy>?>.Default.Equals(RequestRateLimitPolicies, other.RequestRateLimitPolicies) &&
113111
EqualityComparer<RequestRateLimitsEnforcementPolicy?>.Default.Equals(RequestRateLimitsEnforcementPolicy, other.RequestRateLimitsEnforcementPolicy) &&
114112
EqualityComparer<QueryConsistencyPolicy?>.Default.Equals(QueryConsistencyPolicy, other.QueryConsistencyPolicy);
115113
}
@@ -120,15 +118,9 @@ public override int GetHashCode()
120118
{
121119
var hc = new HashCode();
122120
hc.Add(RequestLimitsPolicy);
121+
hc.Add(RequestRateLimitPolicies);
123122
hc.Add(RequestRateLimitsEnforcementPolicy);
124123
hc.Add(QueryConsistencyPolicy);
125-
if (RequestRateLimitPolicies != null)
126-
{
127-
foreach (var policy in RequestRateLimitPolicies)
128-
{
129-
hc.Add(policy);
130-
}
131-
}
132124
return hc.ToHashCode();
133125
}
134126

@@ -397,4 +389,42 @@ public override string ToString()
397389
});
398390
}
399391
}
392+
393+
public class PolicyList<T> : List<T> where T : IEquatable<T>
394+
{
395+
public override bool Equals(object? obj)
396+
{
397+
if (obj is not List<T> other)
398+
{
399+
return false;
400+
}
401+
if (Count != other.Count)
402+
{
403+
return false;
404+
}
405+
// Use HashSet for efficient, order-independent comparison
406+
return new HashSet<T>(this).SetEquals(other);
407+
}
408+
409+
public override int GetHashCode()
410+
{
411+
int hashCode = 0;
412+
// Order-independent hash code calculation
413+
foreach (T item in this.OrderBy(i => i.GetHashCode()))
414+
{
415+
// XORing hash codes is a common technique for order-independent hashing
416+
hashCode ^= item.GetHashCode();
417+
}
418+
return hashCode;
419+
}
420+
421+
public override string ToString()
422+
{
423+
return JsonConvert.SerializeObject(this, new JsonSerializerSettings
424+
{
425+
NullValueHandling = NullValueHandling.Ignore,
426+
Formatting = Formatting.None
427+
});
428+
}
429+
}
400430
}

0 commit comments

Comments
 (0)