Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New array initializer syntax #2115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void ConfigureServices(IServiceCollection services)
healthQuery: "SELECT 1;",
name: "sql",
failureStatus: HealthStatus.Degraded,
tags: new string[] { "db", "sql", "sqlserver" });
tags: ["db", "sql", "sqlserver"]);
}
```

Expand Down
6 changes: 3 additions & 3 deletions samples/HealthChecks.UI.Branding/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void ConfigureServices(IServiceCollection services)
services
//.AddDemoAuthentication()
.AddHealthChecks()
.AddProcessAllocatedMemoryHealthCheck(maximumMegabytesAllocated: 100, tags: new[] { "process", "memory" })
.AddCheck<RandomHealthCheck>("random1", tags: new[] { "random" })
.AddCheck<RandomHealthCheck>("random2", tags: new[] { "random" })
.AddProcessAllocatedMemoryHealthCheck(maximumMegabytesAllocated: 100, tags: ["process", "memory"])
.AddCheck<RandomHealthCheck>("random1", tags: ["random"])
.AddCheck<RandomHealthCheck>("random2", tags: ["random"])
.Services
.AddHealthChecksUI(setupSettings: setup =>
{
Expand Down
2 changes: 1 addition & 1 deletion samples/HealthChecks.UI.StorageProviders/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ConfigureServices(IServiceCollection services)
services
.AddRouting()
.AddHealthChecks()
.AddProcessAllocatedMemoryHealthCheck(maximumMegabytesAllocated: 200, tags: new[] { "memory" })
.AddProcessAllocatedMemoryHealthCheck(maximumMegabytesAllocated: 200, tags: ["memory"])
.AddCheck(name: "random", () => DateTime.UtcNow.Second % 2 == 0 ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy())
.Services
.AddHealthChecksUI(setup =>
Expand Down
8 changes: 4 additions & 4 deletions src/HealthChecks.Aws.Sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void ConfigureServices(IServiceCollection services)
.AddHealthChecks()
.AddSnsSubscriptions(options =>
{
options.AddTopicAndSubscriptions("topicName", new string[] { "subscription1-arn", "subscription2-arn" });
options.AddTopicAndSubscriptions("topicName", ["subscription1-arn", "subscription2-arn"]);
});
}
```
Expand All @@ -94,7 +94,7 @@ public void ConfigureServices(IServiceCollection services)
.AddHealthChecks()
.AddSnsSubscriptions(options =>
{
options.AddTopicAndSubscriptions("topicName", new string[] { "subscription1-arn", "subscription2-arn" });
options.AddTopicAndSubscriptions("topicName", ["subscription1-arn", "subscription2-arn"]);
options.Credentials = new BasicAWSCredentials("access-key", "secret-key");
});
}
Expand All @@ -109,7 +109,7 @@ public void ConfigureServices(IServiceCollection services)
.AddHealthChecks()
.AddSnsSubscriptions(options =>
{
options.AddTopicAndSubscriptions("topicName", new string[] { "subscription1-arn", "subscription2-arn" });
options.AddTopicAndSubscriptions("topicName", ["subscription1-arn", "subscription2-arn"]);
options.RegionEndpoint = RegionEndpoint.EUCentral1;
});
}
Expand All @@ -124,7 +124,7 @@ public void ConfigureServices(IServiceCollection services)
.AddHealthChecks()
.AddSnsSubscriptions(options =>
{
options.AddTopicAndSubscriptions("topicName", new string[] { "subscription1-arn", "subscription2-arn" });
options.AddTopicAndSubscriptions("topicName", ["subscription1-arn", "subscription2-arn"]);
options.Credentials = new BasicAWSCredentials("access-key", "secret-key");
options.RegionEndpoint = RegionEndpoint.EUCentral1;
});
Expand Down
2 changes: 1 addition & 1 deletion src/HealthChecks.Aws.Sns/SnsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SnsOptions AddTopicAndSubscriptions(string topicName, IEnumerable<string>
{
if (!TopicsAndSubscriptions.TryGetValue(topicName, out var subs))
{
TopicsAndSubscriptions.Add(topicName, subs = new List<string>(subscriptions ?? Array.Empty<string>()));
TopicsAndSubscriptions.Add(topicName, subs = new List<string>(subscriptions ?? []));
}
else if (subscriptions != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public class AzureApplicationInsightsHealthCheck : IHealthCheck
{
// from https://docs.microsoft.com/en-us/azure/azure-monitor/app/ip-addresses#outgoing-ports
private readonly string[] _appInsightsUrls =
{
[
"https://dc.applicationinsights.azure.com",
"https://dc.applicationinsights.microsoft.com",
"https://dc.services.visualstudio.com"
};
];
private readonly string _instrumentationKey;

private readonly IHttpClientFactory _httpClientFactory;
Expand Down
4 changes: 2 additions & 2 deletions src/HealthChecks.AzureDigitalTwin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ConfigureServices(IServiceCollection services)
"MyDigitalTwinClientSecret",
"TenantId",
"https://my-awesome-dt-host",
new string[] { "my:dt:definition_a;1", "my:dt:definition_b;1", "my:dt:definition_c;1" })
["my:dt:definition_a;1", "my:dt:definition_b;1", "my:dt:definition_c;1"])
}
```

Expand All @@ -112,7 +112,7 @@ public void ConfigureServices(IServiceCollection services)
.AddHealthChecks()
.AddAzureDigitalTwinModels(
myCredentials,
new string[] { "my:dt:definition_a;1", "my:dt:definition_b;1", "my:dt:definition_c;1" },
["my:dt:definition_a;1", "my:dt:definition_b;1", "my:dt:definition_c;1"],
failureStatus: HealthStatus.Degraded)
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/HealthChecks.Network/FtpHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private WebRequest CreateFtpWebRequest(string host, bool createFile = false, Net
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

using var stream = ftpRequest.GetRequestStream();
stream.Write(new byte[] { 0x0 }, 0, 1);
stream.Write([0x0], 0, 1);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/HealthChecks.Network/SftpHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, Canc
{
if (item.FileCreationOptions.createFile)
{
using var stream = new MemoryStream(new byte[] { 0x0 }, 0, 1);
using var stream = new MemoryStream([0x0], 0, 1);
sftpClient.UploadFile(stream, item.FileCreationOptions.remoteFilePath);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/HealthChecks.OpenIdConnectServer/OidcConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ internal class OidcConstants

internal const string ALGORITHMS_SUPPORTED = "id_token_signing_alg_values_supported";

internal static string[] REQUIRED_RESPONSE_TYPES => new[] { "code", "id_token" };
internal static string[] REQUIRED_RESPONSE_TYPES => ["code", "id_token"];

internal static string[] REQUIRED_COMBINED_RESPONSE_TYPES => new[] { "token id_token", "id_token token" };
internal static string[] REQUIRED_COMBINED_RESPONSE_TYPES => ["token id_token", "id_token token"];

internal static string[] REQUIRED_SUBJECT_TYPES => new[] { "pairwise", "public" };
internal static string[] REQUIRED_SUBJECT_TYPES => ["pairwise", "public"];

internal static string[] REQUIRED_ALGORITHMS => new[] { "RS256" };
internal static string[] REQUIRED_ALGORITHMS => ["RS256"];
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ internal LivenessPrometheusMetrics()
_healthChecksResult = factory.CreateGauge("healthcheck",
"Shows raw health check status (0 = Unhealthy, 1 = Degraded, 2 = Healthy)", new GaugeConfiguration
{
LabelNames = new[] { HEALTH_CHECK_LABEL_NAME },
LabelNames = [HEALTH_CHECK_LABEL_NAME],
SuppressInitialValue = false
});

_healthChecksDuration = factory.CreateGauge("healthcheck_duration_seconds",
"Shows duration of the health check execution in seconds",
new GaugeConfiguration
{
LabelNames = new[] { HEALTH_CHECK_LABEL_NAME },
LabelNames = [HEALTH_CHECK_LABEL_NAME],
SuppressInitialValue = false
});
}
Expand Down
7 changes: 2 additions & 5 deletions src/HealthChecks.Publisher.Datadog/DatadogPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DatadogPublisher(IDogStatsd dogStatsd, string serviceCheckName, string[]?
{
_dogStatsd = Guard.ThrowIfNull(dogStatsd);
_serviceCheckName = Guard.ThrowIfNull(serviceCheckName);
_defaultTags = defaultTags ?? Array.Empty<string>();
_defaultTags = defaultTags ?? [];
}

public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
Expand Down Expand Up @@ -43,10 +43,7 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke
break;
}

var tags = _defaultTags.Concat(new[]
{
$"check:{key}"
}).ToArray();
var tags = _defaultTags.Concat([$"check:{key}"]).ToArray();

var message = entry.Description ?? entry.Status.ToString();
_dogStatsd.ServiceCheck(_serviceCheckName, dataDogStatus, null, Environment.MachineName, tags, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ internal LivenessPrometheusMetrics()
_healthChecksResult = factory.CreateGauge("healthcheck",
"Shows raw health check status (0 = Unhealthy, 1 = Degraded, 2 = Healthy)", new GaugeConfiguration
{
LabelNames = new[] { HEALTH_CHECK_LABEL_NAME },
LabelNames = [HEALTH_CHECK_LABEL_NAME],
SuppressInitialValue = false
});

_healthChecksDuration = factory.CreateGauge("healthcheck_duration_seconds",
"Shows duration of the health check execution in seconds",
new GaugeConfiguration
{
LabelNames = new[] { HEALTH_CHECK_LABEL_NAME },
LabelNames = [HEALTH_CHECK_LABEL_NAME],
SuppressInitialValue = false
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/HealthChecks.Publisher.Seq/SeqPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public async Task PublishAsync(HealthReport report, CancellationToken cancellati

var events = new RawEvents
{
Events = new RawEvent[]
{
Events =
[
new RawEvent
{
Timestamp = DateTimeOffset.UtcNow,
Expand All @@ -54,7 +54,7 @@ public async Task PublishAsync(HealthReport report, CancellationToken cancellati
{ "RawReport" , JsonSerializer.Serialize(report)}
}
}
}
]
};

_options.Configure?.Invoke(events);
Expand Down
2 changes: 1 addition & 1 deletion src/HealthChecks.UI.Client/UIResponseWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class UIResponseWriter
{
private const string DEFAULT_CONTENT_TYPE = "application/json";

private static readonly byte[] _emptyResponse = new byte[] { (byte)'{', (byte)'}' };
private static readonly byte[] _emptyResponse = [(byte)'{', (byte)'}'];
private static readonly Lazy<JsonSerializerOptions> _options = new(CreateJsonOptions);

#pragma warning disable IDE1006 // Naming Styles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task be_healthy_if_arangodb_is_available()
Database = "_system",
UserName = "root",
Password = "strongArangoDbPassword"
}, tags: new string[] { "arangodb" });
}, tags: ["arangodb"]);
})
.Configure(app =>
{
Expand Down Expand Up @@ -47,15 +47,15 @@ public async Task be_healthy_if_multiple_arango_are_available()
Database = "_system",
UserName = "root",
Password = "strongArangoDbPassword"
}, tags: new string[] { "arango" }, name: "1")
}, tags: ["arango"], name: "1")
.AddArangoDb(_ => new ArangoDbOptions
{
HostUri = "http://localhost:8529/",
Database = "_system",
UserName = "root",
Password = "strongArangoDbPassword",
IsGenerateJwtTokenBasedOnUserNameAndPassword = true
}, tags: new string[] { "arango" }, name: "2");
}, tags: ["arango"], name: "2");
})
.Configure(app =>
{
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task be_unhealthy_if_arango_is_not_available()
Database = "_system",
UserName = "root",
Password = "invalid password"
}, tags: new string[] { "arango" });
}, tags: ["arango"]);
})
.Configure(app =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void add_health_check_with_topics_and_subscriptions_when_properly_configu
.AddSnsTopicsAndSubscriptions(setup =>
{
setup.Credentials = new BasicAWSCredentials("access-key", "secret-key");
setup.AddTopicAndSubscriptions("topic1", new string[] { "subscription1-arn", "subscription2-arn" });
setup.AddTopicAndSubscriptions("topic1", ["subscription1-arn", "subscription2-arn"]);
});

using var serviceProvider = services.BuildServiceProvider();
Expand Down Expand Up @@ -76,7 +76,7 @@ public void add_health_check_with_topics_and_subscriptions_assumerole_when_prope
.AddSnsTopicsAndSubscriptions(setup =>
{
setup.Credentials = new AssumeRoleAWSCredentials(null, "role-arn", "session-name");
setup.AddTopicAndSubscriptions("topic1", new string[] { "subscription1-arn", "subscription2-arn" });
setup.AddTopicAndSubscriptions("topic1", ["subscription1-arn", "subscription2-arn"]);
});

using var serviceProvider = services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task return_healthy_when_only_checking_healthy_service()

_tableServiceClient
.QueryAsync(filter: "false", cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<TableItem>.FromPages(Array.Empty<Page<TableItem>>()));
.Returns(AsyncPageable<TableItem>.FromPages([]));

var actual = await _healthCheck.CheckHealthAsync(_context, tokenSource.Token);

Expand All @@ -61,11 +61,11 @@ public async Task return_healthy_when_checking_healthy_service_and_table()

_tableServiceClient
.QueryAsync(filter: "false", cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<TableItem>.FromPages(Array.Empty<Page<TableItem>>()));
.Returns(AsyncPageable<TableItem>.FromPages([]));

_tableClient
.QueryAsync<TableEntity>(filter: "false", cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<TableEntity>.FromPages(Array.Empty<Page<TableEntity>>()));
.Returns(AsyncPageable<TableEntity>.FromPages([]));

_options.TableName = TableName;
var actual = await _healthCheck.CheckHealthAsync(_context, tokenSource.Token);
Expand Down Expand Up @@ -138,7 +138,7 @@ public async Task return_unhealthy_when_checking_unhealthy_container()

_tableServiceClient
.QueryAsync(filter: "false", cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<TableItem>.FromPages(Array.Empty<Page<TableItem>>()));
.Returns(AsyncPageable<TableItem>.FromPages([]));

_tableClient
.QueryAsync<TableEntity>(filter: "false", cancellationToken: tokenSource.Token)
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task return_unhealthy_when_invoked_from_healthcheckservice()

_tableServiceClient
.QueryAsync(filter: "false", cancellationToken: Arg.Any<CancellationToken>())
.Returns(AsyncPageable<TableItem>.FromPages(Array.Empty<Page<TableItem>>()));
.Returns(AsyncPageable<TableItem>.FromPages([]));

_tableClient
.QueryAsync<TableEntity>(filter: "false", cancellationToken: Arg.Any<CancellationToken>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task return_healthy_when_only_checking_healthy_service()

_blobServiceClient
.GetBlobContainersAsync(cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<BlobContainerItem>.FromPages(Array.Empty<Page<BlobContainerItem>>()));
.Returns(AsyncPageable<BlobContainerItem>.FromPages([]));

var actual = await _healthCheck.CheckHealthAsync(_context, tokenSource.Token);

Expand All @@ -61,7 +61,7 @@ public async Task return_healthy_when_checking_healthy_service_and_container()

_blobServiceClient
.GetBlobContainersAsync(cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<BlobContainerItem>.FromPages(new[] { Substitute.For<Page<BlobContainerItem>>() }));
.Returns(AsyncPageable<BlobContainerItem>.FromPages([Substitute.For<Page<BlobContainerItem>>()]));

_blobContainerClient
.GetPropertiesAsync(conditions: null, cancellationToken: tokenSource.Token)
Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task return_unhealthy_when_checking_unhealthy_container()

_blobServiceClient
.GetBlobContainersAsync(cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<BlobContainerItem>.FromPages(new[] { Substitute.For<Page<BlobContainerItem>>() }));
.Returns(AsyncPageable<BlobContainerItem>.FromPages([Substitute.For<Page<BlobContainerItem>>()]));

_blobContainerClient
.GetPropertiesAsync(conditions: null, cancellationToken: tokenSource.Token)
Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task return_unhealthy_when_invoked_from_healthcheckservice()

_blobServiceClient
.GetBlobContainersAsync(cancellationToken: Arg.Any<CancellationToken>())
.Returns(AsyncPageable<BlobContainerItem>.FromPages(new[] { Substitute.For<Page<BlobContainerItem>>() }));
.Returns(AsyncPageable<BlobContainerItem>.FromPages([Substitute.For<Page<BlobContainerItem>>()]));

_blobContainerClient
.GetPropertiesAsync(conditions: null, cancellationToken: Arg.Any<CancellationToken>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task return_healthy_when_only_checking_healthy_service()

_shareServiceClient
.GetSharesAsync(cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<ShareItem>.FromPages(Array.Empty<Page<ShareItem>>()));
.Returns(AsyncPageable<ShareItem>.FromPages([]));

var actual = await _healthCheck.CheckHealthAsync(_context, tokenSource.Token);

Expand All @@ -61,7 +61,7 @@ public async Task return_healthy_when_checking_healthy_service_and_share()

_shareServiceClient
.GetSharesAsync(cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<ShareItem>.FromPages(new[] { Substitute.For<Page<ShareItem>>() }));
.Returns(AsyncPageable<ShareItem>.FromPages([Substitute.For<Page<ShareItem>>()]));

_shareClient
.GetPropertiesAsync(tokenSource.Token)
Expand Down Expand Up @@ -143,7 +143,7 @@ public async Task return_unhealthy_when_checking_unhealthy_share()

_shareServiceClient
.GetSharesAsync(cancellationToken: tokenSource.Token)
.Returns(AsyncPageable<ShareItem>.FromPages(new[] { Substitute.For<Page<ShareItem>>() }));
.Returns(AsyncPageable<ShareItem>.FromPages([Substitute.For<Page<ShareItem>>()]));

_shareClient
.GetPropertiesAsync(tokenSource.Token)
Expand Down Expand Up @@ -178,7 +178,7 @@ public async Task return_unhealthy_when_invoked_from_healthcheckservice()

_shareServiceClient
.GetSharesAsync(cancellationToken: Arg.Any<CancellationToken>())
.Returns(AsyncPageable<ShareItem>.FromPages(new[] { Substitute.For<Page<ShareItem>>() }));
.Returns(AsyncPageable<ShareItem>.FromPages([Substitute.For<Page<ShareItem>>()]));

_shareClient
.GetPropertiesAsync(Arg.Any<CancellationToken>())
Expand Down
Loading
Loading