From b9c4361598d20b11d24662c7eced93617725d61e Mon Sep 17 00:00:00 2001 From: Guy Fankam Date: Thu, 15 Aug 2024 15:17:31 -0400 Subject: [PATCH] Support backend circuit breakers and load balancers (closes #463). --- tools/code/common/Backend.cs | 104 +++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 5 deletions(-) diff --git a/tools/code/common/Backend.cs b/tools/code/common/Backend.cs index cd0c6f87..f277a257 100644 --- a/tools/code/common/Backend.cs +++ b/tools/code/common/Backend.cs @@ -129,6 +129,10 @@ public sealed record BackendDto public record BackendContract { + [JsonPropertyName("circuitBreaker")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public BackendCircuitBreaker? CircuitBreaker { get; init; } + [JsonPropertyName("credentials")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public BackendCredentialsContract? Credentials { get; init; } @@ -137,6 +141,10 @@ public record BackendContract [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string? Description { get; init; } + [JsonPropertyName("pool")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public Pool? Pool { get; init; } + [JsonPropertyName("properties")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public BackendProperties? Properties { get; init; } @@ -161,6 +169,10 @@ public record BackendContract [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public BackendTlsProperties? Tls { get; init; } + [JsonPropertyName("type")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string? Type { get; init; } + [JsonPropertyName("url")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] #pragma warning disable CA1056 // URI-like properties should not be strings @@ -168,6 +180,66 @@ public record BackendContract #pragma warning restore CA1056 // URI-like properties should not be strings } + public record BackendCircuitBreaker + { + [JsonPropertyName("rules")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public ImmutableArray? Rules { get; init; } + } + + public record CircuitBreakerRule + { + [JsonPropertyName("acceptRetryAfter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? AcceptRetryAfter { get; init; } + + [JsonPropertyName("failureCondition")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public CircuitBreakerFailureCondition? FailureCondition { get; init; } + + [JsonPropertyName("name")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string? Name { get; init; } + + [JsonPropertyName("tripDuration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string? TripDuration { get; init; } + } + + public record CircuitBreakerFailureCondition + { + [JsonPropertyName("count")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? Count { get; init; } + + [JsonPropertyName("errorReasons")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public ImmutableArray? ErrorReasons { get; init; } + + [JsonPropertyName("interval")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string? Interval { get; init; } + + [JsonPropertyName("percentage")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? Percentage { get; init; } + + [JsonPropertyName("statusCodeRanges")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public ImmutableArray? StatusCodeRanges { get; init; } + } + + public record FailureStatusCodeRange + { + [JsonPropertyName("max")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? Max { get; init; } + + [JsonPropertyName("min")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? Min { get; init; } + } + public record BackendCredentialsContract { [JsonPropertyName("authorization")] @@ -176,11 +248,11 @@ public record BackendCredentialsContract [JsonPropertyName("certificate")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public ImmutableList? Certificate { get; init; } + public ImmutableArray? Certificate { get; init; } [JsonPropertyName("certificateIds")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public ImmutableList? CertificateIds { get; init; } + public ImmutableArray? CertificateIds { get; init; } [JsonPropertyName("header")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -238,7 +310,7 @@ public record BackendServiceFabricClusterProperties [JsonPropertyName("managementEndpoints")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public ImmutableList? ManagementEndpoints { get; init; } + public ImmutableArray? ManagementEndpoints { get; init; } [JsonPropertyName("maxPartitionResolutionRetries")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -246,11 +318,33 @@ public record BackendServiceFabricClusterProperties [JsonPropertyName("serverCertificateThumbprints")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public ImmutableList? ServerCertificateThumbprints { get; init; } + public ImmutableArray? ServerCertificateThumbprints { get; init; } [JsonPropertyName("serverX509Names")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public ImmutableList? ServerX509Names { get; init; } + public ImmutableArray? ServerX509Names { get; init; } + } + + public record Pool + { + [JsonPropertyName("services")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public ImmutableArray? Services { get; init; } + } + + public record BackendPoolItem + { + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string? Id { get; init; } + + [JsonPropertyName("priority")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? Priority { get; init; } + + [JsonPropertyName("weight")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public int? Weight { get; init; } } public record BackendTlsProperties