Skip to content

Commit

Permalink
Merge pull request #502 from radixdlt/release/babylon
Browse files Browse the repository at this point in the history
Release/babylon -> main
  • Loading branch information
krzlabrdx authored Sep 27, 2023
2 parents 78da411 + 850d927 commit a79a6ae
Show file tree
Hide file tree
Showing 72 changed files with 669 additions and 163 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ dotnet_diagnostic.SA1024.severity = none # SA1024ColonsMustBeSpacedCorrectly - b
dotnet_diagnostic.SA1600.severity = none # SA1600ElementsMustBeDocumented - Duplicates CS1591 - let's just use CS1591 instead
dotnet_diagnostic.SA1615.severity = none # SA1615ElementReturnValueMustBeDocumented
dotnet_diagnostic.SA1611.severity = none # SA1611ElementParametersMustBeDocumented
dotnet_diagnostic.SA1618.severity = none # SA1618GenericTypeParametersMustBeDocumented
dotnet_diagnostic.SA1602.severity = none # SA1602EnumerationItemsMustBeDocumented
dotnet_diagnostic.SA1601.severity = none # SA1601PartialElementsMustBeDocumented

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ jobs:
runs-on: ubuntu-latest
needs:
- setup-tags
- docker-database-migrations-dockerhub
- docker-data-aggregator-dockerhub
- docker-gateway-api-dockerhub
- join-gateway-images
- join-aggregator-images
- join-migrations-images
permissions:
id-token: write
pull-requests: read
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
## Next release (name TBC)
## 1.0.0 - Babylon Launch
Release Date: _unreleased_

### Breaking changes
_None_

### What’s new?
_N/A_
- log warning if sql query takes longer than configured threshold (default to 250ms) for both entity framework and dapper queries.
- gather execution time metrics for all sql queries (both entity framework and dapper).

## 1.0.0-rc3 - Babylon Launch (Release Candidate 3)
Release Date: Friday 22nd September 2023
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.5.4</VersionPrefix>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>develop</VersionSuffix>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageVersion Include="prometheus-net" Version="8.0.1" />
<PackageVersion Include="prometheus-net.AspNetCore" Version="8.0.1" />
<PackageVersion Include="prometheus-net.AspNetCore.HealthChecks" Version="8.0.1" />
<PackageVersion Include="RadixDlt.RadixEngineToolkit" Version="1.0.0-commit-dc89718" />
<PackageVersion Include="RadixDlt.RadixEngineToolkit" Version="1.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<!-- build time dependencies -->
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
Expand All @@ -33,4 +33,4 @@
<PackageVersion Include="xunit" Version="2.5.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.1" />
</ItemGroup>
</Project>
</Project>
3 changes: 0 additions & 3 deletions apps/GatewayApi/GatewayApiStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,15 @@

using GatewayApi.SlowRequestLogging;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Prometheus;
using RadixDlt.NetworkGateway.GatewayApi;
using RadixDlt.NetworkGateway.PostgresIntegration;
using RadixDlt.NetworkGateway.PrometheusIntegration;
using System;
using System.Globalization;

namespace GatewayApi;

Expand Down
1 change: 0 additions & 1 deletion apps/GatewayApi/SlowRequestLogging/BufferingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
using System.Buffers;
using System.Diagnostics;
using System.IO;
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using FluentValidation;
using System;

namespace RadixDlt.NetworkGateway.Abstractions.Configuration;

public sealed class SlowQueryLoggingOptions
{
public TimeSpan SlowQueryThreshold { get; set; } = TimeSpan.FromMilliseconds(250);
}

