mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-29 20:25:24 +08:00
feat: fix reporting errors
This commit is contained in:
@@ -810,7 +810,7 @@ func (p *Processor) flushBlock(ctx context.Context, blockHeader types.BlockHeade
|
||||
|
||||
// submit event to reporting system
|
||||
if p.reportingClient != nil {
|
||||
if err := p.reportingClient.SubmitBlockReport(ctx, reportingclientv2.SubmitBlockReportPayload{
|
||||
if err := p.reportingClient.SubmitBlockReport(ctx, reportingclientv2.SubmitBlockReportPayloadData{
|
||||
Type: "runes",
|
||||
ClientVersion: Version,
|
||||
DBVersion: DBVersion,
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Key for test only. DO NOT USE IN PRODUCTION
|
||||
const (
|
||||
privateKeyStr = "ce9c2fd75623e82a83ed743518ec7749f6f355f7301dd432400b087717fed2f2"
|
||||
mainnetKey = "L49LKamtrPZxty5TG7jaFPHMRZbrvAr4Dvn5BHGdvmvbcTDNAbZj"
|
||||
|
||||
@@ -105,9 +105,10 @@ func (r *ReportingClient) SubmitBlockReport(ctx context.Context, payload SubmitB
|
||||
return errors.Wrap(err, "can't send request")
|
||||
}
|
||||
if resp.StatusCode() >= 400 {
|
||||
logger.WarnContext(ctx, "failed to submit block report", slog.Any("payload", payload), slog.Any("responseBody", resp.Body()))
|
||||
logger.WarnContext(ctx, "failed to submit block report", slog.Any("payload", bodyStruct), slog.Any("responseBody", resp.Body()))
|
||||
} else {
|
||||
logger.DebugContext(ctx, "block report submitted", slog.Any("payload", bodyStruct))
|
||||
}
|
||||
logger.DebugContext(ctx, "block report submitted", slog.Any("payload", payload))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -160,7 +161,8 @@ func (r *ReportingClient) SubmitNodeReport(ctx context.Context, module string, n
|
||||
}
|
||||
if resp.StatusCode() >= 400 {
|
||||
logger.WarnContext(ctx, "failed to submit node report", slog.Any("payload", payload), slog.Any("responseBody", resp.Body()))
|
||||
} else {
|
||||
logger.InfoContext(ctx, "node report submitted", slog.Any("payload", payload))
|
||||
}
|
||||
logger.InfoContext(ctx, "node report submitted", slog.Any("payload", payload))
|
||||
return nil
|
||||
}
|
||||
|
||||
46
pkg/reportingclientv2/reportingclient_test.go
Normal file
46
pkg/reportingclientv2/reportingclient_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package reportingclientv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/gaze-network/indexer-network/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Key for test only. DO NOT USE IN PRODUCTION
|
||||
const (
|
||||
privateKeyStr = "ce9c2fd75623e82a83ed743518ec7749f6f355f7301dd432400b087717fed2f2"
|
||||
mainnetKey = "L49LKamtrPZxty5TG7jaFPHMRZbrvAr4Dvn5BHGdvmvbcTDNAbZj"
|
||||
pubKeyStr = "0251e2dfcdeea17cc9726e4be0855cd0bae19e64f3e247b10760cd76851e7df47e"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
config := Config{
|
||||
ReportCenter: ReportCenter{
|
||||
BaseURL: "http://localhost:8000",
|
||||
PublicKey: defaultPublicKey,
|
||||
},
|
||||
NodeInfo: NodeInfo{
|
||||
Name: "tests",
|
||||
},
|
||||
}
|
||||
client, err := New(config, privateKeyStr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = client.SubmitNodeReport(context.Background(), "runes", "mainnet", "v0.0.1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = client.SubmitBlockReport(context.Background(), SubmitBlockReportPayloadData{
|
||||
Type: "runes",
|
||||
ClientVersion: "v0.0.1",
|
||||
DBVersion: 1,
|
||||
EventHashVersion: 1,
|
||||
Network: common.NetworkMainnet,
|
||||
BlockHeight: 2,
|
||||
BlockHash: chainhash.Hash{},
|
||||
EventHash: chainhash.Hash{},
|
||||
CumulativeEventHash: chainhash.Hash{},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user