-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
services/horizon + horizonclient: Add new async transaction submissio…
…n endpoint (#5188) * Add new txsub endpoint - 1 * Add new txsub endpoint - 2 * Add new txsub endpoint - 3 * Update Status to TxStatus * Add unittests for new endpoint * Create submit_transaction_async_test.go * Fix goimports * Rearrange code and remove duplicate code * Add metrics - 1 * Add metrics - 2 * Add metrics - 3 * Fix failing unittest * Add new endpoint to go sdk + integration test * Small changes - 1 * Add openAPI taml * Address review changes - 1 * Remove private methods from interface * Use common metrics client for legacy and async txsub * Fix submitter test * Update submit_transaction_async.go * Fix failing test * Update txsub_async_oapi.yaml * Update submitter.go * Interface method change * Remove duplicate code * Add test for GET /transactions-async * Encapsulation - 1 * Change endpoint naming * Pass interface instead of client * Remove ClientInterface * Remove HTTP Status from submission response * Add logging statements * Fix failing integration tests * Fix failing tests - 1 * Add back deleted files * Remove circular import * Group metrics into submission duration * Group metrics into submission duration - 2 * Remove logging statements where not needed * Change to internal server error * Use request context logger * Use interface method for setting http status * Remove not needed metrics * Remove version * add error in extras * Resolve merge conflicts * Add TODO for problem response * Adding and removing logging statements * Move interface to async handler file * change httpstatus interface definition * Add deleted files back * Revert friendbot change * Add test for getting pending tx * Fix failing test * remove metrics struct and make vars private * pass only rawTx string * Move mock to test file * Make core client private * Remove UpdateTxSubMetrics func * Change http status for DISABLE_TX_SUB * Fix failing unittest * Revert submitter changes * Fix failing submitter_test * Revert import changes * Revert import changes - 2 * Revert import changes - 3 * Remove integration test function * Update main.go
- Loading branch information
1 parent
ee9bbbf
commit a387ffb
Showing
22 changed files
with
1,001 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package stellarcore | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
proto "github.com/stellar/go/protocols/stellarcore" | ||
"github.com/stellar/go/xdr" | ||
) | ||
|
||
var envelopeTypeToLabel = map[xdr.EnvelopeType]string{ | ||
xdr.EnvelopeTypeEnvelopeTypeTxV0: "v0", | ||
xdr.EnvelopeTypeEnvelopeTypeTx: "v1", | ||
xdr.EnvelopeTypeEnvelopeTypeTxFeeBump: "fee_bump", | ||
} | ||
|
||
type ClientWithMetrics struct { | ||
coreClient Client | ||
|
||
// submissionDuration exposes timing metrics about the rate and latency of | ||
// submissions to stellar-core | ||
submissionDuration *prometheus.SummaryVec | ||
} | ||
|
||
func (c ClientWithMetrics) SubmitTx(ctx context.Context, rawTx string) (*proto.TXResponse, error) { | ||
var envelope xdr.TransactionEnvelope | ||
err := xdr.SafeUnmarshalBase64(rawTx, &envelope) | ||
if err != nil { | ||
return &proto.TXResponse{}, err | ||
} | ||
|
||
startTime := time.Now() | ||
response, err := c.coreClient.SubmitTransaction(ctx, rawTx) | ||
duration := time.Since(startTime).Seconds() | ||
|
||
label := prometheus.Labels{} | ||
if err != nil { | ||
label["status"] = "request_error" | ||
} else if response.IsException() { | ||
label["status"] = "exception" | ||
} else { | ||
label["status"] = response.Status | ||
} | ||
|
||
label["envelope_type"] = envelopeTypeToLabel[envelope.Type] | ||
c.submissionDuration.With(label).Observe(duration) | ||
|
||
return response, err | ||
} | ||
|
||
func NewClientWithMetrics(client Client, registry *prometheus.Registry, prometheusSubsystem string) ClientWithMetrics { | ||
submissionDuration := prometheus.NewSummaryVec(prometheus.SummaryOpts{ | ||
Namespace: "horizon", | ||
Subsystem: prometheusSubsystem, | ||
Name: "submission_duration_seconds", | ||
Help: "submission durations to Stellar-Core, sliding window = 10m", | ||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, | ||
}, []string{"status", "envelope_type"}) | ||
|
||
registry.MustRegister( | ||
submissionDuration, | ||
) | ||
|
||
return ClientWithMetrics{ | ||
coreClient: client, | ||
submissionDuration: submissionDuration, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.