Skip to content

Commit

Permalink
use default config
Browse files Browse the repository at this point in the history
  • Loading branch information
okdas committed Dec 10, 2024
1 parent 867a691 commit 42716a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
8 changes: 3 additions & 5 deletions cmd/poktrolld/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ type PoktrollAppConfig struct {
}

// poktrollAppConfigDefaults sets default values to render in `app.toml`.
// Checkout `customAppConfigTemplate()` for additional information about each setting.
// Checkout `customAppConfigTemplate()` for additional information about each config parameter.
func poktrollAppConfigDefaults() PoktrollAppConfig {
return PoktrollAppConfig{
Telemetry: telemetry.PoktrollTelemetryConfig{
CardinalityLevel: "medium",
},
Telemetry: telemetry.DefaultConfig(),
}
}

Expand Down Expand Up @@ -104,7 +102,6 @@ func initCometBFTConfig() *cmtcfg.Config {
// return "", nil if no custom configuration is required for the application.
// TODO_MAINNET: Reconsider values - check `app.toml` for possible options.
func initAppConfig() (string, interface{}) {
// The following code snippet is just for reference.
type CustomAppConfig struct {
serverconfig.Config `mapstructure:",squash"`
Poktroll PoktrollAppConfig `mapstructure:"poktroll"`
Expand Down Expand Up @@ -140,6 +137,7 @@ func initAppConfig() (string, interface{}) {
srvCfg.GRPC.Enable = true
srvCfg.GRPCWeb.Enable = true

// Create the custom config with both server and poktroll configs
customAppConfig := CustomAppConfig{
Config: *srvCfg,
Poktroll: poktrollAppConfigDefaults(),
Expand Down
14 changes: 14 additions & 0 deletions telemetry/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package telemetry

// Default configuration values for telemetry
const (
// DefaultCardinalityLevel represents the default cardinality level for metrics collection
DefaultCardinalityLevel = "medium"
)

// DefaultConfig returns the default telemetry configuration
func DefaultConfig() PoktrollTelemetryConfig {
return PoktrollTelemetryConfig{
CardinalityLevel: DefaultCardinalityLevel,
}
}
23 changes: 19 additions & 4 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@ import (
// Set once on initialization and remains constant during runtime.
var globalTelemetryConfig PoktrollTelemetryConfig

// PoktrollTelemetryConfig represents the telemetry protion of the custom poktroll config section in `app.toml`.
// PoktrollTelemetryConfig represents the telemetry portion of the custom poktroll config section in `app.toml`.
type PoktrollTelemetryConfig struct {
CardinalityLevel string `mapstructure:"cardinality-level"`
}

// New sets the globalTelemetryConfig for telemetry package.
func New(appOpts servertypes.AppOptions) error {
// Extract the map from appOpts.
// `poktroll.telemetry` comes from `app.toml` which is parsed into a map.
telemetryMap := appOpts.Get("poktroll.telemetry").(map[string]interface{})
// Get the poktroll config section. If it doesn't exist, use defaults
poktrollConfig := appOpts.Get("poktroll")
if poktrollConfig == nil {
globalTelemetryConfig = DefaultConfig()
return nil
}

// Try to get the telemetry subsection
poktrollMap, ok := poktrollConfig.(map[string]interface{})
if !ok {
return fmt.Errorf("invalid poktroll config format: expected map[string]interface{}, got %T", poktrollConfig)
}

telemetryMap, ok := poktrollMap["telemetry"].(map[string]interface{})
if !ok {
globalTelemetryConfig = DefaultConfig()
return nil
}

// Use mapstructure to decode the map into the struct
if err := mapstructure.Decode(telemetryMap, &globalTelemetryConfig); err != nil {
Expand Down

0 comments on commit 42716a9

Please sign in to comment.