Skip to content

Commit 1f6896d

Browse files
committed
Update so that telemetry can still be configured the old way
1 parent 5575784 commit 1f6896d

File tree

6 files changed

+118
-31
lines changed

6 files changed

+118
-31
lines changed

core/config/telemetry_ingress_config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type TelemetryIngress interface {
1717
UseBatchSend() bool
1818
Endpoints() []TelemetryIngressEndpoint
1919

20-
ServerPubKey() string // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, if this field is set it will trigger an error, only used to warn NOPs of change
21-
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
20+
ServerPubKey() string // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, this field will be removed in future versions
21+
URL() *url.URL // Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
2222
}
2323

2424
//go:generate mockery --quiet --name TelemetryIngressEndpoint --output ./mocks/ --case=underscore --filename telemetry_ingress_endpoint.go

core/config/toml/types.go

+5-21
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ type TelemetryIngress struct {
433433
UseBatchSend *bool
434434
Endpoints []TelemetryIngressEndpoint `toml:",omitempty"`
435435

436-
URL *models.URL `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.URL instead, if this field is set it will trigger an error, only used to warn NOPs of change
437-
ServerPubKey *string `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, if this field is set it will trigger an error, only used to warn NOPs of change
436+
URL *models.URL `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
437+
ServerPubKey *string `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, this field will be removed in future versions
438438
}
439439

