Skip to content

Commit

Permalink
Refactor config and logging setup (#65)
Browse files Browse the repository at this point in the history
I'm going to change metrics to be non-global, this moves irrelevant
files out of infra package.
  • Loading branch information
sergekh2 authored May 24, 2024
1 parent 88f8b98 commit f727146
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 34 deletions.
4 changes: 2 additions & 2 deletions core/node/infra/logging.go → core/node/cmd/logging.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package infra
package cmd

import (
"fmt"
"log/slog"
"os"

"github.com/river-build/river/core/node/config"
"github.com/river-build/river/core/node/dlog"
config "github.com/river-build/river/core/node/infra/config"
)

var (
Expand Down
3 changes: 1 addition & 2 deletions core/node/cmd/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/mitchellh/mapstructure"

"github.com/river-build/river/core/node/config"
"github.com/river-build/river/core/node/infra"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -92,7 +91,7 @@ func initConfigAndLog() {

// If loaded successfully, set the global config
cmdConfig = &configStruct
infra.InitLogFromConfig(&cmdConfig.Log)
InitLogFromConfig(&cmdConfig.Log)
} else {
fmt.Println("No config file specified")
}
Expand Down
21 changes: 18 additions & 3 deletions core/node/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
infra "github.com/river-build/river/core/node/infra/config"
"github.com/river-build/river/core/node/shared"
)

Expand Down Expand Up @@ -51,10 +50,10 @@ type Config struct {
RegistryContract ContractConfig

// Logging
Log infra.LogConfig
Log LogConfig

// Metrics
Metrics infra.MetricsConfig
Metrics MetricsConfig
PerformanceTracking PerformanceTrackingConfig

// Stream configuration
Expand Down Expand Up @@ -234,6 +233,22 @@ type ArchiveConfig struct {
StreamsContractCallPageSize int64 // If 0, default to 5000.
}

type LogConfig struct {
Level string // Used for both file and console if their levels not set explicitly
File string // Path to log file
FileLevel string // If not set, use Level
Console bool // Log to sederr if true
ConsoleLevel string // If not set, use Level
NoColor bool
Format string // "json" or "text"
}

type MetricsConfig struct {
Enabled bool
Interface string
Port int
}

func (ac *ArchiveConfig) GetReadMiniblocksSize() uint64 {
if ac.ReadMiniblcocksSize <= 0 {
return 100
Expand Down
17 changes: 0 additions & 17 deletions core/node/infra/config/config.go

This file was deleted.

5 changes: 0 additions & 5 deletions core/node/infra/constants.go

This file was deleted.

2 changes: 1 addition & 1 deletion core/node/infra/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/river-build/river/core/node/config"
"github.com/river-build/river/core/node/dlog"
config "github.com/river-build/river/core/node/infra/config"
)

/* SuccessMetrics is a struct for tracking success/failure of various operations.
Expand Down
4 changes: 2 additions & 2 deletions core/xchain/cmd/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/river-build/river/core/node/config"

"github.com/river-build/river/core/node/infra"
node_cmd "github.com/river-build/river/core/node/cmd"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -85,7 +85,7 @@ func initConfigAndLog() {
}

loadedCfg = &configStruct
infra.InitLogFromConfig(&loadedCfg.Log)
node_cmd.InitLogFromConfig(&loadedCfg.Log)
} else {
fmt.Println("No config file specified")
}
Expand Down
3 changes: 1 addition & 2 deletions core/xchain/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
node_contracts "github.com/river-build/river/core/node/contracts"
node_crypto "github.com/river-build/river/core/node/crypto"
"github.com/river-build/river/core/node/dlog"
infra "github.com/river-build/river/core/node/infra/config"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -270,7 +269,7 @@ func (st *serviceTester) Config() *config.Config {
TestCustomEntitlementContract: config.ContractConfig{
Address: st.mockCustomEntitlementAddress,
},
Log: infra.LogConfig{
Log: config.LogConfig{
NoColor: true,
},
}
Expand Down

0 comments on commit f727146

Please sign in to comment.