Skip to content

Commit b41e189

Browse files
committed
merge master
2 parents 7c62b89 + 95101a0 commit b41e189

File tree

109 files changed

+7319
-3437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+7319
-3437
lines changed

.golangci.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ linters-settings:
1212
- performance
1313
- style
1414
govet:
15-
check-shadowing: true
15+
enable:
16+
- shadow
1617
nolintlint:
1718
require-explanation: true
1819
require-specific: true
19-
20+
issues:
21+
exclude-rules:
22+
# Exclude some linters from running on tests files.
23+
- path: _test\.go
24+
linters:
25+
- gocritic
26+
- gosec
27+
- wsl
2028
linters:
2129
disable-all: true
2230
enable:
@@ -29,7 +37,7 @@ linters:
2937
- durationcheck
3038
- errcheck
3139
- errname
32-
- exportloopref
40+
- copyloopvar
3341
- goconst
3442
- gocritic
3543
- gocyclo

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Xatu
1+
# <img src="./assets/xatu.png" height="40" alt="Xatu Logo"> Xatu
22

33
Ethereum network monitoring with collection clients and a centralized server for data pipelining.
44

assets/xatu.png

31.7 KB
Loading

cmd/cannon.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ var CannonOverrides = []CannonOverride{
9999
overrides.NetworkName.Value = val
100100
},
101101
}),
102+
createCannonOverride(CannonOverrideConfig{
103+
FlagName: "metrics-addr",
104+
EnvName: "METRICS_ADDR",
105+
Description: "sets the metrics address",
106+
OverrideFunc: func(val string, overrides *cannon.Override) {
107+
overrides.MetricsAddr.Enabled = true
108+
overrides.MetricsAddr.Value = val
109+
},
110+
}),
102111
}
103112

104113
// cannonCmd represents the cannon command
@@ -120,7 +129,6 @@ var cannonCmd = &cobra.Command{
120129
log.WithField("location", cannonCfgFile).Info("Loaded config")
121130

122131
overrides := &cannon.Override{}
123-
124132
for _, override := range CannonOverrides {
125133
if errr := override.Setter(cmd, overrides); errr != nil {
126134
log.Fatal(errr)

cmd/cl-mimicry.go

+49-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ var (
1414
clMimicryCfgFile string
1515
)
1616

17+
type CLMimicryOverride struct {
18+
EnvVar string
19+
Flag string
20+
FlagHelper func(cmd *cobra.Command)
21+
Setter func(cmd *cobra.Command, overrides *clmimicry.Override) error
22+
}
23+
24+
var CLMimicryOverrides = []CLMimicryOverride{
25+
{
26+
EnvVar: "METRICS_ADDR",
27+
Flag: "metrics-addr",
28+
FlagHelper: func(cmd *cobra.Command) {
29+
cmd.Flags().String(metricsAddrFlag, "", `metrics address (env: METRICS_ADDR). If set, overrides the metrics address in the config file.`)
30+
},
31+
Setter: func(cmd *cobra.Command, overrides *clmimicry.Override) error {
32+
val := ""
33+
34+
if cmd.Flags().Changed(metricsAddrFlag) {
35+
val = cmd.Flags().Lookup(metricsAddrFlag).Value.String()
36+
}
37+
38+
if os.Getenv("METRICS_ADDR") != "" {
39+
val = os.Getenv("METRICS_ADDR")
40+
}
41+
42+
if val == "" {
43+
return nil
44+
}
45+
46+
overrides.MetricsAddr.Enabled = true
47+
overrides.MetricsAddr.Value = val
48+
49+
return nil
50+
},
51+
},
52+
}
53+
1754
// clMimicryCmd represents the consensus layer mimicry command
1855
var clMimicryCmd = &cobra.Command{
1956
Use: "cl-mimicry",
@@ -32,7 +69,14 @@ var clMimicryCmd = &cobra.Command{
3269

3370
log.WithField("location", clMimicryCfgFile).Info("Loaded config")
3471

35-
mimicry, err := clmimicry.New(cmd.Context(), log, config)
72+
overrides := &clmimicry.Override{}
73+
for _, o := range CLMimicryOverrides {
74+
if e := o.Setter(cmd, overrides); e != nil {
75+
log.Fatal(e)
76+
}
77+
}
78+
79+
mimicry, err := clmimicry.New(cmd.Context(), log, config, overrides)
3680
if err != nil {
3781
log.Fatal(err)
3882
}
@@ -49,6 +93,10 @@ func init() {
4993
rootCmd.AddCommand(clMimicryCmd)
5094

5195
clMimicryCmd.Flags().StringVar(&clMimicryCfgFile, "config", "cl-mimicry.yaml", "config file (default is cl-mimicry.yaml)")
96+
97+
for _, o := range CLMimicryOverrides {
98+
o.FlagHelper(clMimicryCmd)
99+
}
52100
}
53101

54102
func loadCLMimicryConfigFromFile(file string) (*clmimicry.Config, error) {

cmd/discovery.go

+50-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ var (
1414
discoveryCfgFile string
1515
)
1616

17+
type DiscoveryOverride struct {
18+
EnvVar string
19+
Flag string
20+
FlagHelper func(cmd *cobra.Command)
21+
Setter func(cmd *cobra.Command, overrides *discovery.Override) error
22+
}
23+
24+
var DiscoveryOverrides = []DiscoveryOverride{
25+
{
26+
EnvVar: "METRICS_ADDR",
27+
Flag: "metrics-addr",
28+
FlagHelper: func(cmd *cobra.Command) {
29+
cmd.Flags().String(metricsAddrFlag, "", `metrics address (env: METRICS_ADDR). If set, overrides the metrics address in the config file.`)
30+
},
31+
Setter: func(cmd *cobra.Command, overrides *discovery.Override) error {
32+
val := ""
33+
34+
if cmd.Flags().Changed(metricsAddrFlag) {
35+
val = cmd.Flags().Lookup(metricsAddrFlag).Value.String()
36+
}
37+
38+
if os.Getenv("METRICS_ADDR") != "" {
39+
val = os.Getenv("METRICS_ADDR")
40+
}
41+
42+
if val == "" {
43+
return nil
44+
}
45+
46+
overrides.MetricsAddr.Enabled = true
47+
overrides.MetricsAddr.Value = val
48+
49+
return nil
50+
},
51+
},
52+
}
53+
1754
// discoveryCmd represents the discovery command
1855
var discoveryCmd = &cobra.Command{
1956
Use: "discovery",
@@ -31,7 +68,15 @@ var discoveryCmd = &cobra.Command{
3168
log = getLogger(config.LoggingLevel, "")
3269

3370
log.WithField("location", discoveryCfgFile).Info("Loaded config")
34-
discovery, err := discovery.New(cmd.Context(), log, config)
71+
72+
overrides := &discovery.Override{}
73+
for _, o := range DiscoveryOverrides {
74+
if e := o.Setter(cmd, overrides); e != nil {
75+
log.Fatal(e)
76+
}
77+
}
78+
79+
discovery, err := discovery.New(cmd.Context(), log, config, overrides)
3580
if err != nil {
3681
log.Fatal(err)
3782
}
@@ -48,6 +93,10 @@ func init() {
4893
rootCmd.AddCommand(discoveryCmd)
4994

5095
discoveryCmd.Flags().StringVar(&discoveryCfgFile, "config", "discovery.yaml", "config file (default is discovery.yaml)")
96+
97+
for _, o := range DiscoveryOverrides {
98+
o.FlagHelper(discoveryCmd)
99+
}
51100
}
52101

53102
func loadDiscoveryConfigFromFile(file string) (*discovery.Config, error) {

cmd/mimicry.go

+49-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ var (
1414
mimicryCfgFile string
1515
)
1616

17+
type MimicryOverride struct {
18+
EnvVar string
19+
Flag string
20+
FlagHelper func(cmd *cobra.Command)
21+
Setter func(cmd *cobra.Command, overrides *mimicry.Override) error
22+
}
23+
24+
var MimicryOverrides = []MimicryOverride{
25+
{
26+
EnvVar: "METRICS_ADDR",
27+
Flag: "metrics-addr",
28+
FlagHelper: func(cmd *cobra.Command) {
29+
cmd.Flags().String(metricsAddrFlag, "", `metrics address (env: METRICS_ADDR). If set, overrides the metrics address in the config file.`)
30+
},
31+
Setter: func(cmd *cobra.Command, overrides *mimicry.Override) error {
32+
val := ""
33+
34+
if cmd.Flags().Changed(metricsAddrFlag) {
35+
val = cmd.Flags().Lookup(metricsAddrFlag).Value.String()
36+
}
37+
38+
if os.Getenv("METRICS_ADDR") != "" {
39+
val = os.Getenv("METRICS_ADDR")
40+
}
41+
42+
if val == "" {
43+
return nil
44+
}
45+
46+
overrides.MetricsAddr.Enabled = true
47+
overrides.MetricsAddr.Value = val
48+
49+
return nil
50+
},
51+
},
52+
}
53+
1754
// mimicryCmd represents the mimicry command
1855
var mimicryCmd = &cobra.Command{
1956
Use: "mimicry",
@@ -32,7 +69,14 @@ var mimicryCmd = &cobra.Command{
3269

3370
log.WithField("location", mimicryCfgFile).Info("Loaded config")
3471

35-
mimicry, err := mimicry.New(cmd.Context(), log, config)
72+
overrides := &mimicry.Override{}
73+
for _, o := range MimicryOverrides {
74+
if e := o.Setter(cmd, overrides); e != nil {
75+
log.Fatal(e)
76+
}
77+
}
78+
79+
mimicry, err := mimicry.New(cmd.Context(), log, config, overrides)
3680
if err != nil {
3781
log.Fatal(err)
3882
}
@@ -49,6 +93,10 @@ func init() {
4993
rootCmd.AddCommand(mimicryCmd)
5094

5195
mimicryCmd.Flags().StringVar(&mimicryCfgFile, "config", "mimicry.yaml", "config file (default is mimicry.yaml)")
96+
97+
for _, o := range MimicryOverrides {
98+
o.FlagHelper(mimicryCmd)
99+
}
52100
}
53101

54102
func loadMimicryConfigFromFile(file string) (*mimicry.Config, error) {

cmd/relay-monitor.go

+49-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ var (
1414
relayMonitorCfgFile string
1515
)
1616

17+
type RelayMonitorOverride struct {
18+
EnvVar string
19+
Flag string
20+
FlagHelper func(cmd *cobra.Command)
21+
Setter func(cmd *cobra.Command, overrides *relaymonitor.Override) error
22+
}
23+
24+
var RelayMonitorOverrides = []RelayMonitorOverride{
25+
{
26+
EnvVar: "METRICS_ADDR",
27+
Flag: "metrics-addr",
28+
FlagHelper: func(cmd *cobra.Command) {
29+
cmd.Flags().String(metricsAddrFlag, "", `metrics address (env: METRICS_ADDR). If set, overrides the metrics address in the config file.`)
30+
},
31+
Setter: func(cmd *cobra.Command, overrides *relaymonitor.Override) error {
32+
val := ""
33+
34+
if cmd.Flags().Changed(metricsAddrFlag) {
35+
val = cmd.Flags().Lookup(metricsAddrFlag).Value.String()
36+
}
37+
38+
if os.Getenv("METRICS_ADDR") != "" {
39+
val = os.Getenv("METRICS_ADDR")
40+
}
41+
42+
if val == "" {
43+
return nil
44+
}
45+
46+
overrides.MetricsAddr.Enabled = true
47+
overrides.MetricsAddr.Value = val
48+
49+
return nil
50+
},
51+
},
52+
}
53+
1754
// relayMonitorCmd represents the relay monitor command
1855
var relayMonitorCmd = &cobra.Command{
1956
Use: "relay-monitor",
@@ -32,7 +69,14 @@ var relayMonitorCmd = &cobra.Command{
3269

3370
log.WithField("location", relayMonitorCfgFile).Info("Loaded config")
3471

35-
monitor, err := relaymonitor.New(cmd.Context(), log, config)
72+
overrides := &relaymonitor.Override{}
73+
for _, o := range RelayMonitorOverrides {
74+
if e := o.Setter(cmd, overrides); e != nil {
75+
log.Fatal(e)
76+
}
77+
}
78+
79+
monitor, err := relaymonitor.New(cmd.Context(), log, config, overrides)
3680
if err != nil {
3781
log.Fatal(err)
3882
}
@@ -49,6 +93,10 @@ func init() {
4993
rootCmd.AddCommand(relayMonitorCmd)
5094

5195
relayMonitorCmd.Flags().StringVar(&relayMonitorCfgFile, "config", "relay-monitor.yaml", "config file (default is relay-monitor.yaml)")
96+
97+
for _, o := range RelayMonitorOverrides {
98+
o.FlagHelper(relayMonitorCmd)
99+
}
52100
}
53101

54102
func loadRelayMonitorConfigFromFile(file string) (*relaymonitor.Config, error) {

cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var (
1515

1616
defaultLogLevel = "info"
1717
defaultLogFormat = "text"
18+
19+
metricsAddrFlag = "metrics-addr"
1820
)
1921

2022
// rootCmd represents the base command when called without any subcommands

0 commit comments

Comments
 (0)