From 97bef085e4bc8db0f8e156f552fb5661ba7697c6 Mon Sep 17 00:00:00 2001 From: Akshay Aggarwal Date: Fri, 1 Dec 2023 21:23:47 +0530 Subject: [PATCH] Delete unused custom telemetry files (#11441) --- .../plugins/ocr2keeper/custom_telemetry.go | 159 ------------------ .../ocr2keeper/custom_telemetry_test.go | 17 -- 2 files changed, 176 deletions(-) delete mode 100644 core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go delete mode 100644 core/services/ocr2/plugins/ocr2keeper/custom_telemetry_test.go diff --git a/core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go b/core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go deleted file mode 100644 index d250df4afe1..00000000000 --- a/core/services/ocr2/plugins/ocr2keeper/custom_telemetry.go +++ /dev/null @@ -1,159 +0,0 @@ -package ocr2keeper - -import ( - "context" - "encoding/hex" - "time" - - "google.golang.org/protobuf/proto" - - "github.com/smartcontractkit/libocr/commontypes" - "github.com/smartcontractkit/libocr/offchainreporting2plus/types" - - ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" - - "github.com/smartcontractkit/chainlink-common/pkg/services" - - "github.com/smartcontractkit/chainlink/v2/core/logger" - evm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21" - "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 { - services.StateMachine - 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 deleted file mode 100644 index a40a3f3525d..00000000000 --- a/core/services/ocr2/plugins/ocr2keeper/custom_telemetry_test.go +++ /dev/null @@ -1,17 +0,0 @@ -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) - // } -}