Skip to content

Commit

Permalink
Remove old way of configuring telemetry pubkey and url
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin committed Jan 15, 2024
1 parent c32efca commit 7c440eb
Show file tree
Hide file tree
Showing 22 changed files with 2 additions and 213 deletions.
4 changes: 0 additions & 4 deletions core/config/docs/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ LeaseRefreshInterval = '1s' # Default
UniConn = true # Default
# Logging toggles verbose logging of the raw telemetry messages being sent.
Logging = false # Default
# ServerPubKey is the public key of the telemetry server. This field will be removed in a furture version
ServerPubKey = 'test-pub-key' # Example
# URL is where to send telemetry. This field will be removed in a furture version
URL = 'https://prom.test' # Example
# BufferSize is the number of telemetry messages to buffer before dropping new ones.
BufferSize = 100 # Default
# MaxBatchSize is the maximum number of messages to batch into one telemetry request.
Expand Down
7 changes: 0 additions & 7 deletions core/config/docs/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
stkcfg "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config"

"github.com/smartcontractkit/chainlink-common/pkg/config"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/config/docs"
Expand All @@ -38,12 +37,6 @@ 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(commonconfig.URL)

cfgtest.AssertFieldsNotNil(t, c)

var defaults chainlink.Config
Expand Down
3 changes: 0 additions & 3 deletions core/config/telemetry_ingress_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ type TelemetryIngress interface {
SendTimeout() time.Duration
UseBatchSend() bool
Endpoints() []TelemetryIngressEndpoint

ServerPubKey() string // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, this field will be removed in future versions
URL() *url.URL // Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
}

