Add index to parsedVaa collection (#616)
* Improve log to get latency for all endpoints except ready and health Co-authored-by: walker-16 <agpazos85@gmail.com> * Add index to parsedVaa collection Co-authored-by: walker-16 <agpazos85@gmail.com> --------- Co-authored-by: walker-16 <agpazos85@gmail.com>
This commit is contained in:
parent
88d6f64bf4
commit
0d2b5bdfd7
|
@ -167,7 +167,14 @@ func main() {
|
||||||
|
|
||||||
app.Use(requestid.New())
|
app.Use(requestid.New())
|
||||||
app.Use(logger.New(logger.Config{
|
app.Use(logger.New(logger.Config{
|
||||||
Format: "level=info timestamp=${time} method=${method} path=${path} status${status} request_id=${locals:requestid}\n",
|
Format: "level=info timestamp=${time} method=${method} path=${path} latency=${latency} status${status} request_id=${locals:requestid}\n",
|
||||||
|
Next: func(c *fiber.Ctx) bool {
|
||||||
|
path := c.Path()
|
||||||
|
if path == "/api/v1/health" || path == "/api/v1/ready" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
if cfg.PprofEnabled {
|
if cfg.PprofEnabled {
|
||||||
app.Use(pprof.New())
|
app.Use(pprof.New())
|
||||||
|
|
|
@ -2,7 +2,7 @@ ENVIRONMENT=production-mainnet
|
||||||
NAMESPACE=wormscan
|
NAMESPACE=wormscan
|
||||||
NAME=wormscan-api
|
NAME=wormscan-api
|
||||||
PORT=8000
|
PORT=8000
|
||||||
REPLICAS=2
|
REPLICAS=4
|
||||||
IMAGE_NAME=
|
IMAGE_NAME=
|
||||||
RESOURCES_LIMITS_MEMORY=256Mi
|
RESOURCES_LIMITS_MEMORY=256Mi
|
||||||
RESOURCES_LIMITS_CPU=500m
|
RESOURCES_LIMITS_CPU=500m
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
parserAlert "github.com/wormhole-foundation/wormhole-explorer/parser/internal/alert"
|
parserAlert "github.com/wormhole-foundation/wormhole-explorer/parser/internal/alert"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/parser/internal/metrics"
|
"github.com/wormhole-foundation/wormhole-explorer/parser/internal/metrics"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/parser/internal/sqs"
|
"github.com/wormhole-foundation/wormhole-explorer/parser/internal/sqs"
|
||||||
|
"github.com/wormhole-foundation/wormhole-explorer/parser/migration"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/parser/parser"
|
"github.com/wormhole-foundation/wormhole-explorer/parser/parser"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/parser/processor"
|
"github.com/wormhole-foundation/wormhole-explorer/parser/processor"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/parser/queue"
|
"github.com/wormhole-foundation/wormhole-explorer/parser/queue"
|
||||||
|
@ -58,6 +59,12 @@ func Run() {
|
||||||
logger.Fatal("failed to connect MongoDB", zap.Error(err))
|
logger.Fatal("failed to connect MongoDB", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run the database migration.
|
||||||
|
err = migration.Run(db.Database)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal("error running migration", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
// get alert client.
|
// get alert client.
|
||||||
alertClient, err := newAlertClient(config)
|
alertClient, err := newAlertClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/wormhole-foundation/wormhole-explorer/parser/parser"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: move this to migration tool that support mongodb.
|
||||||
|
func Run(db *mongo.Database) error {
|
||||||
|
// Created parsedVaa collection.
|
||||||
|
err := db.CreateCollection(context.TODO(), parser.ParsedVAACollection)
|
||||||
|
if err != nil && isNotAlreadyExistsError(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// create index in observations collection by indexedAt.
|
||||||
|
indexToAddress := mongo.IndexModel{Keys: bson.D{{Key: "standardizedProperties.toAddress", Value: 1}}}
|
||||||
|
_, err = db.Collection(parser.ParsedVAACollection).Indexes().CreateOne(context.TODO(), indexToAddress)
|
||||||
|
if err != nil && isNotAlreadyExistsError(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isNotAlreadyExistsError(err error) bool {
|
||||||
|
target := &mongo.CommandError{}
|
||||||
|
isCommandError := errors.As(err, target)
|
||||||
|
if !isCommandError || err.(mongo.CommandError).Code != 48 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -14,6 +14,8 @@ import (
|
||||||
// repository errors
|
// repository errors
|
||||||
var ErrDocNotFound = errors.New("NOT FOUND")
|
var ErrDocNotFound = errors.New("NOT FOUND")
|
||||||
|
|
||||||
|
const ParsedVAACollection = "parsedVaa"
|
||||||
|
|
||||||
// Repository definitions.
|
// Repository definitions.
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
db *mongo.Database
|
db *mongo.Database
|
||||||
|
@ -28,7 +30,7 @@ func NewRepository(db *mongo.Database, log *zap.Logger) *Repository {
|
||||||
return &Repository{db, log, struct {
|
return &Repository{db, log, struct {
|
||||||
parsedVaa *mongo.Collection
|
parsedVaa *mongo.Collection
|
||||||
}{
|
}{
|
||||||
parsedVaa: db.Collection("parsedVaa"),
|
parsedVaa: db.Collection(ParsedVAACollection),
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue