diff --git a/.golangci.yml b/.golangci.yml index ae2d42c..552370d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - dogsled - dupl - errcheck + - govet - exportloopref - exhaustive - goconst diff --git a/internal/core/controllers/monitor/base.go b/internal/core/controllers/monitor/base.go index 387417a..fa66134 100644 --- a/internal/core/controllers/monitor/base.go +++ b/internal/core/controllers/monitor/base.go @@ -30,22 +30,25 @@ type Builders struct { } type Controller struct { - lock sync.RWMutex // 8 bytes on 64-bit, keep first due to its size and to avoid false sharing + builders Builders // 8 bytes // Pointers (8 bytes each on 64-bit systems), group together - configs map[string]config.Config // 8 bytes - gateways Gateways // 8 bytes - builders Builders // 8 bytes - hosts Hosts // 8 bytes - releases []metrics.Release // 8 bytes + configs map[string]config.Config // 8 bytes + gateways Gateways // 8 bytes + selectedConfig config.Config // size depends on the struct definition // Strings and slices (16 bytes each on 64-bit systems), group together - network string // 16 bytes (pointer + len) - selectedTables []enums.TableType // 16 bytes (pointer + len + cap) + network string // 16 bytes (pointer + len) // Enum and struct types, smaller than pointers, group together - selectedDashboard enums.TableType // size depends on the underlying type, typically int32 or int - selectedConfig config.Config // size depends on the struct definition + selectedDashboard enums.TableType // size depends on the underlying type, typically int32 or int + hosts Hosts // 8 bytes + releases []metrics.Release // 8 bytes + + selectedTables []enums.TableType // 16 bytes (pointer + len + cap) + + lock sync.RWMutex // 8 bytes on 64-bit, keep first due to its size and to avoid false sharing + } // NewController creates a new instance of the Controller. diff --git a/internal/core/domain/config/base.go b/internal/core/domain/config/base.go index 4406dcc..38a29d0 100644 --- a/internal/core/domain/config/base.go +++ b/internal/core/domain/config/base.go @@ -15,6 +15,9 @@ const ( ) type Config struct { + IPLookup struct { + AccessToken string `yaml:"access-token"` + } `yaml:"ip-lookup"` PublicRPC []string `yaml:"public-rpc"` FullNodes []struct { JSONRPCAddress string `yaml:"json-rpc-address"` @@ -23,9 +26,6 @@ type Config struct { Validators []struct { MetricsAddress string `yaml:"metrics-address"` } `yaml:"validators"` - IPLookup struct { - AccessToken string `yaml:"access-token"` - } `yaml:"ip-lookup"` } // NewConfig reads the Suimon configuration files from the directory specified by diff --git a/internal/core/domain/host/addressinfo.go b/internal/core/domain/host/addressinfo.go index 773348b..89e94d6 100644 --- a/internal/core/domain/host/addressinfo.go +++ b/internal/core/domain/host/addressinfo.go @@ -20,8 +20,8 @@ const ( ) type AddressInfo struct { - Endpoint address.Endpoint Ports map[enums.PortType]string + Endpoint address.Endpoint } // GetUrlRPC generates a URL for the RPC endpoint of the address. diff --git a/internal/core/domain/host/host.go b/internal/core/domain/host/host.go index 1abd282..03f1166 100644 --- a/internal/core/domain/host/host.go +++ b/internal/core/domain/host/host.go @@ -23,13 +23,13 @@ type Gateways struct { type Host struct { AddressInfo + gateways Gateways + IPInfo *ports.IPResult + TableType enums.TableType Status enums.Status - IPInfo *ports.IPResult Metrics metrics.Metrics - - gateways Gateways } func NewHost( diff --git a/internal/core/domain/metrics/metrics.go b/internal/core/domain/metrics/metrics.go index 46b5eed..04339eb 100644 --- a/internal/core/domain/metrics/metrics.go +++ b/internal/core/domain/metrics/metrics.go @@ -16,6 +16,8 @@ const ( type ( // Transactions represents information about transactions on the Sui blockchain network. Transactions struct { + TransactionsHistory []int + CertificatesHistory []int TotalTransactionsBlocks int TotalTransactionCertificates int CertificatesCreated int @@ -24,12 +26,11 @@ type ( TotalTransactionEffects int TransactionsPerSecond int TxSyncPercentage int - TransactionsHistory []int - CertificatesHistory []int } // Checkpoints represents information about checkpoints on the Sui blockchain network. Checkpoints struct { + CheckpointsHistory []int LatestCheckpoint int HighestKnownCheckpoint int HighestSyncedCheckpoint int @@ -38,16 +39,15 @@ type ( CheckpointExecBacklog int CheckpointSyncBacklog int CheckSyncPercentage int - CheckpointsHistory []int } // Rounds represents information about rounds on the Sui blockchain network. Rounds struct { + RoundsHistory []int CurrentRound int HighestProcessedRound int RoundsPerSecond int LastCommittedRound int - RoundsHistory []int } // Peers represents information about peers on the Sui blockchain network. @@ -59,11 +59,11 @@ type ( // Epoch represents information about the current epoch on the Sui blockchain network. Epoch struct { - CurrentEpoch int EpochStartTimeUTC string - EpochTotalDuration int EpochDurationHHMM string DurationTillEpochEndHHMM string + CurrentEpoch int + EpochTotalDuration int EpochPercentage int TimeTillNextEpoch int64 } @@ -86,23 +86,24 @@ type ( // Metrics represents various metrics about the Sui blockchain network. Metrics struct { - Updated bool - - SystemState SuiSystemState ValidatorsApyParsed ValidatorsApyParsed Uptime string Version string Commit string - Transactions - Checkpoints + SystemState SuiSystemState + + Epoch Protocol Rounds - Peers - Epoch + + Transactions + Checkpoints GasPrice + Peers Errors + Updated bool } ) diff --git a/internal/core/domain/metrics/release.go b/internal/core/domain/metrics/release.go index da1d037..0c38a36 100644 --- a/internal/core/domain/metrics/release.go +++ b/internal/core/domain/metrics/release.go @@ -15,14 +15,14 @@ type Release struct { TagName string `json:"tag_name"` CommitHash string `json:"target_commitish"` Name string `json:"name"` - Draft bool `json:"draft"` - PreRelease bool `json:"prerelease"` PublishedAt string `json:"published_at"` CreatedAt string `json:"created_at"` URL string `json:"html_url"` Author struct { Login string `json:"login"` } `json:"author"` + Draft bool `json:"draft"` + PreRelease bool `json:"prerelease"` } // getReleases fetches releases for a given repo and filters them by network name diff --git a/internal/core/domain/metrics/suisystemstate.go b/internal/core/domain/metrics/suisystemstate.go index 36a6011..f04f187 100644 --- a/internal/core/domain/metrics/suisystemstate.go +++ b/internal/core/domain/metrics/suisystemstate.go @@ -12,13 +12,13 @@ const validatorsQuorum = 6667 type ( // SuiSystemState represents the current state of the Sui blockchain system. SuiSystemState struct { + AddressToValidator AddressToValidator Epoch string `json:"epoch"` ProtocolVersion string `json:"protocolVersion"` SystemStateVersion string `json:"systemStateVersion"` StorageFundTotalObjectStorageRebates string `json:"storageFundTotalObjectStorageRebates"` StorageFundNonRefundableBalance string `json:"storageFundNonRefundableBalance"` ReferenceGasPrice string `json:"referenceGasPrice"` - SafeMode bool `json:"safeMode"` SafeModeStorageRewards string `json:"safeModeStorageRewards"` SafeModeComputationRewards string `json:"safeModeComputationRewards"` SafeModeStorageRebates string `json:"safeModeStorageRebates"` @@ -35,23 +35,23 @@ type ( StakeSubsidyDistributionCounter string `json:"stakeSubsidyDistributionCounter"` StakeSubsidyCurrentDistributionAmount string `json:"stakeSubsidyCurrentDistributionAmount"` StakeSubsidyPeriodLength string `json:"stakeSubsidyPeriodLength"` - StakeSubsidyDecreaseRate int `json:"stakeSubsidyDecreaseRate"` TotalStake string `json:"totalStake"` - ActiveValidators Validators `json:"activeValidators"` PendingActiveValidatorsID string `json:"pendingActiveValidatorsId"` PendingActiveValidatorsSize string `json:"pendingActiveValidatorsSize"` - PendingRemovals []interface{} `json:"pendingRemovals"` StakingPoolMappingsID string `json:"stakingPoolMappingsId"` StakingPoolMappingsSize string `json:"stakingPoolMappingsSize"` InactivePoolsID string `json:"inactivePoolsId"` InactivePoolsSize string `json:"inactivePoolsSize"` ValidatorCandidatesID string `json:"validatorCandidatesId"` ValidatorCandidatesSize string `json:"validatorCandidatesSize"` + ActiveValidators Validators `json:"activeValidators"` + PendingRemovals []interface{} `json:"pendingRemovals"` AtRiskValidators [][]interface{} `json:"atRiskValidators"` ValidatorReportRecords [][]interface{} `json:"validatorReportRecords"` - AddressToValidator AddressToValidator ValidatorsAtRiskParsed ValidatorsAtRisk ValidatorReportsParsed ValidatorsReports + StakeSubsidyDecreaseRate int `json:"stakeSubsidyDecreaseRate"` + SafeMode bool `json:"safeMode"` } // ValidatorsApy represents the APYs of validators. @@ -71,8 +71,8 @@ type ( // ValidatorReport represents validator reporters ValidatorReport struct { Name string - SlashingPercentage float64 Reporters []ValidatorReporter + SlashingPercentage float64 } // ValidatorReporter contains information about a validator reporter diff --git a/internal/core/domain/service/dashboardbuilder/base.go b/internal/core/domain/service/dashboardbuilder/base.go index 0283590..aea9c98 100644 --- a/internal/core/domain/service/dashboardbuilder/base.go +++ b/internal/core/domain/service/dashboardbuilder/base.go @@ -18,13 +18,13 @@ import ( type Builder struct { ctx context.Context - tableType enums.TableType cliGateway *cligw.Gateway terminal *termbox.Terminal dashboard *container.Container host *domainhost.Host cells dashboards.Cells quitter func(k *terminalapi.Keyboard) + tableType enums.TableType } // NewBuilder creates a new Builder instance with the provided CLI gateway. diff --git a/internal/core/domain/service/dashboardbuilder/dashboards/cell.go b/internal/core/domain/service/dashboardbuilder/dashboards/cell.go index 0201ba2..41406f9 100644 --- a/internal/core/domain/service/dashboardbuilder/dashboards/cell.go +++ b/internal/core/domain/service/dashboardbuilder/dashboards/cell.go @@ -34,9 +34,9 @@ type Cells map[enums.ColumnName]*Cell // Cell is a struct that represents a single cell in a dashboard grid. It contains a widget and a list of options. type Cell struct { + LastUpdatedAt time.Time Widget widgetapi.Widget Options []container.Option - LastUpdatedAt time.Time } // NewCell is a function that creates a new Cell struct given a cellName and a widget. It returns a pointer to the new Cell and an error (if any). diff --git a/internal/core/domain/service/dashboardbuilder/dashboards/row.go b/internal/core/domain/service/dashboardbuilder/dashboards/row.go index 5fa130f..583f58c 100644 --- a/internal/core/domain/service/dashboardbuilder/dashboards/row.go +++ b/internal/core/domain/service/dashboardbuilder/dashboards/row.go @@ -14,8 +14,8 @@ type RowsConfig []RowConfig // RowConfig is a type that represents the configuration for a single row in a grid. // It contains a height and a list of column names that should be included in the row. type RowConfig struct { - Height int Columns []enums.ColumnName + Height int } // Rows is a type that represents a set of grid rows, each of which is an element in the grid. diff --git a/internal/core/domain/service/tablebuilder/base.go b/internal/core/domain/service/tablebuilder/base.go index d2f38df..8179994 100644 --- a/internal/core/domain/service/tablebuilder/base.go +++ b/internal/core/domain/service/tablebuilder/base.go @@ -19,12 +19,12 @@ const slashingPct50 = 50 const slashingPct100 = 50 type Builder struct { + writer table.Writer + cliGateway *cligw.Gateway + config *tables.TableConfig tableType enums.TableType hosts []host.Host Releases []metrics.Release - cliGateway *cligw.Gateway - writer table.Writer - config *tables.TableConfig } // NewBuilder creates a new instance of the table builder, using the CLI gateway diff --git a/internal/core/domain/service/tablebuilder/tables/base.go b/internal/core/domain/service/tablebuilder/tables/base.go index 5742dd7..98880e6 100644 --- a/internal/core/domain/service/tablebuilder/tables/base.go +++ b/internal/core/domain/service/tablebuilder/tables/base.go @@ -105,10 +105,10 @@ type SortConfig []table.SortBy // TableConfig represents the overall configuration for a table. type TableConfig struct { - Name string // The name of the table - Style table.Style // The style of the table Columns ColumnsConfig // Configuration for the table's columns + Name string // The name of the table Rows RowsConfig // Configuration for the table's rows + Style table.Style // The style of the table ColumnsCount int // The total number of columns in the table RowsCount int // The total number of rows in the table } diff --git a/internal/core/domain/service/tablebuilder/tables/column.go b/internal/core/domain/service/tablebuilder/tables/column.go index d081b45..7d4979b 100644 --- a/internal/core/domain/service/tablebuilder/tables/column.go +++ b/internal/core/domain/service/tablebuilder/tables/column.go @@ -21,8 +21,8 @@ type ( ColumnValues map[enums.ColumnName]any Column struct { - Values []any Config *table.ColumnConfig + Values []any } ) diff --git a/internal/core/gateways/cligw/error.go b/internal/core/gateways/cligw/error.go index 4bd3fa7..cb5e63c 100644 --- a/internal/core/gateways/cligw/error.go +++ b/internal/core/gateways/cligw/error.go @@ -29,13 +29,13 @@ func (gateway *Gateway) ErrorfWithOpts(msg string, opts MsgOpts, vars ...interfa } func (Gateway) ErrorWithOpts(msg string, opts MsgOpts) { - var icon string + var newIcon string for icon, i := errorIcon, opts.Indent; i > 0; i-- { - icon = fmt.Sprintf(" %s", icon) + newIcon = fmt.Sprintf(" %s", icon) } - formattedIcon := iconErrColor.Sprint(icon) + formattedIcon := iconErrColor.Sprint(newIcon) formattedMsg := messageErrColor.Sprint(msg) result := fmt.Sprintf("%s %s", formattedIcon, formattedMsg) diff --git a/internal/core/gateways/cligw/info.go b/internal/core/gateways/cligw/info.go index ba36b19..a8b735f 100644 --- a/internal/core/gateways/cligw/info.go +++ b/internal/core/gateways/cligw/info.go @@ -31,13 +31,13 @@ func (gateway *Gateway) InfoWithOpts(label, value string, opts MsgOpts) { } func (Gateway) infoLabel(label string, indent int) string { - var icon string + var newIcon string for icon, i := infoIcon, indent; i > 0; i-- { - icon = fmt.Sprintf(" %s", icon) + newIcon = fmt.Sprintf(" %s", icon) } - bang := iconInfoColor.Sprint(icon) + bang := iconInfoColor.Sprint(newIcon) formattedLabel := messageInfoColor.Sprint(label) return fmt.Sprintf("%s %s", bang, formattedLabel) diff --git a/internal/core/gateways/cligw/selectchoice.go b/internal/core/gateways/cligw/selectchoice.go index 662828e..6e6ebfa 100644 --- a/internal/core/gateways/cligw/selectchoice.go +++ b/internal/core/gateways/cligw/selectchoice.go @@ -3,9 +3,9 @@ package cligw type ( SelectChoiceList []SelectChoice SelectChoice struct { + Data any Label string Value string - Data any } ) diff --git a/internal/core/gateways/cligw/warn.go b/internal/core/gateways/cligw/warn.go index a694715..5cc0022 100644 --- a/internal/core/gateways/cligw/warn.go +++ b/internal/core/gateways/cligw/warn.go @@ -29,13 +29,13 @@ func (gateway *Gateway) WarnfWithOpts(msg string, opts MsgOpts, vars ...interfac } func (Gateway) WarnWithOpts(msg string, opts MsgOpts) { - var icon string + var newIcon string for icon, i := warnIcon, opts.Indent; i > 0; i-- { - icon = fmt.Sprintf(" %s", icon) + newIcon = fmt.Sprintf(" %s", icon) } - formattedIcon := iconWarnColor.Sprint(icon) + formattedIcon := iconWarnColor.Sprint(newIcon) formattedMsg := messageWarnColor.Sprint(msg) result := fmt.Sprintf("%s %s", formattedIcon, formattedMsg) diff --git a/internal/core/gateways/geogw/base.go b/internal/core/gateways/geogw/base.go index d22380e..9946854 100644 --- a/internal/core/gateways/geogw/base.go +++ b/internal/core/gateways/geogw/base.go @@ -19,9 +19,9 @@ const ( type Gateway struct { ctx context.Context - accessToken string client *ipinfo.Client cliGateway *cligw.Gateway + accessToken string } func NewGateway(cliGW *cligw.Gateway, accessToken string) ports.GeoGateway { diff --git a/internal/core/gateways/prometheusgw/base.go b/internal/core/gateways/prometheusgw/base.go index 5dc469d..33d46d2 100644 --- a/internal/core/gateways/prometheusgw/base.go +++ b/internal/core/gateways/prometheusgw/base.go @@ -13,9 +13,9 @@ const httpClientTimeout = 3 * time.Second type Gateway struct { ctx context.Context - url string client *http.Client cliGateway *cligw.Gateway + url string } func NewGateway(cliGW *cligw.Gateway, url string) ports.PrometheusGateway { diff --git a/internal/core/gateways/prometheusgw/callfor.go b/internal/core/gateways/prometheusgw/callfor.go index 07397d5..22e2a80 100644 --- a/internal/core/gateways/prometheusgw/callfor.go +++ b/internal/core/gateways/prometheusgw/callfor.go @@ -49,9 +49,9 @@ func (gateway *Gateway) CallFor(metrics ports.Metrics) (result ports.MetricsResu go func() { //nolint:bodyclose // The response body is closed below to handle the response properly. - resp, err := gateway.client.Do(req) + resp, reqErr := gateway.client.Do(req) - respChan <- responseWithError{response: resp, err: err} + respChan <- responseWithError{response: resp, err: reqErr} }() select { diff --git a/internal/core/gateways/rpcgw/base.go b/internal/core/gateways/rpcgw/base.go index fcb2712..0162953 100644 --- a/internal/core/gateways/rpcgw/base.go +++ b/internal/core/gateways/rpcgw/base.go @@ -15,9 +15,9 @@ const rpcClientTimeout = 3 * time.Second type Gateway struct { ctx context.Context - url string client jsonrpc.RPCClient cliGateway *cligw.Gateway + url string } func NewGateway(cliGW *cligw.Gateway, url string) ports.RPCGateway { diff --git a/internal/core/ports/gateway.go b/internal/core/ports/gateway.go index 2830682..5b22685 100644 --- a/internal/core/ports/gateway.go +++ b/internal/core/ports/gateway.go @@ -21,15 +21,15 @@ type GeoGateway interface { } type MetricResult struct { - Value float64 Labels prometheus.Labels + Value float64 } type MetricsResult map[enums.PrometheusMetricName]MetricResult type MetricConfig struct { - MetricType enums.PrometheusMetricType Labels prometheus.Labels + MetricType enums.PrometheusMetricType } type Metrics map[enums.PrometheusMetricName]MetricConfig @@ -41,7 +41,7 @@ type Company struct { } type IPResult struct { - IP net.IP + Company *Company Hostname string City string Region string @@ -49,5 +49,5 @@ type IPResult struct { CountryName string CountryEmoji string Location string - Company *Company + IP net.IP } diff --git a/internal/pkg/address/address.go b/internal/pkg/address/address.go index 1d01fbd..9e90d48 100644 --- a/internal/pkg/address/address.go +++ b/internal/pkg/address/address.go @@ -12,11 +12,11 @@ import ( ) type Endpoint struct { - Address string IP *string Host *string Path *string Port *string + Address string SSL bool } @@ -137,7 +137,7 @@ func ParseURL(address string) (*Endpoint, error) { SSL: scheme == "https", } - if ip, err := ParseIP(hostName); err == nil { + if ip, pasreErr := ParseIP(hostName); pasreErr == nil { endpoint.IP = ip }