Skip to content

Commit

Permalink
Merge pull request #524 from radixdlt/fix-metrics-with-empty-node-if-…
Browse files Browse the repository at this point in the history
…failed-in-gateway

Fix metrics with empty node if failed in gateway
  • Loading branch information
PawelPawelec-RDX authored Oct 9, 2023
2 parents d08fc2e + 4c09998 commit a0711de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace RadixDlt.NetworkGateway.GatewayApi.Services;

public interface ISubmissionServiceObserver
{
ValueTask ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome outcome);
ValueTask ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome outcome, string? targetNode = null);
}

// This can be turned into an enum in future if we need this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ public SubmissionService(
using var parsedTransaction = await HandlePreSubmissionParseTransaction(transactionBytes);
await CheckPendingTransactionEpochValidity(ledgerState, parsedTransaction);

var targetNode = _coreApiHandler.GetCoreNodeConnectedTo();
var options = _coreApiIntegrationOptions.CurrentValue;
var submissionResult = await _submissionTrackingService.ObserveSubmissionToGatewayAndSubmitToNetworkIfNew(
_coreApiHandler.GetTransactionApi(),
_coreApiHandler.GetNetworkName(),
_coreApiHandler.GetCoreNodeConnectedTo().Name,
targetNode.Name,
new PendingTransactionHandlingConfig(
options.MaxSubmissionAttempts,
options.StopResubmittingAfter,
Expand All @@ -134,17 +135,17 @@ public SubmissionService(
// Note: I'm not sure this is the correct choice of what should be an API error here, but I don't want to change the API errors that are thrown this close to launch
if (submissionResult.PermanentlyRejectedReason != null)
{
await _observers.ForEachAsync(x => x.ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome.PermanentlyRejected));
await _observers.ForEachAsync(x => x.ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome.PermanentlyRejected, targetNode.Name));
throw InvalidTransactionException.FromPermanentlyRejectedTransactionError(submissionResult.PermanentlyRejectedReason);
}

if (submissionResult.AlreadyKnown)
{
await _observers.ForEachAsync(x => x.ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome.DuplicateSubmission));
await _observers.ForEachAsync(x => x.ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome.DuplicateSubmission, targetNode.Name));
return new GatewayModel.TransactionSubmitResponse(duplicate: true);
}

await _observers.ForEachAsync(x => x.ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome.SubmittedToNetwork));
await _observers.ForEachAsync(x => x.ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome.SubmittedToNetwork, targetNode.Name));
return new GatewayModel.TransactionSubmitResponse(duplicate: false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,29 @@ internal class DataAggregatorMetricsObserver :
private static readonly Counter _transactionResubmissionAttemptCount = Metrics
.CreateCounter(
"ng_construction_transaction_resubmission_attempt_count",
"Number of transaction resubmission attempts"
"Number of transaction resubmission attempts",
new CounterConfiguration { LabelNames = new[] { "target_node" } }
);

private static readonly Counter _transactionResubmissionSuccessCount = Metrics
.CreateCounter(
"ng_construction_transaction_resubmission_success_count",
"Number of transaction resubmission successes"
"Number of transaction resubmission successes",
new CounterConfiguration { LabelNames = new[] { "target_node" } }
);

private static readonly Counter _transactionResubmissionErrorCount = Metrics
.CreateCounter(
"ng_construction_transaction_resubmission_error_count",
"Number of transaction resubmission errors"
"Number of transaction resubmission errors",
new CounterConfiguration { LabelNames = new[] { "target_node" } }
);

private static readonly Counter _transactionResubmissionResolutionByResultCount = Metrics
.CreateCounter(
"ng_construction_transaction_resubmission_resolution_count",
"Number of various resolutions of transaction resubmissions",
new CounterConfiguration { LabelNames = new[] { "result" } }
new CounterConfiguration { LabelNames = new[] { "result", "target_node" } }
);

private static readonly Gauge _aggregatorIsUnhealthy = Metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ ValueTask ISubmissionTrackingServiceObserver.OnSubmissionTrackedInDatabase(bool
return ValueTask.CompletedTask;
}

public ValueTask ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome outcome)
public ValueTask ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmissionOutcome outcome, string? targetNode = null)
{
var label = outcome switch
{
Expand All @@ -306,7 +306,10 @@ public ValueTask ObserveTransactionSubmissionToGatewayOutcome(TransactionSubmiss
TransactionSubmissionOutcome.StartEpochInFuture => "start_epoch_in_future",
TransactionSubmissionOutcome.EndEpochInPast => "end_epoch_in_past",
};
_transactionSubmitResolutionByResultCount.WithLabels(label).Inc();

targetNode ??= "n/a";

_transactionSubmitResolutionByResultCount.WithLabels(label, targetNode).Inc();

return ValueTask.CompletedTask;
}
Expand Down

0 comments on commit a0711de

Please sign in to comment.