-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
indexer binary #168
indexer binary #168
Changes from 30 commits
1e04687
e5faae5
7356166
8d2adcc
a1f1dc9
a192b52
0672c96
02a08b1
fc9a3d4
7d9abbd
15ebfe7
ee5ab58
3f2f38b
e112162
2b74722
4b904e1
3ab9c0d
961c00b
f965585
ec81d2a
20f3e23
bab1d99
a435a28
7cebfc3
2d410cf
b5d8871
6de5af7
9b52471
f0b4137
d8a3f18
14ddedc
cd568fa
d9de7ca
7d83c40
fd94fbb
104ae39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: [ master, development, feat/*, rc/* ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
golangci: | ||
name: golangci linter | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17.6 | ||
- uses: actions/checkout@v3 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. | ||
version: v1.45.2 | ||
|
||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
|
||
# Optional: golangci-lint command line arguments. | ||
args: --timeout 10m0s --max-issues-per-linter 0 --max-same-issues 0 --print-issued-lines | ||
|
||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
only-new-issues: true | ||
|
||
# Optional: if set to true then the action will use pre-installed Go | ||
# skip-go-installation: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[config] | ||
iulianpascalau marked this conversation as resolved.
Show resolved
Hide resolved
bogdan-rosianu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
enabled-indices = [ | ||
"rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", | ||
"receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", | ||
"logs", "delegators", "operations", "collections" | ||
] | ||
[config.web-socket] | ||
server-url = "localhost:22111" | ||
data-marshaller-type = "json" | ||
[config.address-converter] | ||
length = 32 | ||
type = "bech32" | ||
[config.validator-keys-converter] | ||
length = 96 | ||
type = "hex" | ||
[config.hasher] | ||
type = "blake2b" | ||
[config.marshaller] | ||
type = "gogo protobuf" | ||
[config.economics] | ||
denomination = 18 | ||
[config.logs] | ||
log-file-life-span-in-mb = 1024 # 1GB | ||
log-file-life-span-in-sec = 432000 # 5 days | ||
log-file-prefix = "elastic-indexer" | ||
logs-path = "logs" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[elastic-cluster] | ||
use-kibana = false | ||
url = "http://localhost:9200" | ||
username = "" | ||
password = "" | ||
bulk-request-max-size-in-bytes = 4194304 # 4MB |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
logger "github.com/ElrondNetwork/elrond-go-logger" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var ( | ||
configurationFile = cli.StringFlag{ | ||
Name: "config", | ||
Usage: "The main configuration file to load", | ||
Value: "./config/config.toml", | ||
} | ||
// configurationPreferencesFile defines a flag for the path to the preferences toml configuration file | ||
configurationPreferencesFile = cli.StringFlag{ | ||
Name: "config-preferences", | ||
Usage: "The [path] for the preferences configuration file. This TOML file contains " + | ||
"preferences configurations, such as the node display name or the shard to start in when starting as observer", | ||
Value: "./config/prefs.toml", | ||
} | ||
logLevel = cli.StringFlag{ | ||
Name: "log-level", | ||
Usage: "This flag specifies the logger `level(s)`. It can contain multiple comma-separated value. For example" + | ||
", if set to *:INFO the logs for all packages will have the INFO level. However, if set to *:INFO,api:DEBUG" + | ||
" the logs for all packages will have the INFO level, excepting the api package which will receive a DEBUG" + | ||
" log level.", | ||
Value: "*:" + logger.LogInfo.String(), | ||
} | ||
logSaveFile = cli.BoolFlag{ | ||
Name: "log-save", | ||
Usage: "Boolean option for enabling log saving. If set, it will automatically save all the logs into a file.", | ||
} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/ElrondNetwork/elastic-indexer-go/config" | ||
"github.com/ElrondNetwork/elastic-indexer-go/factory" | ||
"github.com/ElrondNetwork/elrond-go-core/core" | ||
"github.com/ElrondNetwork/elrond-go-core/core/check" | ||
"github.com/ElrondNetwork/elrond-go-core/core/closing" | ||
logger "github.com/ElrondNetwork/elrond-go-logger" | ||
"github.com/ElrondNetwork/elrond-go-logger/file" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var ( | ||
log = logger.GetOrCreate("indexer") | ||
helpTemplate = `NAME: | ||
{{.Name}} - {{.Usage}} | ||
USAGE: | ||
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}} | ||
{{if len .Authors}} | ||
AUTHOR: | ||
{{range .Authors}}{{ . }}{{end}} | ||
{{end}}{{if .Commands}} | ||
GLOBAL OPTIONS: | ||
{{range .VisibleFlags}}{{.}} | ||
{{end}} | ||
VERSION: | ||
{{.Version}} | ||
{{end}} | ||
` | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
cli.AppHelpTemplate = helpTemplate | ||
app.Name = "Elastic indexer" | ||
app.Usage = "This tool will index data in an Elasticsearch database" | ||
app.Flags = []cli.Flag{ | ||
configurationFile, | ||
configurationPreferencesFile, | ||
logLevel, | ||
logSaveFile, | ||
} | ||
app.Authors = []cli.Author{ | ||
{ | ||
Name: "The Elrond Team", | ||
Email: "[email protected]", | ||
}, | ||
} | ||
|
||
app.Action = startIndexer | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Error(err.Error()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func startIndexer(ctx *cli.Context) error { | ||
cfg, err := loadMainConfig(ctx.GlobalString(configurationFile.Name)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clusterCfg, err := loadClusterConfig(ctx.GlobalString(configurationPreferencesFile.Name)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fileLogging, err := initializeLogger(ctx, cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
wsClient, err := factory.CreateWsIndexer(cfg, clusterCfg) | ||
if err != nil { | ||
log.Error("cannot create ws indexer", "error", err) | ||
} | ||
|
||
interrupt := make(chan os.Signal, 1) | ||
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
go wsClient.Start() | ||
|
||
<-interrupt | ||
wsClient.Close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might add a log before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
if !check.IfNilReflect(fileLogging) { | ||
err = fileLogging.Close() | ||
log.LogIfError(err) | ||
} | ||
return nil | ||
} | ||
|
||
func loadMainConfig(filepath string) (config.Config, error) { | ||
cfg := config.Config{} | ||
err := core.LoadTomlFile(&cfg, filepath) | ||
|
||
return cfg, err | ||
} | ||
|
||
func loadClusterConfig(filepath string) (config.ClusterConfig, error) { | ||
cfg := config.ClusterConfig{} | ||
err := core.LoadTomlFile(&cfg, filepath) | ||
|
||
return cfg, err | ||
} | ||
|
||
func initializeLogger(ctx *cli.Context, cfg config.Config) (closing.Closer, error) { | ||
logLevelFlagValue := ctx.GlobalString(logLevel.Name) | ||
err := logger.SetLogLevel(logLevelFlagValue) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
withLogFile := ctx.GlobalBool(logSaveFile.Name) | ||
bogdan-rosianu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !withLogFile { | ||
return nil, nil | ||
} | ||
|
||
workingDir, err := os.Getwd() | ||
if err != nil { | ||
log.LogIfError(err) | ||
workingDir = "" | ||
} | ||
|
||
fileLogging, err := file.NewFileLogging(file.ArgsFileLogging{ | ||
WorkingDir: workingDir, | ||
DefaultLogsPath: cfg.Config.Logs.LogsPath, | ||
LogFilePrefix: cfg.Config.Logs.LogFilePrefix, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("%w creating a log file", err) | ||
} | ||
|
||
err = fileLogging.ChangeFileLifeSpan( | ||
time.Second*time.Duration(cfg.Config.Logs.LogFileLifeSpanInSec), | ||
uint64(cfg.Config.Logs.LogFileLifeSpanInMB), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = logger.RemoveLogObserver(os.Stdout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might extract the new code in a function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = logger.AddLogObserver(os.Stdout, &logger.PlainFormatter{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return fileLogging, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will need to get changed to
branches: [ master, development, feat/*, rc/* ]
as fixing a linter issue on a PR will not start the re-check process. Where did you get this file? So we can also apply the patch there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.