440440
type TelemetryIngressEndpoint struct {
@@ -478,30 +478,14 @@ func (t *TelemetryIngress) setFrom(f *TelemetryIngress) {
478478
}
479479

480480
func (t *TelemetryIngress) ValidateConfig() (err error) {
481-
if !t.URL.IsZero() && *t.ServerPubKey != "" {
481+
if (!t.URL.IsZero() || *t.ServerPubKey != "") && len(t.Endpoints) > 0 {
482482
return configutils.ErrInvalid{Name: "URL", Value: t.URL.String(),
483-
Msg: fmt.Sprintf(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey are no longer allowed. Please use TelemetryIngress.Endpoints instead:
484-
[[TelemetryIngress.Endpoints]]
485-
Network = '...' # e.g. EVM. Solana, Starknet, Cosmos
486-
ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
487-
URL = '%s'
488-
ServerPubKey = '%s'`, t.URL.String(), *t.ServerPubKey)}
489-
} else if !t.URL.IsZero() {
490-
return configutils.ErrInvalid{Name: "URL", Value: t.URL.String(),
491-
Msg: fmt.Sprintf(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey are no longer allowed. Please use TelemetryIngress.Endpoints instead:
492-
[[TelemetryIngress.Endpoints]]
493-
Network = '...' # e.g. EVM. Solana, Starknet, Cosmos
494-
ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
495-
URL = '%s'
496-
ServerPubKey = '...'`, t.URL.String())}
497-
} else if *t.ServerPubKey != "" {
498-
return configutils.ErrInvalid{Name: "ServerPubKey", Value: *t.ServerPubKey,
499-
Msg: fmt.Sprintf(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey are no longer allowed. Please use TelemetryIngress.Endpoints instead:
483+
Msg: `Cannot set both TelemetryIngress.URL and TelemetryIngress.ServerPubKey alongside TelemetryIngress.Endpoints. Please use only TelemetryIngress.Endpoints:
500484
[[TelemetryIngress.Endpoints]]
501485
Network = '...' # e.g. EVM. Solana, Starknet, Cosmos
502486
ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
503487
URL = '...'
504-
ServerPubKey = '%s'`, *t.ServerPubKey)}
488+
ServerPubKey = '...'`}
505489
}
506490

507491
return nil

core/services/chainlink/config_telemetry_ingress.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func (t *telemetryIngressConfig) UseBatchSend() bool {
4646
return *t.c.UseBatchSend
4747
}
4848

49-
// Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, if this field is set it will trigger an error, only used to warn NOPs of change
49+
// Deprecated: Use TelemetryIngressEndpoint.ServerPubKey, this field will be removed in future versions
5050
func (t *telemetryIngressConfig) ServerPubKey() string {
5151
return *t.c.ServerPubKey
5252
}
5353

54-
// Deprecated: Use TelemetryIngressEndpoint.URL instead, if this field is set it will trigger an error, only used to warn NOPs of change
54+
// Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
5555
func (t *telemetryIngressConfig) URL() *url.URL {
5656
return t.c.URL.URL()
5757
}

core/services/telemetry/manager.go

+51-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ type Manager struct {
3838
uniConn bool
3939
useBatchSend bool
4040
MonitoringEndpointGenerator MonitoringEndpointGenerator
41+
42+
//legacyMode means that we are sending all telemetry to a single endpoint.
43+
//In order for this to be set as true, we need to have no endpoints defined with TelemetryIngress.URL and TelemetryIngress.ServerPubKey set.
44+
//This mode will be supported until we completely switch to TelemetryIngress.Endpoints in config.toml
45+
legacyMode bool
46+
}
47+
48+
type legacyEndpointConfig struct {
49+
Url *url.URL
50+
PubKey string
51+
}
52+
53+
func (l *legacyEndpointConfig) Network() string {
54+
return "-"
55+
}
56+
57+
func (l *legacyEndpointConfig) ChainID() string {
58+
return "-"
59+
}
60+
61+
func (l *legacyEndpointConfig) ServerPubKey() string {
62+
return l.PubKey
63+
}
64+
65+
func (l *legacyEndpointConfig) URL() *url.URL {
66+
return l.Url
4167
}
4268

4369
type telemetryEndpoint struct {
@@ -62,13 +88,30 @@ func NewManager(cfg config.TelemetryIngress, csaKeyStore keystore.CSA, lggr logg
6288
sendTimeout: cfg.SendTimeout(),
6389
uniConn: cfg.UniConn(),
6490
useBatchSend: cfg.UseBatchSend(),
91+
legacyMode: false,
6592
}
6693
for _, e := range cfg.Endpoints() {
6794
if err := m.addEndpoint(e); err != nil {
68-
m.lggr.Error(err.Error())
95+
m.lggr.Error(err)
6996
}
97+
}
7098

99+
if len(cfg.Endpoints()) == 0 && cfg.URL() != nil && cfg.ServerPubKey() != "" {
100+
m.lggr.Error(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey will be removed in a future version, please switch to TelemetryIngress.Endpoints:
101+
[[TelemetryIngress.Endpoints]]
102+
Network = '...' # e.g. EVM. Solana, Starknet, Cosmos
103+
ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
104+
URL = '...'
105+
ServerPubKey = '...'`)
106+
m.legacyMode = true
107+
if err := m.addEndpoint(&legacyEndpointConfig{
108+
Url: cfg.URL(),
109+
PubKey: cfg.ServerPubKey(),
110+
}); err != nil {
111+
m.lggr.Error(err)
112+
}
71113
}
114+
72115
return m
73116
}
74117

@@ -124,11 +167,11 @@ func (m *Manager) GenMonitoringEndpoint(contractID string, telemType synchroniza
124167
}
125168

126169
func (m *Manager) addEndpoint(e config.TelemetryIngressEndpoint) error {
127-
if e.Network() == "" {
170+
if e.Network() == "" && !m.legacyMode {
128171
return errors.New("cannot add telemetry endpoint, network cannot be empty")
129172
}
130173

131-
if e.ChainID() == "" {
174+
if e.ChainID() == "" && !m.legacyMode {
132175
return errors.New("cannot add telemetry endpoint, chainID cannot be empty")
133176
}
134177

@@ -164,6 +207,11 @@ func (m *Manager) addEndpoint(e config.TelemetryIngressEndpoint) error {
164207
}
165208

166209
func (m *Manager) getEndpoint(network string, chainID string) (*telemetryEndpoint, bool) {
210+
//in legacy mode we send telemetry to a single endpoint
211+
if m.legacyMode && len(m.endpoints) == 1 {
212+
return m.endpoints[0], true
213+
}
214+
167215
for _, e := range m.endpoints {
168216
if e.Network == strings.ToUpper(network) && e.ChainID == strings.ToUpper(chainID) {
169217
return e, true

core/services/telemetry/manager_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
mocks3 "github.com/smartcontractkit/chainlink/v2/core/services/keystore/mocks"
2323
"github.com/smartcontractkit/chainlink/v2/core/services/synchronization"
2424
mocks2 "github.com/smartcontractkit/chainlink/v2/core/services/synchronization/mocks"
25+
"github.com/smartcontractkit/chainlink/v2/core/store/models"
2526
"github.com/smartcontractkit/chainlink/v2/core/utils"
2627
)
2728

@@ -200,6 +201,7 @@ func TestNewManager(t *testing.T) {
200201
func TestCorrectEndpointRouting(t *testing.T) {
201202
tic := setupMockConfig(t, true)
202203
tic.On("Endpoints").Return(nil)
204+
tic.On("URL").Return(nil)
203205

204206
lggr, obsLogs := logger.TestLoggerObserved(t, zapcore.InfoLevel)
205207
ks := mocks3.NewCSA(t)
@@ -286,3 +288,54 @@ func TestCorrectEndpointRouting(t *testing.T) {
286288
}
287289

288290
}
291+
292+
func TestLegacyMode(t *testing.T) {
293+
tic := setupMockConfig(t, true)
294+
tic.On("Endpoints").Return(nil)
295+
url, err := models.ParseURL("test.test")
296+
require.NoError(t, err)
297+
tic.On("URL").Return(url.URL())
298+
tic.On("ServerPubKey").Return("some-pub-key")
299+
300+
lggr, obsLogs := logger.TestLoggerObserved(t, zapcore.InfoLevel)
301+
ks := mocks3.NewCSA(t)
302+
303+
tm := NewManager(tic, ks, lggr)
304+
require.Equal(t, true, tm.legacyMode)
305+
require.Len(t, tm.endpoints, 1)
306+
307+
clientSent := make([]synchronization.TelemPayload, 0)
308+
clientMock := mocks2.NewTelemetryService(t)
309+
clientMock.On("Send", mock.Anything, mock.AnythingOfType("[]uint8"), mock.AnythingOfType("string"), mock.AnythingOfType("TelemetryType")).Return().Run(func(args mock.Arguments) {
310+
clientSent = append(clientSent, synchronization.TelemPayload{
311+
Telemetry: args[1].([]byte),
312+
ContractID: args[2].(string),
313+
TelemType: args[3].(synchronization.TelemetryType),
314+
})
315+
})
316+
tm.endpoints[0].client = clientMock
317+
318+
e := tm.GenMonitoringEndpoint("some-contractID", "some-type", "unknown-network", "unknown-chainID")
319+
require.Equal(t, "*telemetry.IngressAgentBatch", reflect.TypeOf(e).String())
320+
321+
e.SendLog([]byte("endpoint-1-message-1"))
322+
e.SendLog([]byte("endpoint-1-message-2"))
323+
e.SendLog([]byte("endpoint-1-message-3"))
324+
require.Len(t, clientSent, 3)
325+
326+
e2 := tm.GenMonitoringEndpoint("another-contractID", "another-type", "another-unknown-network", "another-unknown-chainID")
327+
require.Equal(t, "*telemetry.IngressAgentBatch", reflect.TypeOf(e).String())
328+
329+
e2.SendLog([]byte("endpoint-2-message-1"))
330+
e2.SendLog([]byte("endpoint-2-message-2"))
331+
e2.SendLog([]byte("endpoint-2-message-3"))
332+
require.Len(t, clientSent, 6)
333+
334+
require.Equal(t, 1, obsLogs.Len()) // Deprecation warning for TelemetryIngress.URL and TelemetryIngress.ServerPubKey
335+
require.Equal(t, []byte("endpoint-1-message-1"), clientSent[0].Telemetry)
336+
require.Equal(t, []byte("endpoint-1-message-2"), clientSent[1].Telemetry)
337+
require.Equal(t, []byte("endpoint-1-message-3"), clientSent[2].Telemetry)
338+
require.Equal(t, []byte("endpoint-2-message-1"), clientSent[3].Telemetry)
339+
require.Equal(t, []byte("endpoint-2-message-2"), clientSent[4].Telemetry)
340+
require.Equal(t, []byte("endpoint-2-message-3"), clientSent[5].Telemetry)
341+
}

docs/CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
2020
URL = '...'
2121
ServerPubKey = '...'
2222
```
23-
These replace `TelemetryIngress.URL` and `TelemetryIngress.ServerPubKey`, which are no longer allowed.
23+
These will eventually replace `TelemetryIngress.URL` and `TelemetryIngress.ServerPubKey`. Setting `TelemetryIngress.URL` and `TelemetryIngress.ServerPubKey` alongside `[[TelemetryIngress.Endpoints]]` will prevent the node from booting. Only one way of configuring telemetry endpoints is supported.
24+
25+
### Upcoming Required Configuration Change
26+
27+
- Starting in 2.8.0, chainlink nodes will no longer allow `TelemetryIngress.URL` and `TelemetryIngress.ServerPubKey`. Any TOML configuration that sets this fields will prevent the node from booting. These fields will be replaced by `[[TelemetryIngress.Endpoints]]`
2428

2529
## 2.6.0 - UNRELEASED
2630

@@ -43,8 +47,6 @@ All nodes will have to remove the following secret configurations:
4347

4448
All nodes will have to remove the following configuration field: `ExplorerURL`
4549

46-
- Removed `TelemetryIngress.URL` and `TelemetryIngress.ServerPubKey`. They are no longer valid, and will prevent a node from booting. Use `TelemetryIngress.Endpoints` instead.
47-
4850
### Fixed
4951

5052
- Unauthenticated users executing CLI commands previously generated a confusing error log, which is now removed:

0 commit comments

Comments
 (0)