Skip to content

Commit

Permalink
Merge pull request #314 from multiversx/MX-16233-sovereign-flag
Browse files Browse the repository at this point in the history
sovereign flag
  • Loading branch information
axenteoctavian authored Dec 11, 2024
2 parents b30e362 + 5c50ac4 commit 417430d
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 37 deletions.
5 changes: 5 additions & 0 deletions cmd/elasticindexer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ var (
Name: "disable-ansi-color",
Usage: "Boolean option for disabling ANSI colors in the logging system.",
}
// sovereign defines a flag that specifies if the es instance should run for a sovereign chain
sovereign = cli.BoolFlag{
Name: "sovereign",
Usage: "If set to true, will use sovereign run type components",
}
)
9 changes: 6 additions & 3 deletions cmd/elasticindexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/core/closing"
"github.com/multiversx/mx-chain-core-go/data/outport"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-logger-go/file"
"github.com/urfave/cli"

"github.com/multiversx/mx-chain-es-indexer-go/config"
"github.com/multiversx/mx-chain-es-indexer-go/factory"
"github.com/multiversx/mx-chain-es-indexer-go/metrics"
"github.com/multiversx/mx-chain-es-indexer-go/process/wsindexer"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-logger-go/file"
"github.com/urfave/cli"
)

var (
Expand Down Expand Up @@ -63,6 +64,7 @@ func main() {
logLevel,
logSaveFile,
disableAnsiColor,
sovereign,
}
app.Authors = []cli.Author{
{
Expand All @@ -86,6 +88,7 @@ func startIndexer(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("%w while loading the config file", err)
}
cfg.SovereignType = ctx.GlobalBool(sovereign.Name)

clusterCfg, err := loadClusterConfig(ctx.GlobalString(configurationPreferencesFile.Name))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config struct {
LogsPath string `toml:"logs-path"`
} `toml:"logs"`
} `toml:"config"`
SovereignType bool
}

// ClusterConfig will hold the config for the Elasticsearch cluster
Expand Down
24 changes: 0 additions & 24 deletions factory/interface.go

This file was deleted.

23 changes: 23 additions & 0 deletions factory/runType/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@ type RunTypeComponentsCreator interface {
Create() *runTypeComponents
IsInterfaceNil() bool
}

// ComponentHandler defines the actions common to all component handlers
type ComponentHandler interface {
Create() error
Close() error
CheckSubcomponents() error
String() string
}

// RunTypeComponentsHandler defines the run type components handler actions
type RunTypeComponentsHandler interface {
ComponentHandler
RunTypeComponentsHolder
}

// RunTypeComponentsHolder holds the run type components
type RunTypeComponentsHolder interface {
Create() error
Close() error
CheckSubcomponents() error
String() string
IsInterfaceNil() bool
}
8 changes: 3 additions & 5 deletions factory/runType/runTypeComponentsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"sync"

"github.com/multiversx/mx-chain-core-go/core/check"

"github.com/multiversx/mx-chain-es-indexer-go/factory"
)

const runTypeComponentsName = "managedRunTypeComponents"

var _ factory.ComponentHandler = (*managedRunTypeComponents)(nil)
var _ factory.RunTypeComponentsHandler = (*managedRunTypeComponents)(nil)
var _ factory.RunTypeComponentsHolder = (*managedRunTypeComponents)(nil)
var _ ComponentHandler = (*managedRunTypeComponents)(nil)
var _ RunTypeComponentsHandler = (*managedRunTypeComponents)(nil)
var _ RunTypeComponentsHolder = (*managedRunTypeComponents)(nil)

type managedRunTypeComponents struct {
*runTypeComponents
Expand Down
4 changes: 1 addition & 3 deletions factory/runType/runTypeComponentsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-es-indexer-go/factory"
)

func createComponents() (factory.RunTypeComponentsHandler, error) {
func createComponents() (RunTypeComponentsHandler, error) {
rtcf := NewRunTypeComponentsFactory()
return NewManagedRunTypeComponents(rtcf)
}
Expand Down
4 changes: 3 additions & 1 deletion factory/wsIndexerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
factoryHasher "github.com/multiversx/mx-chain-core-go/hashing/factory"
"github.com/multiversx/mx-chain-core-go/marshal"
factoryMarshaller "github.com/multiversx/mx-chain-core-go/marshal/factory"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-es-indexer-go/config"
"github.com/multiversx/mx-chain-es-indexer-go/core"
"github.com/multiversx/mx-chain-es-indexer-go/process/factory"
"github.com/multiversx/mx-chain-es-indexer-go/process/wsindexer"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("elasticindexer")
Expand Down Expand Up @@ -76,6 +77,7 @@ func createDataIndexer(
}

return factory.NewIndexer(factory.ArgsIndexerFactory{
SovereignType: cfg.SovereignType,
UseKibana: clusterCfg.Config.ElasticCluster.UseKibana,
Denomination: cfg.Config.Economics.Denomination,
BulkRequestMaxSize: clusterCfg.Config.ElasticCluster.BulkRequestMaxSizeInBytes,
Expand Down
29 changes: 28 additions & 1 deletion process/factory/indexerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-es-indexer-go/client"
"github.com/multiversx/mx-chain-es-indexer-go/client/logging"
"github.com/multiversx/mx-chain-es-indexer-go/client/transport"
indexerCore "github.com/multiversx/mx-chain-es-indexer-go/core"
"github.com/multiversx/mx-chain-es-indexer-go/factory/runType"
"github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc"
"github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/factory"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("indexer/factory")
Expand All @@ -30,6 +32,7 @@ type ArgsIndexerFactory struct {
Enabled bool
UseKibana bool
ImportDB bool
SovereignType bool
Denomination int
BulkRequestMaxSize int
Url string
Expand All @@ -44,6 +47,7 @@ type ArgsIndexerFactory struct {
AddressPubkeyConverter core.PubkeyConverter
ValidatorPubkeyConverter core.PubkeyConverter
StatusMetrics indexerCore.StatusMetricsHandler
RunTypeComponents runType.RunTypeComponentsHandler
}

// NewIndexer will create a new instance of Indexer
Expand All @@ -53,6 +57,15 @@ func NewIndexer(args ArgsIndexerFactory) (dataindexer.Indexer, error) {
return nil, err
}

if args.SovereignType {
args.RunTypeComponents, err = createManagedRunTypeComponents(runType.NewSovereignRunTypeComponentsFactory())
} else {
args.RunTypeComponents, err = createManagedRunTypeComponents(runType.NewRunTypeComponentsFactory())
}
if err != nil {
return nil, err
}

elasticProcessor, err := createElasticProcessor(args)
if err != nil {
return nil, err
Expand All @@ -72,6 +85,20 @@ func NewIndexer(args ArgsIndexerFactory) (dataindexer.Indexer, error) {
return dataindexer.NewDataIndexer(arguments)
}

func createManagedRunTypeComponents(factory runType.RunTypeComponentsCreator) (runType.RunTypeComponentsHandler, error) {
managedRunTypeComponents, err := runType.NewManagedRunTypeComponents(factory)
if err != nil {
return nil, err
}

err = managedRunTypeComponents.Create()
if err != nil {
return nil, err
}

return managedRunTypeComponents, nil
}

func retryBackOff(attempt int) time.Duration {
d := time.Duration(math.Exp2(float64(attempt))) * time.Second
log.Debug("elastic: retry backoff", "attempt", attempt, "sleep duration", d)
Expand Down

0 comments on commit 417430d

Please sign in to comment.