//go:generate mockery --quiet --name TelemetryIngressEndpoint --output ./mocks/ --case=underscore --filename telemetry_ingress_endpoint.go
Expand Down
23 changes: 0 additions & 23 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,6 @@ type TelemetryIngress struct {
SendTimeout *commonconfig.Duration
UseBatchSend *bool
Endpoints []TelemetryIngressEndpoint `toml:",omitempty"`

URL *commonconfig.URL `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
ServerPubKey *string `toml:",omitempty"` // Deprecated: Use TelemetryIngressEndpoint.ServerPubKey instead, this field will be removed in future versions
}

type TelemetryIngressEndpoint struct {
Expand Down Expand Up @@ -475,26 +472,6 @@ 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 != "") && len(t.Endpoints) > 0 {
return configutils.ErrInvalid{Name: "URL", Value: t.URL.String(),
Msg: `Cannot set both TelemetryIngress.URL and TelemetryIngress.ServerPubKey alongside TelemetryIngress.Endpoints. Please use only TelemetryIngress.Endpoints:
[[TelemetryIngress.Endpoints]]
Network = '...' # e.g. EVM. Solana, Starknet, Cosmos
ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
URL = '...'
ServerPubKey = '...'`}
}

return nil
}

type AuditLogger struct {
Expand Down
10 changes: 0 additions & 10 deletions core/services/chainlink/config_telemetry_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ func (t *telemetryIngressConfig) UseBatchSend() bool {
return *t.c.UseBatchSend
}

// Deprecated: Use TelemetryIngressEndpoint.ServerPubKey, this field will be removed in future versions
func (t *telemetryIngressConfig) ServerPubKey() string {
return *t.c.ServerPubKey
}

// Deprecated: Use TelemetryIngressEndpoint.URL instead, this field will be removed in future versions
func (t *telemetryIngressConfig) URL() *url.URL {
return t.c.URL.URL()
}

func (t *telemetryIngressConfig) Endpoints() []config.TelemetryIngressEndpoint {
var endpoints []config.TelemetryIngressEndpoint
for _, e := range t.c.Endpoints {
Expand Down
15 changes: 0 additions & 15 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ func TestConfig_Marshal(t *testing.T) {
SendInterval: commonconfig.MustNewDuration(time.Minute),
SendTimeout: commonconfig.MustNewDuration(5 * time.Second),
UseBatchSend: ptr(true),
URL: ptr(commonconfig.URL{}),
ServerPubKey: ptr(""),
Endpoints: []toml.TelemetryIngressEndpoint{{
Network: ptr("EVM"),
ChainID: ptr("1"),
Expand Down Expand Up @@ -744,8 +742,6 @@ MaxBatchSize = 4321
SendInterval = '1m0s'
SendTimeout = '5s'
UseBatchSend = true
URL = ''
ServerPubKey = ''
[[TelemetryIngress.Endpoints]]
Network = 'EVM'
Expand Down Expand Up @@ -1141,17 +1137,6 @@ 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(commonconfig.URL)
}

cfgtest.AssertFieldsNotNil(t, got)
}

Expand Down
2 changes: 0 additions & 2 deletions core/services/chainlink/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MaxBatchSize = 50
SendInterval = '500ms'
SendTimeout = '10s'
UseBatchSend = true
URL = ''
ServerPubKey = ''

[AuditLogger]
Enabled = false
Expand Down
2 changes: 0 additions & 2 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MaxBatchSize = 4321
SendInterval = '1m0s'
SendTimeout = '5s'
UseBatchSend = true
URL = ''
ServerPubKey = ''

[[TelemetryIngress.Endpoints]]
Network = 'EVM'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MaxBatchSize = 50
SendInterval = '500ms'
SendTimeout = '10s'
UseBatchSend = true
URL = ''
ServerPubKey = ''

[AuditLogger]
Enabled = true
Expand Down
60 changes: 2 additions & 58 deletions core/services/telemetry/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/synchronization"
)

//// Client encapsulates all the functionality needed to
//// send telemetry to the ingress server using wsrpc
//type Client interface {
// services.ServiceCtx
// Send(context.Context, synchronization.TelemPayload)
//}

type Manager struct {
services.StateMachine
bufferSize uint
Expand All @@ -38,32 +31,6 @@ type Manager struct {
uniConn bool
useBatchSend bool
MonitoringEndpointGenerator MonitoringEndpointGenerator

//legacyMode means that we are sending all telemetry to a single endpoint.
//In order for this to be set as true, we need to have no endpoints defined with TelemetryIngress.URL and TelemetryIngress.ServerPubKey set.
//This mode will be supported until we completely switch to TelemetryIngress.Endpoints in config.toml
legacyMode bool
}

type legacyEndpointConfig struct {
Url *url.URL
PubKey string
}

func (l *legacyEndpointConfig) Network() string {
return "-"
}

func (l *legacyEndpointConfig) ChainID() string {
return "-"
}

func (l *legacyEndpointConfig) ServerPubKey() string {
return l.PubKey
}

func (l *legacyEndpointConfig) URL() *url.URL {
return l.Url
}

type telemetryEndpoint struct {
Expand All @@ -87,30 +54,12 @@ func NewManager(cfg config.TelemetryIngress, csaKeyStore keystore.CSA, lggr logg
sendTimeout: cfg.SendTimeout(),
uniConn: cfg.UniConn(),
useBatchSend: cfg.UseBatchSend(),
legacyMode: false,
}
for _, e := range cfg.Endpoints() {
if err := m.addEndpoint(e); err != nil {
m.lggr.Error(err)
}
}

if len(cfg.Endpoints()) == 0 && cfg.URL() != nil && cfg.ServerPubKey() != "" {
m.lggr.Error(`TelemetryIngress.URL and TelemetryIngress.ServerPubKey will be removed in a future version, please switch to TelemetryIngress.Endpoints:
[[TelemetryIngress.Endpoints]]
Network = '...' # e.g. EVM. Solana, Starknet, Cosmos
ChainID = '...' # e.g. 1, 5, devnet, mainnet-beta
URL = '...'
ServerPubKey = '...'`)
m.legacyMode = true
if err := m.addEndpoint(&legacyEndpointConfig{
Url: cfg.URL(),
PubKey: cfg.ServerPubKey(),
}); err != nil {
m.lggr.Error(err)
}
}

return m
}

Expand Down Expand Up @@ -165,11 +114,11 @@ func (m *Manager) GenMonitoringEndpoint(network string, chainID string, contract
}

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

if e.ChainID() == "" && !m.legacyMode {
if e.ChainID() == "" {
return errors.New("cannot add telemetry endpoint, chainID cannot be empty")
}

Expand Down Expand Up @@ -205,11 +154,6 @@ func (m *Manager) addEndpoint(e config.TelemetryIngressEndpoint) error {
}

func (m *Manager) getEndpoint(network string, chainID string) (*telemetryEndpoint, bool) {
//in legacy mode we send telemetry to a single endpoint
if m.legacyMode && len(m.endpoints) == 1 {
return m.endpoints[0], true
}

for _, e := range m.endpoints {
if e.Network == strings.ToUpper(network) && e.ChainID == strings.ToUpper(chainID) {
return e, true
Expand Down
53 changes: 0 additions & 53 deletions core/services/telemetry/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/mocks"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
Expand Down Expand Up @@ -201,7 +199,6 @@ func TestNewManager(t *testing.T) {
func TestCorrectEndpointRouting(t *testing.T) {
tic := setupMockConfig(t, true)
tic.On("Endpoints").Return(nil)
tic.On("URL").Return(nil)

lggr, obsLogs := logger.TestLoggerObserved(t, zapcore.InfoLevel)
ks := mocks3.NewCSA(t)
Expand Down Expand Up @@ -287,53 +284,3 @@ func TestCorrectEndpointRouting(t *testing.T) {
}

}

func TestLegacyMode(t *testing.T) {
tic := setupMockConfig(t, true)
tic.On("Endpoints").Return(nil)
url, err := commonconfig.ParseURL("test.test")
require.NoError(t, err)
tic.On("URL").Return(url.URL())
tic.On("ServerPubKey").Return("some-pub-key")

lggr, obsLogs := logger.TestLoggerObserved(t, zapcore.InfoLevel)
ks := mocks3.NewCSA(t)

tm := NewManager(tic, ks, lggr)
require.Equal(t, true, tm.legacyMode)
require.Len(t, tm.endpoints, 1)

var clientSent []synchronization.TelemPayload
clientMock := mocks2.NewTelemetryService(t)
clientMock.On("Send", mock.Anything, mock.AnythingOfType("[]uint8"), mock.AnythingOfType("string"), mock.AnythingOfType("TelemetryType")).Return().Run(func(args mock.Arguments) {
clientSent = append(clientSent, synchronization.TelemPayload{
Telemetry: args[1].([]byte),
ContractID: args[2].(string),
TelemType: args[3].(synchronization.TelemetryType),
})
})
tm.endpoints[0].client = clientMock

e := tm.GenMonitoringEndpoint("unknown-network", "unknown-chainID", "some-contractID", "some-type")
require.Equal(t, "*telemetry.IngressAgentBatch", reflect.TypeOf(e).String())

e.SendLog([]byte("endpoint-1-message-1"))
e.SendLog([]byte("endpoint-1-message-2"))
e.SendLog([]byte("endpoint-1-message-3"))
require.Len(t, clientSent, 3)

e2 := tm.GenMonitoringEndpoint("another-unknown-network", "another-unknown-chainID", "another-contractID", "another-type")
require.Equal(t, "*telemetry.IngressAgentBatch", reflect.TypeOf(e).String())

e2.SendLog([]byte("endpoint-2-message-1"))
e2.SendLog([]byte("endpoint-2-message-2"))
e2.SendLog([]byte("endpoint-2-message-3"))
require.Len(t, clientSent, 6)
assert.Equal(t, []byte("endpoint-1-message-1"), clientSent[0].Telemetry)
assert.Equal(t, []byte("endpoint-1-message-2"), clientSent[1].Telemetry)
assert.Equal(t, []byte("endpoint-1-message-3"), clientSent[2].Telemetry)
assert.Equal(t, []byte("endpoint-2-message-1"), clientSent[3].Telemetry)
assert.Equal(t, []byte("endpoint-2-message-2"), clientSent[4].Telemetry)
assert.Equal(t, []byte("endpoint-2-message-3"), clientSent[5].Telemetry)
assert.Equal(t, 1, obsLogs.Len()) // Deprecation warning for TelemetryIngress.URL and TelemetryIngress.ServerPubKey
}
2 changes: 0 additions & 2 deletions core/web/resolver/testdata/config-empty-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MaxBatchSize = 50
SendInterval = '500ms'
SendTimeout = '10s'
UseBatchSend = true
URL = ''
ServerPubKey = ''

[AuditLogger]
Enabled = false
Expand Down
2 changes: 0 additions & 2 deletions core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MaxBatchSize = 4321
SendInterval = '1m0s'
SendTimeout = '5s'
UseBatchSend = true
URL = ''
ServerPubKey = ''

[[TelemetryIngress.Endpoints]]
Network = 'EVM'
Expand Down
2 changes: 0 additions & 2 deletions core/web/resolver/testdata/config-multi-chain-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MaxBatchSize = 50
SendInterval = '500ms'
SendTimeout = '10s'
UseBatchSend = true
URL = ''
ServerPubKey = ''

[AuditLogger]
Enabled = true
Expand Down
14 changes: 0 additions & 14 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ LeaseRefreshInterval determines how often to refresh the lease lock. Also contro
[TelemetryIngress]
UniConn = true # Default
Logging = false # Default
ServerPubKey = 'test-pub-key' # Example
URL = 'https://prom.test' # Example
BufferSize = 100 # Default
MaxBatchSize = 50 # Default
SendInterval = '500ms' # Default
Expand All @@ -266,18 +264,6 @@ Logging = false # Default
```
Logging toggles verbose logging of the raw telemetry messages being sent.

### ServerPubKey
```toml
ServerPubKey = 'test-pub-key' # Example
```
ServerPubKey is the public key of the telemetry server. This field will be removed in a furture version

### URL
```toml
URL = 'https://prom.test' # Example
```
URL is where to send telemetry. This field will be removed in a furture version

### BufferSize
```toml
BufferSize = 100 # Default
Expand Down
Loading

0 comments on commit 7c440eb

Please sign in to comment.