public class SlowQueryLoggingOptionsValidator : AbstractOptionsValidator<SlowQueryLoggingOptions>
{
public SlowQueryLoggingOptionsValidator()
{
RuleFor(x => x.SlowQueryThreshold).GreaterThan(TimeSpan.Zero);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
* permissions under this License.
*/

using RadixDlt.NetworkGateway.Abstractions.CoreCommunications;
using RadixDlt.NetworkGateway.Abstractions.Exceptions;
using System;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentValidation;
using Microsoft.Extensions.Configuration;
using RadixDlt.NetworkGateway.Abstractions.Configuration;

namespace RadixDlt.NetworkGateway.DataAggregator.Configuration;

public sealed class NodeWorkersOptions
{
[ConfigurationKeyName("ErrorStartupBlockTimeSeconds")]
public int ErrorStartupBlockTimeSeconds { get; set; } = 20;

[ConfigurationKeyName("GraceSecondsBeforeMarkingStalled")]
public int GraceSecondsBeforeMarkingStalled { get; set; } = 10;
}

internal class NodeWorkersOptionsValidator : AbstractOptionsValidator<NodeWorkersOptions>
{
public NodeWorkersOptionsValidator()
{
RuleFor(x => x.ErrorStartupBlockTimeSeconds).GreaterThan(0);
RuleFor(x => x.GraceSecondsBeforeMarkingStalled).GreaterThan(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
* permissions under this License.
*/

using RadixDlt.NetworkGateway.Abstractions.CoreCommunications;
using RadixDlt.NetworkGateway.Abstractions.Extensions;
using RadixDlt.NetworkGateway.DataAggregator.Services;
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
* permissions under this License.
*/

using RadixDlt.NetworkGateway.Abstractions.Configuration;
using RadixDlt.NetworkGateway.DataAggregator.Configuration;

namespace RadixDlt.NetworkGateway.DataAggregator.NodeServices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using RadixDlt.NetworkGateway.Abstractions;
using RadixDlt.NetworkGateway.Abstractions.Exceptions;
using RadixDlt.NetworkGateway.Abstractions.Extensions;
using RadixDlt.NetworkGateway.DataAggregator.Configuration;
using RadixDlt.NetworkGateway.DataAggregator.Workers.NodeWorkers;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -107,6 +109,7 @@ private set
private readonly object _statusLock = new();
private readonly ILogger<NodeWorkersRunner> _logger;
private readonly IClock _clock;
private readonly IOptionsMonitor<NodeWorkersOptions> _nodeWorkersOptions;

private IServiceScope? _nodeDependencyInjectionScope;

Expand All @@ -119,12 +122,13 @@ private set
private IDisposable? _logScope;
private NodeWorkersRunnerStatus _status;

public NodeWorkersRunner(ILogger<NodeWorkersRunner> logger, IServiceScope nodeDependencyInjectionScope, IDisposable logScope, IClock clock)
public NodeWorkersRunner(ILogger<NodeWorkersRunner> logger, IServiceScope nodeDependencyInjectionScope, IDisposable logScope, IClock clock, IOptionsMonitor<NodeWorkersOptions> nodeWorkersOptions)
{
_logger = logger;
_nodeDependencyInjectionScope = nodeDependencyInjectionScope;
_logScope = logScope;
_clock = clock;
_nodeWorkersOptions = nodeWorkersOptions;
_cancellationTokenSource = new CancellationTokenSource();
_initializers = nodeDependencyInjectionScope.ServiceProvider.GetServices<INodeInitializer>().ToList();
_workers = nodeDependencyInjectionScope.ServiceProvider.GetServices<INodeWorker>().ToList();
Expand All @@ -136,16 +140,16 @@ public NodeWorkersRunner(ILogger<NodeWorkersRunner> logger, IServiceScope nodeDe
/// </summary>
public bool IsHealthy()
{
const int GraceSecondsBeforeMarkingStalled = 10;
var graceSecondsBeforeMarkingStalled = _nodeWorkersOptions.CurrentValue.GraceSecondsBeforeMarkingStalled;

var isRunningOrNotStalled = Status == NodeWorkersRunnerStatus.Running || _lastStatusChange.WithinPeriodOfNow(TimeSpan.FromSeconds(GraceSecondsBeforeMarkingStalled), _clock);
var isRunningOrNotStalled = Status == NodeWorkersRunnerStatus.Running || _lastStatusChange.WithinPeriodOfNow(TimeSpan.FromSeconds(graceSecondsBeforeMarkingStalled), _clock);
if (!isRunningOrNotStalled)
{
_logger.LogWarning(
"Marked as unhealthy because current status is {Status} and last status changes was at {LastStatusChange}, longer than {GracePeriod}s ago - suggesting that the WorkersRegistry hasn't properly handled something, and these NodeWorkers should be restarted",
Status,
_lastStatusChange,
GraceSecondsBeforeMarkingStalled
graceSecondsBeforeMarkingStalled
);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ public static DataAggregatorBuilder AddNetworkGatewayDataAggregatorCore(this ISe

services
.AddValidatableOptionsAtSection<NetworkOptions, NetworkOptionsValidator>("DataAggregator:Network")
.AddValidatableOptionsAtSection<SlowQueryLoggingOptions, SlowQueryLoggingOptionsValidator>("DataAggregator:SlowQueryLogging")
.AddValidatableOptionsAtSection<MonitoringOptions, MonitoringOptionsValidator>("DataAggregator:Monitoring")
.AddValidatableOptionsAtSection<MempoolOptions, MempoolOptionsValidator>("DataAggregator:Mempool")
.AddValidatableOptionsAtSection<NodeWorkersOptions, NodeWorkersOptionsValidator>("DataAggregator:NodeWorkers")
.AddValidatableOptionsAtSection<LedgerConfirmationOptions, LedgerConfirmationOptionsValidator>("DataAggregator:LedgerConfirmation")
.AddValidatableOptionsAtSection<TransactionAssertionsOptions, TransactionAssertionsOptionsValidator>("DataAggregator:TransactionAssertions");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public interface IFetchedTransactionStore

void StoreNodeTransactions(string nodeName, List<CoreModel.CommittedTransaction> transactions, int responseSize);

bool ShouldFetchNewTransactions(string nodeName, long fromStateVersion);
bool ShouldFetchNewTransactions(string nodeName, long committedStateVersion);

long GetFirstStateVersionToFetch(string nodeName, long lastCommittedStateVersion);
}
Expand Down Expand Up @@ -172,12 +172,12 @@ public void RemoveProcessedTransactions(long committedStateVersion)
.ToList();
}

public bool ShouldFetchNewTransactions(string nodeName, long fromStateVersion)
public bool ShouldFetchNewTransactions(string nodeName, long committedStateVersion)
{
var transactionStore = GetTransactionsStoreForNode(nodeName);

var storedTransactionsSize = transactionStore
.Where(x => x.Key >= fromStateVersion)
.Where(x => x.Key > committedStateVersion)
.Aggregate(0, (sum, current) => sum + current.Value.EstimatedSize);

var shouldFetchTransactions = storedTransactionsSize < Config.MaxEstimatedTransactionPipelineByteSizePerNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
* permissions under this License.
*/

using RadixDlt.NetworkGateway.Abstractions.Model;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
using RadixDlt.NetworkGateway.DataAggregator.Exceptions;
using RadixDlt.NetworkGateway.DataAggregator.Monitoring;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
* permissions under this License.
*/

using RadixDlt.NetworkGateway.Abstractions;
using RadixDlt.NetworkGateway.Abstractions.Addressing;
using RadixDlt.NetworkGateway.Abstractions.CoreCommunications;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@

using RadixDlt.NetworkGateway.Abstractions.Extensions;
using RadixDlt.NetworkGateway.DataAggregator.NodeServices;
using RadixDlt.NetworkGateway.DataAggregator.NodeServices.ApiReaders;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using CoreModel = RadixDlt.CoreApiSdk.Model;

namespace RadixDlt.NetworkGateway.DataAggregator.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using RadixDlt.NetworkGateway.Abstractions;
using RadixDlt.NetworkGateway.DataAggregator.Configuration;
using RadixDlt.NetworkGateway.DataAggregator.NodeServices;
Expand Down Expand Up @@ -97,6 +98,7 @@ public NodeWorkersRunner CreateWorkersForNode(CoreApiNode initialCoreApiNode)
var nodeScope = _services.CreateScope();
nodeScope.ServiceProvider.GetRequiredService<INodeConfigProvider>().CoreApiNode = initialCoreApiNode;
var logScope = _logger.BeginScope($"[NODE: {initialCoreApiNode.Name}]");
return new NodeWorkersRunner(_logger, nodeScope, logScope!, nodeScope.ServiceProvider.GetRequiredService<IClock>());
return new NodeWorkersRunner(_logger, nodeScope, logScope!, nodeScope.ServiceProvider.GetRequiredService<IClock>(),
nodeScope.ServiceProvider.GetRequiredService<IOptionsMonitor<NodeWorkersOptions>>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
*/

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using RadixDlt.NetworkGateway.Abstractions.Extensions;
using RadixDlt.NetworkGateway.DataAggregator.Configuration;
using RadixDlt.NetworkGateway.DataAggregator.NodeServices;
Expand All @@ -83,18 +84,18 @@ public interface INodeWorkersRunnerRegistry

internal class NodeWorkersRunnerRegistry : INodeWorkersRunnerRegistry
{
private const int ErrorStartupBlockTimeSeconds = 20;

private readonly ILogger<INodeWorkersRunnerRegistry> _logger;
private readonly IOptionsMonitor<NodeWorkersOptions> _nodeWorkersOptions;
private readonly INodeWorkersRunnerFactory _nodeWorkersRunnerFactory;
private readonly Dictionary<CoreApiNode, NodeWorkersRunner> _servicesMap = new();
private readonly Dictionary<string, Task> _startupBlocklist = new();
private readonly object _servicesMapLock = new();

public NodeWorkersRunnerRegistry(ILogger<NodeWorkersRunnerRegistry> logger, INodeWorkersRunnerFactory nodeWorkersRunnerFactory)
public NodeWorkersRunnerRegistry(ILogger<NodeWorkersRunnerRegistry> logger, INodeWorkersRunnerFactory nodeWorkersRunnerFactory, IOptionsMonitor<NodeWorkersOptions> nodeWorkersOptions)
{
_logger = logger;
_nodeWorkersRunnerFactory = nodeWorkersRunnerFactory;
_nodeWorkersOptions = nodeWorkersOptions;
}

public async Task EnsureCorrectNodeServicesRunning(List<CoreApiNode> enabledNodes, CancellationToken cancellationToken)
Expand Down Expand Up @@ -185,16 +186,18 @@ private async Task CreateAndStartNodeWorkersIfNotExists(CoreApiNode coreApiNode,
throw;
}

var errorStartupBlockTimeSeconds = _nodeWorkersOptions.CurrentValue.ErrorStartupBlockTimeSeconds;

_logger.LogError(
ex,
"Error initializing or starting up services for node: {NodeName}. We won't try again for {ErrorStartupBlockTimeSeconds} seconds. Now clearing up...",
coreApiNode.Name,
ErrorStartupBlockTimeSeconds
errorStartupBlockTimeSeconds
);

lock (_servicesMapLock)
{
_startupBlocklist[coreApiNode.Name] = Task.Delay(TimeSpan.FromSeconds(ErrorStartupBlockTimeSeconds), cancellationToken);
_startupBlocklist[coreApiNode.Name] = Task.Delay(TimeSpan.FromSeconds(errorStartupBlockTimeSeconds), cancellationToken);
}

await StopNodeWorkers(coreApiNode, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public sealed class EndpointOptions
[ConfigurationKeyName("MaxPageSize")]
public int MaxPageSize { get; set; } = 100;

[ConfigurationKeyName("DefaultTransactionsStreamPageSize")]
public int DefaultTransactionsStreamPageSize { get; set; } = 10;

[ConfigurationKeyName("DefaultNonFungibleIdsPageSize")]
public int DefaultNonFungibleIdsPageSize { get; set; } = 100;

[ConfigurationKeyName("RequestTimeout")]
public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(10);

Expand All @@ -98,6 +104,8 @@ internal class EndpointOptionsValidator : AbstractOptionsValidator<EndpointOptio
public EndpointOptionsValidator()
{
RuleFor(x => x.MaxPageSize).GreaterThan(0);
RuleFor(x => x.DefaultNonFungibleIdsPageSize).GreaterThan(0);
RuleFor(x => x.DefaultTransactionsStreamPageSize).GreaterThan(0);
RuleFor(x => x.RequestTimeout).GreaterThan(TimeSpan.Zero);
RuleFor(x => x.DefaultPageSize).GreaterThan(0);
RuleFor(x => x.ValidatorsPageSize).GreaterThan(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
* permissions under this License.
*/

using System;
using CoreModel = RadixDlt.CoreApiSdk.Model;
using GatewayModel = RadixDlt.NetworkGateway.GatewayApiSdk.Model;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

using RadixDlt.NetworkGateway.Abstractions.Extensions;
using System;
using System.Net;
using GatewayModel = RadixDlt.NetworkGateway.GatewayApiSdk.Model;

namespace RadixDlt.NetworkGateway.GatewayApi.Exceptions;
Expand All @@ -76,8 +77,10 @@ public enum NotSyncedUpRequestType

public sealed class NotSyncedUpException : KnownGatewayErrorException
{
private const int InternalServerErrorCode = (int)HttpStatusCode.InternalServerError;

private NotSyncedUpException(GatewayModel.NotSyncedUpError gatewayError, string userFacingMessage)
: base(500, gatewayError, userFacingMessage)
: base(InternalServerErrorCode, gatewayError, userFacingMessage)
{
}

Expand Down
Loading

0 comments on commit a79a6ae

Please sign in to comment.