diff --git a/cmd/algod/main.go b/cmd/algod/main.go index 3e4162bf30..b67747984c 100644 --- a/cmd/algod/main.go +++ b/cmd/algod/main.go @@ -327,12 +327,17 @@ func run() int { } currentVersion := config.GetCurrentVersion() + var overrides []telemetryspec.NameValue + for name, val := range config.GetNonDefaultConfigValues(cfg, startupConfigCheckFields) { + overrides = append(overrides, telemetryspec.NameValue{Name: name, Value: val}) + } startupDetails := telemetryspec.StartupEventDetails{ Version: currentVersion.String(), CommitHash: currentVersion.CommitHash, Branch: currentVersion.Branch, Channel: currentVersion.Channel, InstanceHash: crypto.Hash([]byte(absolutePath)).String(), + Overrides: overrides, } log.EventWithDetails(telemetryspec.ApplicationState, telemetryspec.StartupEvent, startupDetails) @@ -369,6 +374,30 @@ func run() int { return 0 } +var startupConfigCheckFields = []string{ + "AgreementIncomingBundlesQueueLength", + "AgreementIncomingProposalsQueueLength", + "AgreementIncomingVotesQueueLength", + "BroadcastConnectionsLimit", + "CatchupBlockValidateMode", + "ConnectionsRateLimitingCount", + "ConnectionsRateLimitingWindowSeconds", + "GossipFanout", + "IncomingConnectionsLimit", + "IncomingMessageFilterBucketCount", + "IncomingMessageFilterBucketSize", + "LedgerSynchronousMode", + "MaxAcctLookback", + "MaxConnectionsPerIP", + "OutgoingMessageFilterBucketCount", + "OutgoingMessageFilterBucketSize", + "ProposalAssemblyTime", + "ReservedFDs", + "TxPoolExponentialIncreaseFactor", + "TxPoolSize", + "VerifiedTranscationsCacheSize", +} + func resolveDataDir() string { // Figure out what data directory to tell algod to use. // If not specified on cmdline with '-d', look for default in environment. diff --git a/config/config_test.go b/config/config_test.go index 454f52c613..1e1915faa3 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -26,6 +26,7 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/algorand/go-algorand/protocol" @@ -551,3 +552,31 @@ func TestLocalVersionField(t *testing.T) { expectedTag = expectedTag[:len(expectedTag)-1] require.Equal(t, expectedTag, string(field.Tag)) } + +func TestGetNonDefaultConfigValues(t *testing.T) { + partitiontest.PartitionTest(t) + + cfg := GetDefaultLocal() + + // set 4 non-default values + cfg.AgreementIncomingBundlesQueueLength = 2 + cfg.AgreementIncomingProposalsQueueLength = 200 + cfg.TxPoolSize = 30 + cfg.Archival = true + + // ask for 2 of them + ndmap := GetNonDefaultConfigValues(cfg, []string{"AgreementIncomingBundlesQueueLength", "TxPoolSize"}) + + // assert correct + expected := map[string]interface{}{ + "AgreementIncomingBundlesQueueLength": uint64(2), + "TxPoolSize": int(30), + } + assert.Equal(t, expected, ndmap) + + // ask for field that doesn't exist: should skip + assert.Equal(t, expected, GetNonDefaultConfigValues(cfg, []string{"Blah", "AgreementIncomingBundlesQueueLength", "TxPoolSize"})) + + // check unmodified defaults + assert.Empty(t, GetNonDefaultConfigValues(GetDefaultLocal(), []string{"AgreementIncomingBundlesQueueLength", "TxPoolSize"})) +} diff --git a/config/migrate.go b/config/migrate.go index 9fd9c86076..405314c628 100644 --- a/config/migrate.go +++ b/config/migrate.go @@ -198,3 +198,25 @@ func getVersionedDefaultLocalConfig(version uint32) (local Local) { } return } + +// GetNonDefaultConfigValues takes a provided cfg and list of field names, and returns a map of all values in cfg +// that are not set to the default for the latest version. +func GetNonDefaultConfigValues(cfg Local, fieldNames []string) map[string]interface{} { + defCfg := GetDefaultLocal() + ret := make(map[string]interface{}) + + for _, fieldName := range fieldNames { + defField := reflect.ValueOf(defCfg).FieldByName(fieldName) + if !defField.IsValid() { + continue + } + cfgField := reflect.ValueOf(cfg).FieldByName(fieldName) + if !cfgField.IsValid() { + continue + } + if !reflect.DeepEqual(defField.Interface(), cfgField.Interface()) { + ret[fieldName] = cfgField.Interface() + } + } + return ret +} diff --git a/logging/telemetryspec/event.go b/logging/telemetryspec/event.go index 81d2283241..a759bb261d 100644 --- a/logging/telemetryspec/event.go +++ b/logging/telemetryspec/event.go @@ -29,6 +29,12 @@ type Event string // StartupEvent event const StartupEvent Event = "Startup" +// NameValue defines a named value, for use in an array reported to telemetry. +type NameValue struct { + Name string + Value interface{} +} + // StartupEventDetails contains details for the StartupEvent type StartupEventDetails struct { Version string @@ -36,6 +42,7 @@ type StartupEventDetails struct { Branch string Channel string InstanceHash string + Overrides []NameValue } // HeartbeatEvent is sent periodically to indicate node is running