Skip to content

Commit

Permalink
available indices and disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Oct 6, 2022
1 parent cd568fa commit d9de7ca
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/elasticindexer/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[config]
enabled-indices = [
available-indices = [
"rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory",
"receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags",
"logs", "delegators", "operations", "collections"
Expand Down
1 change: 1 addition & 0 deletions cmd/elasticindexer/config/prefs.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[config]
disabled-indices = []
[config.web-socket]
server-url = "localhost:22111"
data-marshaller-type = "json"
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
// Config will hold the whole config file's data
type Config struct {
Config struct {
EnabledIndices []string `toml:"enabled-indices"`
AvailableIndices []string `toml:"available-indices"`
AddressConverter struct {
Length int `toml:"length"`
Type string `toml:"type"`
Expand Down Expand Up @@ -33,7 +33,8 @@ type Config struct {
// ClusterConfig will hold the config for the Elasticsearch cluster
type ClusterConfig struct {
Config struct {
WebSocket struct {
DisabledIndices []string `toml:"disabled-indices"`
WebSocket struct {
ServerURL string `toml:"server-url"`
DataMarshallerType string `toml:"data-marshaller-type"`
} `toml:"web-socket"`
Expand Down
20 changes: 19 additions & 1 deletion factory/wsIndexerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,28 @@ func createDataIndexer(cfg config.Config, clusterCfg config.ClusterConfig) (wsin
Url: clusterCfg.Config.ElasticCluster.URL,
UserName: clusterCfg.Config.ElasticCluster.UserName,
Password: clusterCfg.Config.ElasticCluster.Password,
EnabledIndexes: cfg.Config.EnabledIndices,
EnabledIndexes: prepareIndices(cfg.Config.AvailableIndices, clusterCfg.Config.DisabledIndices),
Marshalizer: marshaller,
Hasher: hasher,
AddressPubkeyConverter: addressPubkeyConverter,
ValidatorPubkeyConverter: validatorPubkeyConverter,
})
}

func prepareIndices(availableIndices, disabledIndices []string) []string {
indices := make([]string, 0)

mapDisabledIndices := make(map[string]struct{})
for _, index := range disabledIndices {
mapDisabledIndices[index] = struct{}{}
}

for _, availableIndex := range availableIndices {
_, found := mapDisabledIndices[availableIndex]
if !found {
indices = append(indices, availableIndex)
}
}

return indices
}
23 changes: 23 additions & 0 deletions factory/wsindexerFactory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package factory

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestPrepareIndices(t *testing.T) {
t.Parallel()

available := []string{"index1", "index2"}
disabled := []string{"index2", "index3"}

res := prepareIndices(available, disabled)
require.Equal(t, []string{"index1"}, res)

available = []string{"index1", "index2"}
disabled = []string{}

res = prepareIndices(available, disabled)
require.Equal(t, []string{"index1", "index2"}, res)
}

0 comments on commit d9de7ca

Please sign in to comment.