From b2c1a17cf529317d70674aa9f73596a4a426f418 Mon Sep 17 00:00:00 2001 From: JonWong203 <82334955+JonWong203@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:19:54 -0500 Subject: [PATCH] Automation Telemetry: Send BlockNumber and Node Version (#9927) * rebase on toml feature flag * fixes + send node version rebase on feature flag PR * fixes * comments * minor changes * lint * constant added * logger * toggle by feature flag * minor fixes * marshal error exits start() * marshal error fix * add automation custom telem to job * rename toml tag * test * removed print statement * merge * configDigest go routine getter * configDigest var * refactor1 * send NodeVersion msg every new ConfigDigest * lint * refactor * move registry creation outside delegate.go * plugin config bool flag * custom telem for 2.1 * block subscriber + thread controller * ContractConfigTracker * reset forge-std * use toml config flag * set toml flag default to true * plugin config bool flag * make generate * refactor * hourly node version msg * fix tests * lint fix * goimports fixed * goimport fix 2 --------- Co-authored-by: FelixFan1992 --- core/config/docs/core.toml | 2 +- core/services/chainlink/config_ocr2_test.go | 2 +- core/services/chainlink/config_test.go | 4 +- .../testdata/config-empty-effective.toml | 2 +- .../chainlink/testdata/config-full.toml | 2 +- .../config-multi-chain-effective.toml | 2 +- core/services/ocr2/delegate.go | 23 ++- .../ocr2/plugins/ocr2keeper/config.go | 2 + .../plugins/ocr2keeper/custom_telemetry.go | 156 +++++++++++++++++ .../ocr2keeper/custom_telemetry_test.go | 17 ++ .../evm21/autotelemetry21/custom_telemetry.go | 160 ++++++++++++++++++ .../autotelemetry21/custom_telemetry_test.go | 56 ++++++ .../testdata/config-empty-effective.toml | 2 +- core/web/resolver/testdata/config-full.toml | 2 +- .../config-multi-chain-effective.toml | 2 +- docs/CONFIG.md | 4 +- testdata/scripts/node/validate/default.txtar | 2 +- .../disk-based-logging-disabled.txtar | 2 +- .../validate/disk-based-logging-no-dir.txtar | 2 +- .../node/validate/disk-based-logging.txtar | 2 +- testdata/scripts/node/validate/invalid.txtar | 2 +- testdata/scripts/node/validate/valid.txtar | 2 +- testdata/scripts/node/validate/warnings.txtar | 2 +- 23 files changed, 431 insertions(+), 21 deletions(-) create mode 100644 core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go create mode 100644 core/services/ocr2/plugins/ocr2keeper/custom_telemetry_test.go create mode 100644 core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry.go create mode 100644 core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry_test.go diff --git a/core/config/docs/core.toml b/core/config/docs/core.toml index 0a8e6aba3be..148de90cd95 100644 --- a/core/config/docs/core.toml +++ b/core/config/docs/core.toml @@ -352,7 +352,7 @@ KeyBundleID = '7a5f66bbe6594259325bf2b4f5b1a9c900000000000000000000000000000000' # CaptureEATelemetry toggles collecting extra information from External Adaptares CaptureEATelemetry = false # Default # CaptureAutomationCustomTelemetry toggles collecting automation specific telemetry -CaptureAutomationCustomTelemetry = false # Default +CaptureAutomationCustomTelemetry = true # Default # DefaultTransactionQueueDepth controls the queue size for `DropOldestStrategy` in OCR2. Set to 0 to use `SendEvery` strategy instead. DefaultTransactionQueueDepth = 1 # Default # SimulateTransactions enables transaction simulation for OCR2. diff --git a/core/services/chainlink/config_ocr2_test.go b/core/services/chainlink/config_ocr2_test.go index 66427489241..5bf84934d13 100644 --- a/core/services/chainlink/config_ocr2_test.go +++ b/core/services/chainlink/config_ocr2_test.go @@ -38,7 +38,7 @@ func TestOCR2Config(t *testing.T) { require.Equal(t, false, ocr2Cfg.TraceLogging()) require.Equal(t, uint32(1), ocr2Cfg.DefaultTransactionQueueDepth()) require.Equal(t, false, ocr2Cfg.CaptureEATelemetry()) - require.Equal(t, false, ocr2Cfg.CaptureAutomationCustomTelemetry()) + require.Equal(t, true, ocr2Cfg.CaptureAutomationCustomTelemetry()) keyBundleID, err := ocr2Cfg.KeyBundleID() require.NoError(t, err) diff --git a/core/services/chainlink/config_test.go b/core/services/chainlink/config_test.go index 0caae3607f7..fbadb379cad 100644 --- a/core/services/chainlink/config_test.go +++ b/core/services/chainlink/config_test.go @@ -385,7 +385,7 @@ func TestConfig_Marshal(t *testing.T) { DatabaseTimeout: models.MustNewDuration(8 * time.Second), KeyBundleID: ptr(models.MustSha256HashFromHex("7a5f66bbe6594259325bf2b4f5b1a9c9")), CaptureEATelemetry: ptr(false), - CaptureAutomationCustomTelemetry: ptr(false), + CaptureAutomationCustomTelemetry: ptr(true), DefaultTransactionQueueDepth: ptr[uint32](1), SimulateTransactions: ptr(false), TraceLogging: ptr(false), @@ -848,7 +848,7 @@ ContractTransmitterTransmitTimeout = '1m0s' DatabaseTimeout = '8s' KeyBundleID = '7a5f66bbe6594259325bf2b4f5b1a9c900000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/core/services/chainlink/testdata/config-empty-effective.toml b/core/services/chainlink/testdata/config-empty-effective.toml index f5d775fe744..b897fba7f10 100644 --- a/core/services/chainlink/testdata/config-empty-effective.toml +++ b/core/services/chainlink/testdata/config-empty-effective.toml @@ -137,7 +137,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/core/services/chainlink/testdata/config-full.toml b/core/services/chainlink/testdata/config-full.toml index 5ede10ef695..531c98d7344 100644 --- a/core/services/chainlink/testdata/config-full.toml +++ b/core/services/chainlink/testdata/config-full.toml @@ -143,7 +143,7 @@ ContractTransmitterTransmitTimeout = '1m0s' DatabaseTimeout = '8s' KeyBundleID = '7a5f66bbe6594259325bf2b4f5b1a9c900000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/core/services/chainlink/testdata/config-multi-chain-effective.toml b/core/services/chainlink/testdata/config-multi-chain-effective.toml index 9dd0be8f5d2..c743601ced8 100644 --- a/core/services/chainlink/testdata/config-multi-chain-effective.toml +++ b/core/services/chainlink/testdata/config-multi-chain-effective.toml @@ -137,7 +137,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '20s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index 20c13512978..944c04c8d44 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -49,6 +49,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/median" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/mercury" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21" ocr2keeper21core "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21/core" ocr2vrfconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2vrf/config" ocr2coordinator "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2vrf/coordinator" @@ -174,6 +175,7 @@ type ocr2Config interface { DatabaseTimeout() time.Duration KeyBundleID() (string, error) TraceLogging() bool + CaptureAutomationCustomTelemetry() bool } type insecureConfig interface { @@ -1161,7 +1163,7 @@ func (d *Delegate) newServicesOCR2Keepers21( d.cfg.JobPipeline().MaxSuccessfulRuns(), ) - return []job.ServiceCtx{ + automationServices := []job.ServiceCtx{ runResultSaver, keeperProvider, services.Registry(), @@ -1171,7 +1173,24 @@ func (d *Delegate) newServicesOCR2Keepers21( services.UpkeepStateStore(), services.TransmitEventProvider(), pluginService, - }, nil + } + + if cfg.CaptureAutomationCustomTelemetry != nil && *cfg.CaptureAutomationCustomTelemetry || + cfg.CaptureAutomationCustomTelemetry == nil && d.cfg.OCR2().CaptureAutomationCustomTelemetry() { + endpoint := d.monitoringEndpointGen.GenMonitoringEndpoint(rid.Network, rid.ChainID, spec.ContractID, synchronization.AutomationCustom) + customTelemService, custErr := autotelemetry21.NewAutomationCustomTelemetryService( + endpoint, + lggr, + services.BlockSubscriber(), + keeperProvider.ContractConfigTracker(), + ) + if custErr != nil { + return nil, errors.Wrap(custErr, "Error when creating AutomationCustomTelemetryService") + } + automationServices = append(automationServices, customTelemService) + } + + return automationServices, nil } func (d *Delegate) newServicesOCR2Keepers20( diff --git a/core/services/ocr2/plugins/ocr2keeper/config.go b/core/services/ocr2/plugins/ocr2keeper/config.go index d3035878ece..ec56f9c6993 100644 --- a/core/services/ocr2/plugins/ocr2keeper/config.go +++ b/core/services/ocr2/plugins/ocr2keeper/config.go @@ -58,6 +58,8 @@ type PluginConfig struct { ServiceQueueLength int `json:"serviceQueueLength"` // ContractVersion is the contract version ContractVersion string `json:"contractVersion"` + // CaptureAutomationCustomTelemetry is a bool flag to toggle Custom Telemetry Service + CaptureAutomationCustomTelemetry *bool `json:"captureAutomationCustomTelemetry,omitempty"` } func ValidatePluginConfig(cfg PluginConfig) error { diff --git a/core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go b/core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go new file mode 100644 index 00000000000..0f03ae5bd06 --- /dev/null +++ b/core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go @@ -0,0 +1,156 @@ +package ocr2keeper + +import ( + "context" + "encoding/hex" + "time" + + "github.com/smartcontractkit/libocr/commontypes" + "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "google.golang.org/protobuf/proto" + + ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types" + + "github.com/smartcontractkit/chainlink/v2/core/logger" + evm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21" + "github.com/smartcontractkit/chainlink/v2/core/services/synchronization/telem" + "github.com/smartcontractkit/chainlink/v2/core/static" + "github.com/smartcontractkit/chainlink/v2/core/utils" +) + +type AutomationCustomTelemetryService struct { + utils.StartStopOnce + monitoringEndpoint commontypes.MonitoringEndpoint + blockSubscriber *evm21.BlockSubscriber + blockSubChanID int + threadCtrl utils.ThreadControl + lggr logger.Logger + configDigest [32]byte + contractConfigTracker types.ContractConfigTracker +} + +// NewAutomationCustomTelemetryService creates a telemetry service for new blocks and node version +func NewAutomationCustomTelemetryService(me commontypes.MonitoringEndpoint, + lggr logger.Logger, blocksub *evm21.BlockSubscriber, configTracker types.ContractConfigTracker) (*AutomationCustomTelemetryService, error) { + return &AutomationCustomTelemetryService{ + monitoringEndpoint: me, + threadCtrl: utils.NewThreadControl(), + lggr: lggr.Named("AutomationCustomTelem"), + contractConfigTracker: configTracker, + blockSubscriber: blocksub, + }, nil +} + +// Start starts Custom Telemetry Service, sends 1 NodeVersion message to endpoint at start and sends new BlockNumber messages +func (e *AutomationCustomTelemetryService) Start(ctx context.Context) error { + return e.StartOnce("AutomationCustomTelemetryService", func() error { + e.lggr.Infof("Starting: Custom Telemetry Service") + _, configDetails, err := e.contractConfigTracker.LatestConfigDetails(ctx) + if err != nil { + e.lggr.Errorf("Error occurred while getting newestConfigDetails for initialization %s", err) + } else { + e.configDigest = configDetails + e.sendNodeVersionMsg() + } + e.threadCtrl.Go(func(ctx context.Context) { + ticker := time.NewTicker(1 * time.Minute) + defer ticker.Stop() + for { + select { + case <-ticker.C: + _, newConfigDigest, err := e.contractConfigTracker.LatestConfigDetails(ctx) + if err != nil { + e.lggr.Errorf("Error occurred while getting newestConfigDetails in configDigest loop %s", err) + } + if newConfigDigest != e.configDigest { + e.configDigest = newConfigDigest + e.sendNodeVersionMsg() + } + case <-ctx.Done(): + return + } + } + }) + + chanID, blockSubscriberChan, blockSubErr := e.blockSubscriber.Subscribe() + if blockSubErr != nil { + e.lggr.Errorf("Block Subscriber Error: Subscribe(): %s", blockSubErr) + + } else { + e.blockSubChanID = chanID + e.threadCtrl.Go(func(ctx context.Context) { + e.lggr.Infof("Started: Sending BlockNumber Messages") + for { + select { + case blockHistory := <-blockSubscriberChan: + latestBlockKey, err := blockHistory.Latest() + if err != nil { + e.lggr.Errorf("BlockSubscriber BlockHistory.Latest() failed: %s", err) + continue + } + e.sendBlockNumberMsg(latestBlockKey) + case <-ctx.Done(): + return + } + } + }) + } + return nil + }) +} + +// Close stops go routines and closes channels +func (e *AutomationCustomTelemetryService) Close() error { + // use utils + return e.StopOnce("AutomationCustomTelemetryService", func() error { + e.lggr.Infof("Stopping: custom telemetry service") + e.threadCtrl.Close() + err := e.blockSubscriber.Unsubscribe(e.blockSubChanID) + if err != nil { + return err + } + e.lggr.Infof("Stopped: Custom telemetry service") + return nil + }) +} + +func (e *AutomationCustomTelemetryService) sendNodeVersionMsg() { + vMsg := &telem.NodeVersion{ + Timestamp: uint64(time.Now().UTC().UnixMilli()), + NodeVersion: static.Version, + ConfigDigest: e.configDigest[:], + } + wrappedVMsg := &telem.AutomationTelemWrapper{ + Msg: &telem.AutomationTelemWrapper_NodeVersion{ + NodeVersion: vMsg, + }, + } + bytes, err := proto.Marshal(wrappedVMsg) + if err != nil { + e.lggr.Errorf("Error occurred while marshalling the Node Version Message %s: %v", wrappedVMsg.String(), err) + } else { + e.monitoringEndpoint.SendLog(bytes) + e.lggr.Infof("NodeVersion Message Sent to Endpoint: %d", vMsg.Timestamp) + } +} + +func (e *AutomationCustomTelemetryService) sendBlockNumberMsg(blockKey ocr2keepers.BlockKey) { + blockNumMsg := &telem.BlockNumber{ + Timestamp: uint64(time.Now().UTC().UnixMilli()), + BlockNumber: uint64(blockKey.Number), + BlockHash: hex.EncodeToString(blockKey.Hash[:]), + ConfigDigest: e.configDigest[:], + } + wrappedBlockNumMsg := &telem.AutomationTelemWrapper{ + Msg: &telem.AutomationTelemWrapper_BlockNumber{ + BlockNumber: blockNumMsg, + }, + } + b, err := proto.Marshal(wrappedBlockNumMsg) + if err != nil { + e.lggr.Errorf("Error occurred while marshalling the Block Num Message %s: %v", wrappedBlockNumMsg.String(), err) + } else { + e.monitoringEndpoint.SendLog(b) + e.lggr.Infof("BlockNumber Message Sent to Endpoint: %d", blockNumMsg.Timestamp) + } +} diff --git a/core/services/ocr2/plugins/ocr2keeper/custom_telemetry_test.go b/core/services/ocr2/plugins/ocr2keeper/custom_telemetry_test.go new file mode 100644 index 00000000000..a40a3f3525d --- /dev/null +++ b/core/services/ocr2/plugins/ocr2keeper/custom_telemetry_test.go @@ -0,0 +1,17 @@ +package ocr2keeper + +import ( + "testing" +) + +func TestNewAutomationCustomTelemetryService(t *testing.T) { + // me := &MockMonitoringEndpoint{} + // lggr := &MockLogger{} + // blocksub := &MockBlockSubscriber{} + // configTracker := &MockContractConfigTracker{} + + // service, err := NewAutomationCustomTelemetryService(me, lggr, blocksub, configTracker) + // if err != nil { + // t.Errorf("Expected no error, but got: %v", err) + // } +} diff --git a/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry.go b/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry.go new file mode 100644 index 00000000000..93f35ce0d24 --- /dev/null +++ b/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry.go @@ -0,0 +1,160 @@ +package autotelemetry21 + +import ( + "context" + "encoding/hex" + "time" + + "github.com/smartcontractkit/libocr/commontypes" + "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "google.golang.org/protobuf/proto" + + ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types" + + "github.com/smartcontractkit/chainlink/v2/core/logger" + evm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21" + "github.com/smartcontractkit/chainlink/v2/core/services/synchronization/telem" + "github.com/smartcontractkit/chainlink/v2/core/static" + "github.com/smartcontractkit/chainlink/v2/core/utils" +) + +type AutomationCustomTelemetryService struct { + utils.StartStopOnce + monitoringEndpoint commontypes.MonitoringEndpoint + blockSubscriber *evm21.BlockSubscriber + blockSubChanID int + threadCtrl utils.ThreadControl + lggr logger.Logger + configDigest [32]byte + contractConfigTracker types.ContractConfigTracker +} + +// NewAutomationCustomTelemetryService creates a telemetry service for new blocks and node version +func NewAutomationCustomTelemetryService(me commontypes.MonitoringEndpoint, + lggr logger.Logger, blocksub *evm21.BlockSubscriber, configTracker types.ContractConfigTracker) (*AutomationCustomTelemetryService, error) { + return &AutomationCustomTelemetryService{ + monitoringEndpoint: me, + threadCtrl: utils.NewThreadControl(), + lggr: lggr.Named("AutomationCustomTelem"), + contractConfigTracker: configTracker, + blockSubscriber: blocksub, + }, nil +} + +// Start starts Custom Telemetry Service, sends 1 NodeVersion message to endpoint at start and sends new BlockNumber messages +func (e *AutomationCustomTelemetryService) Start(ctx context.Context) error { + return e.StartOnce("AutomationCustomTelemetryService", func() error { + e.lggr.Infof("Starting: Custom Telemetry Service") + _, configDetails, err := e.contractConfigTracker.LatestConfigDetails(ctx) + if err != nil { + e.lggr.Errorf("Error occurred while getting newestConfigDetails for initialization %s", err) + } else { + e.configDigest = configDetails + e.sendNodeVersionMsg() + } + e.threadCtrl.Go(func(ctx context.Context) { + minuteTicker := time.NewTicker(1 * time.Minute) + hourTicker := time.NewTicker(1 * time.Hour) + defer minuteTicker.Stop() + defer hourTicker.Stop() + for { + select { + case <-minuteTicker.C: + _, newConfigDigest, err := e.contractConfigTracker.LatestConfigDetails(ctx) + if err != nil { + e.lggr.Errorf("Error occurred while getting newestConfigDetails in configDigest loop %s", err) + } + if newConfigDigest != e.configDigest { + e.configDigest = newConfigDigest + e.sendNodeVersionMsg() + } + case <-hourTicker.C: + e.sendNodeVersionMsg() + case <-ctx.Done(): + return + } + } + }) + + chanID, blockSubscriberChan, blockSubErr := e.blockSubscriber.Subscribe() + if blockSubErr != nil { + e.lggr.Errorf("Block Subscriber Error: Subscribe(): %s", blockSubErr) + return blockSubErr + } + e.blockSubChanID = chanID + e.threadCtrl.Go(func(ctx context.Context) { + e.lggr.Debug("Started: Sending BlockNumber Messages") + for { + select { + case blockHistory := <-blockSubscriberChan: + // Exploratory: Debounce blocks to avoid overflow in case of re-org + latestBlockKey, err := blockHistory.Latest() + if err != nil { + e.lggr.Errorf("BlockSubscriber BlockHistory.Latest() failed: %s", err) + continue + } + e.sendBlockNumberMsg(latestBlockKey) + case <-ctx.Done(): + return + } + } + }) + return nil + }) +} + +// Close stops go routines and closes channels +func (e *AutomationCustomTelemetryService) Close() error { + return e.StopOnce("AutomationCustomTelemetryService", func() error { + e.lggr.Debug("Stopping: custom telemetry service") + e.threadCtrl.Close() + err := e.blockSubscriber.Unsubscribe(e.blockSubChanID) + if err != nil { + e.lggr.Errorf("Custom telemetry service encounters error %v when stopping", err) + return err + } + e.lggr.Infof("Stopped: Custom telemetry service") + return nil + }) +} + +func (e *AutomationCustomTelemetryService) sendNodeVersionMsg() { + vMsg := &telem.NodeVersion{ + Timestamp: uint64(time.Now().UTC().UnixMilli()), + NodeVersion: static.Version, + ConfigDigest: e.configDigest[:], + } + wrappedVMsg := &telem.AutomationTelemWrapper{ + Msg: &telem.AutomationTelemWrapper_NodeVersion{ + NodeVersion: vMsg, + }, + } + bytes, err := proto.Marshal(wrappedVMsg) + if err != nil { + e.lggr.Errorf("Error occurred while marshalling the Node Version Message %s: %v", wrappedVMsg.String(), err) + } else { + e.monitoringEndpoint.SendLog(bytes) + e.lggr.Debugf("NodeVersion Message Sent to Endpoint: %d", vMsg.Timestamp) + } +} + +func (e *AutomationCustomTelemetryService) sendBlockNumberMsg(blockKey ocr2keepers.BlockKey) { + blockNumMsg := &telem.BlockNumber{ + Timestamp: uint64(time.Now().UTC().UnixMilli()), + BlockNumber: uint64(blockKey.Number), + BlockHash: hex.EncodeToString(blockKey.Hash[:]), + ConfigDigest: e.configDigest[:], + } + wrappedBlockNumMsg := &telem.AutomationTelemWrapper{ + Msg: &telem.AutomationTelemWrapper_BlockNumber{ + BlockNumber: blockNumMsg, + }, + } + b, err := proto.Marshal(wrappedBlockNumMsg) + if err != nil { + e.lggr.Errorf("Error occurred while marshalling the Block Num Message %s: %v", wrappedBlockNumMsg.String(), err) + } else { + e.monitoringEndpoint.SendLog(b) + e.lggr.Debugf("BlockNumber Message Sent to Endpoint: %d", blockNumMsg.Timestamp) + } +} diff --git a/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry_test.go b/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry_test.go new file mode 100644 index 00000000000..4318d9aac60 --- /dev/null +++ b/core/services/ocr2/plugins/ocr2keeper/evm21/autotelemetry21/custom_telemetry_test.go @@ -0,0 +1,56 @@ +package autotelemetry21 + +import ( + "sync" + "testing" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "github.com/stretchr/testify/assert" + + headtracker "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" + "github.com/smartcontractkit/chainlink/v2/core/logger" + evm "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21" +) + +// const historySize = 4 +// const blockSize = int64(4) +const finality = uint32(4) + +func TestNewAutomationCustomTelemetryService(t *testing.T) { + me := &MockMonitoringEndpoint{} + lggr := logger.TestLogger(t) + var hb headtracker.HeadBroadcaster + var lp logpoller.LogPoller + + bs := evm.NewBlockSubscriber(hb, lp, finality, lggr) + // configTracker := &MockContractConfigTracker{} + var configTracker types.ContractConfigTracker + + service, err := NewAutomationCustomTelemetryService(me, lggr, bs, configTracker) + if err != nil { + t.Errorf("Expected no error, but got: %v", err) + } + service.monitoringEndpoint.SendLog([]byte("test")) + assert.Equal(t, me.LogCount(), 1) + service.monitoringEndpoint.SendLog([]byte("test2")) + assert.Equal(t, me.LogCount(), 2) + service.Close() +} + +type MockMonitoringEndpoint struct { + sentLogs [][]byte + lock sync.RWMutex +} + +func (me *MockMonitoringEndpoint) SendLog(log []byte) { + me.lock.Lock() + defer me.lock.Unlock() + me.sentLogs = append(me.sentLogs, log) +} + +func (me *MockMonitoringEndpoint) LogCount() int { + me.lock.RLock() + defer me.lock.RUnlock() + return len(me.sentLogs) +} diff --git a/core/web/resolver/testdata/config-empty-effective.toml b/core/web/resolver/testdata/config-empty-effective.toml index f5d775fe744..b897fba7f10 100644 --- a/core/web/resolver/testdata/config-empty-effective.toml +++ b/core/web/resolver/testdata/config-empty-effective.toml @@ -137,7 +137,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/core/web/resolver/testdata/config-full.toml b/core/web/resolver/testdata/config-full.toml index 95d898c353b..6cd6eaabc3c 100644 --- a/core/web/resolver/testdata/config-full.toml +++ b/core/web/resolver/testdata/config-full.toml @@ -143,7 +143,7 @@ ContractTransmitterTransmitTimeout = '1m0s' DatabaseTimeout = '8s' KeyBundleID = '7a5f66bbe6594259325bf2b4f5b1a9c900000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/core/web/resolver/testdata/config-multi-chain-effective.toml b/core/web/resolver/testdata/config-multi-chain-effective.toml index 9dd0be8f5d2..c743601ced8 100644 --- a/core/web/resolver/testdata/config-multi-chain-effective.toml +++ b/core/web/resolver/testdata/config-multi-chain-effective.toml @@ -137,7 +137,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '20s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 1eb9cd5023d..5b93c7061e8 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -890,7 +890,7 @@ ContractTransmitterTransmitTimeout = '10s' # Default DatabaseTimeout = '10s' # Default KeyBundleID = '7a5f66bbe6594259325bf2b4f5b1a9c900000000000000000000000000000000' # Example CaptureEATelemetry = false # Default -CaptureAutomationCustomTelemetry = false # Default +CaptureAutomationCustomTelemetry = true # Default DefaultTransactionQueueDepth = 1 # Default SimulateTransactions = false # Default TraceLogging = false # Default @@ -987,7 +987,7 @@ CaptureEATelemetry toggles collecting extra information from External Adaptares ### CaptureAutomationCustomTelemetry ```toml -CaptureAutomationCustomTelemetry = false # Default +CaptureAutomationCustomTelemetry = true # Default ``` CaptureAutomationCustomTelemetry toggles collecting automation specific telemetry diff --git a/testdata/scripts/node/validate/default.txtar b/testdata/scripts/node/validate/default.txtar index 8a3b1af96fa..01e96ac944d 100644 --- a/testdata/scripts/node/validate/default.txtar +++ b/testdata/scripts/node/validate/default.txtar @@ -149,7 +149,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/testdata/scripts/node/validate/disk-based-logging-disabled.txtar b/testdata/scripts/node/validate/disk-based-logging-disabled.txtar index 31fded1b423..1f6901e9ffd 100644 --- a/testdata/scripts/node/validate/disk-based-logging-disabled.txtar +++ b/testdata/scripts/node/validate/disk-based-logging-disabled.txtar @@ -193,7 +193,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/testdata/scripts/node/validate/disk-based-logging-no-dir.txtar b/testdata/scripts/node/validate/disk-based-logging-no-dir.txtar index 78fc976912c..4c1a1c75fc3 100644 --- a/testdata/scripts/node/validate/disk-based-logging-no-dir.txtar +++ b/testdata/scripts/node/validate/disk-based-logging-no-dir.txtar @@ -193,7 +193,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/testdata/scripts/node/validate/disk-based-logging.txtar b/testdata/scripts/node/validate/disk-based-logging.txtar index 226a7bbb3b4..536b7d8ac08 100644 --- a/testdata/scripts/node/validate/disk-based-logging.txtar +++ b/testdata/scripts/node/validate/disk-based-logging.txtar @@ -193,7 +193,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/testdata/scripts/node/validate/invalid.txtar b/testdata/scripts/node/validate/invalid.txtar index 5cd3d567467..89f59574fcc 100644 --- a/testdata/scripts/node/validate/invalid.txtar +++ b/testdata/scripts/node/validate/invalid.txtar @@ -183,7 +183,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/testdata/scripts/node/validate/valid.txtar b/testdata/scripts/node/validate/valid.txtar index fd24150b587..2d32b39a644 100644 --- a/testdata/scripts/node/validate/valid.txtar +++ b/testdata/scripts/node/validate/valid.txtar @@ -190,7 +190,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false diff --git a/testdata/scripts/node/validate/warnings.txtar b/testdata/scripts/node/validate/warnings.txtar index 828d953da9a..e478203e00e 100644 --- a/testdata/scripts/node/validate/warnings.txtar +++ b/testdata/scripts/node/validate/warnings.txtar @@ -186,7 +186,7 @@ ContractTransmitterTransmitTimeout = '10s' DatabaseTimeout = '10s' KeyBundleID = '0000000000000000000000000000000000000000000000000000000000000000' CaptureEATelemetry = false -CaptureAutomationCustomTelemetry = false +CaptureAutomationCustomTelemetry = true DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false