diff --git a/core/config/docs/docs.go b/core/config/docs/docs.go index c3b696e551f..d5b0e7d8386 100644 --- a/core/config/docs/docs.go +++ b/core/config/docs/docs.go @@ -122,6 +122,24 @@ func newTable(line string, desc lines) *table { return t } +func newArrayOfTables(line string, desc lines) *table { + t := &table{ + name: strings.Trim(strings.Trim(line, fieldExample), "[[]]"), + codes: []string{line}, + desc: desc, + } + if len(desc) > 0 { + if strings.HasPrefix(strings.TrimSpace(desc[0]), tokenAdvanced) { + t.adv = true + t.desc = t.desc[1:] + } else if strings.HasPrefix(strings.TrimSpace(desc[len(desc)-1]), tokenExtended) { + t.ext = true + t.desc = t.desc[:len(desc)-1] + } + } + return t +} + func (t table) advanced() string { if t.adv { return advancedWarning("Do not change these settings unless you know what you are doing.") @@ -217,6 +235,10 @@ func parseTOMLDocs(s string) (items []fmt.Stringer, err error) { items = append(items, desc) desc = nil } + } else if strings.HasPrefix(line, "[[") { + currentTable = newArrayOfTables(line, desc) + items = append(items, currentTable) + desc = nil } else if strings.HasPrefix(line, "[") { currentTable = newTable(line, desc) items = append(items, currentTable) diff --git a/core/config/docs/docs_test.go b/core/config/docs/docs_test.go index f1a3ab1906c..0eee33cb729 100644 --- a/core/config/docs/docs_test.go +++ b/core/config/docs/docs_test.go @@ -20,6 +20,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" + "github.com/smartcontractkit/chainlink/v2/core/store/models" "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) @@ -37,6 +38,12 @@ func TestDoc(t *testing.T) { require.NoError(t, err) } + // Except for TelemetryIngress.ServerPubKey and TelemetryIngress.URL as this will be removed in the future + // and its only use is to signal to NOPs that these fields are no longer allowed + emptyString := "" + c.TelemetryIngress.ServerPubKey = &emptyString + c.TelemetryIngress.URL = new(models.URL) + cfgtest.AssertFieldsNotNil(t, c) var defaults chainlink.Config diff --git a/core/config/mocks/telemetry_ingress.go b/core/config/mocks/telemetry_ingress.go index 1160e7ca5f5..eade0bdc256 100644 --- a/core/config/mocks/telemetry_ingress.go +++ b/core/config/mocks/telemetry_ingress.go @@ -7,6 +7,8 @@ import ( mock "github.com/stretchr/testify/mock" time "time" + + url "net/url" ) // TelemetryIngress is an autogenerated mock type for the TelemetryIngress type @@ -100,6 +102,36 @@ func (_m *TelemetryIngress) SendTimeout() time.Duration { return r0 } +// ServerPubKey provides a mock function with given fields: +func (_m *TelemetryIngress) ServerPubKey() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// URL provides a mock function with given fields: +func (_m *TelemetryIngress) URL() *url.URL { + ret := _m.Called() + + var r0 *url.URL + if rf, ok := ret.Get(0).(func() *url.URL); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*url.URL) + } + } + + return r0 +} + // UniConn provides a mock function with given fields: func (_m *TelemetryIngress) UniConn() bool { ret := _m.Called() diff --git a/core/config/telemetry_ingress_config.go b/core/config/telemetry_ingress_config.go index a4923391011..1a613aa32a9 100644 --- a/core/config/telemetry_ingress_config.go +++ b/core/config/telemetry_ingress_config.go @@ -16,6 +16,9 @@ type TelemetryIngress interface { SendTimeout() time.Duration UseBatchSend() bool Endpoints() []TelemetryIngressEndpoint + + ServerPubKey() string // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, if this field is set it will trigger an error, only used to warn NOPs of change + URL() *url.URL // Deprecated: Use TelemetryIngressEndpoint.URL instead, if this field is set it will trigger an error, only used to warn NOPs of change } //go:generate mockery --quiet --name TelemetryIngressEndpoint --output ./mocks/ --case=underscore --filename telemetry_ingress_endpoint.go diff --git a/core/config/toml/types.go b/core/config/toml/types.go index 1a38ccc2764..88f73568d1c 100644 --- a/core/config/toml/types.go +++ b/core/config/toml/types.go @@ -428,6 +428,9 @@ type TelemetryIngress struct { SendTimeout *models.Duration UseBatchSend *bool Endpoints []TelemetryIngressEndpoint `toml:",omitempty"` + + URL *models.URL `toml:"-"` // Deprecated: Use TelemetryIngressEndpoint.URL instead, if this field is set it will trigger an error, only used to warn NOPs of change + ServerPubKey *string `toml:"-"` // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, if this field is set it will trigger an error, only used to warn NOPs of change } type TelemetryIngressEndpoint struct { @@ -462,6 +465,42 @@ func (t *TelemetryIngress) setFrom(f *TelemetryIngress) { if v := f.Endpoints; v != nil { t.Endpoints = v } + if v := f.ServerPubKey; v != nil { + t.ServerPubKey = v + } + if v := f.URL; v != nil { + t.URL = v + } +} + +func (t *TelemetryIngress) ValidateConfig() (err error) { + if !t.URL.IsZero() && *t.ServerPubKey != "" { + return configutils.ErrInvalid{Name: "URL", Value: t.URL.String(), + Msg: fmt.Sprintf(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey are no longer allowed. Please use TelemetryIngress.Endpoints instead: + [[TelemetryIngress.Endpoints]] + Network = '...' # e.g. EVM. Solana, Starknet, Cosmos + ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta + URL = '%s' + ServerPubKey = '%s'`, t.URL.String(), *t.ServerPubKey)} + } else if !t.URL.IsZero() { + return configutils.ErrInvalid{Name: "URL", Value: t.URL.String(), + Msg: fmt.Sprintf(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey are no longer allowed. Please use TelemetryIngress.Endpoints instead: + [[TelemetryIngress.Endpoints]] + Network = '...' # e.g. EVM. Solana, Starknet, Cosmos + ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta + URL = '%s' + ServerPubKey = '...'`, t.URL.String())} + } else if *t.ServerPubKey != "" { + return configutils.ErrInvalid{Name: "ServerPubKey", Value: *t.ServerPubKey, + Msg: fmt.Sprintf(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey are no longer allowed. Please use TelemetryIngress.Endpoints instead: + [[TelemetryIngress.Endpoints]] + Network = '...' # e.g. EVM. Solana, Starknet, Cosmos + ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta + URL = '...' + ServerPubKey = '%s'`, *t.ServerPubKey)} + } + + return nil } type AuditLogger struct { diff --git a/core/services/chainlink/config_telemetry_ingress.go b/core/services/chainlink/config_telemetry_ingress.go index 3ad721ad303..902c2ebfc3d 100644 --- a/core/services/chainlink/config_telemetry_ingress.go +++ b/core/services/chainlink/config_telemetry_ingress.go @@ -46,6 +46,16 @@ func (t *telemetryIngressConfig) UseBatchSend() bool { return *t.c.UseBatchSend } +// Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, if this field is set it will trigger an error, only used to warn NOPs of change +func (t *telemetryIngressConfig) ServerPubKey() string { + return t.ServerPubKey() +} + +// Deprecated: Use TelemetryIngressEndpoint.URL instead, if this field is set it will trigger an error, only used to warn NOPs of change +func (t *telemetryIngressConfig) URL() *url.URL { + return t.URL() +} + func (t *telemetryIngressConfig) Endpoints() []config.TelemetryIngressEndpoint { var endpoints []config.TelemetryIngressEndpoint for _, e := range t.c.Endpoints { diff --git a/core/services/chainlink/config_test.go b/core/services/chainlink/config_test.go index e01c048c61c..5e5af48829a 100644 --- a/core/services/chainlink/config_test.go +++ b/core/services/chainlink/config_test.go @@ -1069,6 +1069,17 @@ func TestConfig_full(t *testing.T) { } } + // Except for TelemetryIngress.ServerPubKey as this will be removed in the future + // and its only use is to signal to NOPs that these fields are no longer allowed + if got.TelemetryIngress.ServerPubKey == nil { + got.TelemetryIngress.ServerPubKey = ptr("") + } + // Except for TelemetryIngress.URL as this will be removed in the future + // and its only use is to signal to NOPs that these fields are no longer allowed + if got.TelemetryIngress.URL == nil { + got.TelemetryIngress.URL = new(models.URL) + } + cfgtest.AssertFieldsNotNil(t, got) } diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 59f48680939..7f37f4c849d 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -294,7 +294,7 @@ UseBatchSend = true # Default ``` UseBatchSend toggles sending telemetry to the ingress server using the batch client. -## TelemetryIngress.Endpoints]] # Example +## TelemetryIngress.Endpoints ```toml [[TelemetryIngress.Endpoints]] # Example Network = 'EVM' # Example