Skip to content

Commit

Permalink
BCF-2749 add tests for ocr enhancedTelemetry service creation (#11206)
Browse files Browse the repository at this point in the history
* Add Enhanced telemetry is disabled log to newServicesMercury delegate

* Add test to check if eaTelemetry service was created in ocr servicseForSpec based on ocr spec flag
  • Loading branch information
ilija42 authored Nov 8, 2023
1 parent ea27753 commit b5191f1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
68 changes: 68 additions & 0 deletions core/services/job/runner_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,74 @@ answer1 [type=median index=0];
require.NoError(t, err)
})

t.Run("test enhanced telemetry service creation", func(t *testing.T) {
testCases := []struct {
jbCaptureEATelemetry bool
specCaptureEATelemetry bool
expected bool
}{{false, false, false},
{true, false, false},
{false, true, true},
{true, true, true},
}

for _, tc := range testCases {

config = configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.P2P.V1.Enabled = ptr(true)
c.OCR.CaptureEATelemetry = ptr(tc.specCaptureEATelemetry)
})

relayExtenders = evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, Client: ethClient, GeneralConfig: config, KeyStore: ethKeyStore})
legacyChains = evmrelay.NewLegacyChainsFromRelayerExtenders(relayExtenders)

kb, err := keyStore.OCR().Create()
require.NoError(t, err)

s := fmt.Sprintf(minimalNonBootstrapTemplate, cltest.NewEIP55Address(), transmitterAddress.Hex(), kb.ID(), "http://blah.com", "")
jb, err := ocr.ValidatedOracleSpecToml(legacyChains, s)
require.NoError(t, err)
err = toml.Unmarshal([]byte(s), &jb)
require.NoError(t, err)

jb.MaxTaskDuration = models.Interval(cltest.MustParseDuration(t, "1s"))
err = jobORM.CreateJob(&jb)
require.NoError(t, err)
assert.Equal(t, jb.MaxTaskDuration, models.Interval(cltest.MustParseDuration(t, "1s")))

lggr := logger.TestLogger(t)
pw := ocrcommon.NewSingletonPeerWrapper(keyStore, config.P2P(), config.OCR(), config.Database(), db, lggr)
require.NoError(t, pw.Start(testutils.Context(t)))
sd := ocr.NewDelegate(
db,
jobORM,
keyStore,
nil,
pw,
monitoringEndpoint,
legacyChains,
lggr,
config.Database(),
srvctest.Start(t, utils.NewMailboxMonitor(t.Name())),
)

jb.OCROracleSpec.CaptureEATelemetry = tc.jbCaptureEATelemetry
services, err := sd.ServicesForSpec(jb)
require.NoError(t, err)

enhancedTelemetryServiceCreated := false
for _, service := range services {
_, ok := service.(*ocrcommon.EnhancedTelemetryService[ocrcommon.EnhancedTelemetryData])
enhancedTelemetryServiceCreated = ok
if enhancedTelemetryServiceCreated {
break
}
}

require.Equal(t, tc.expected, enhancedTelemetryServiceCreated)
}
})

t.Run("test job spec error is created", func(t *testing.T) {
// Create a keystore with an ocr key bundle and p2p key.
kb, err := keyStore.OCR().Create()
Expand Down
2 changes: 2 additions & 0 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ func (d *Delegate) newServicesMercury(
if ocrcommon.ShouldCollectEnhancedTelemetryMercury(jb) {
enhancedTelemService := ocrcommon.NewEnhancedTelemetryService(&jb, chEnhancedTelem, make(chan struct{}), d.monitoringEndpointGen.GenMonitoringEndpoint(rid.Network, rid.ChainID, spec.FeedID.String(), synchronization.EnhancedEAMercury), lggr.Named("EnhancedTelemetryMercury"))
mercuryServices = append(mercuryServices, enhancedTelemService)
} else {
lggr.Infow("Enhanced telemetry is disabled for mercury job", "job", jb.Name)
}

return mercuryServices, err2
Expand Down

0 comments on commit b5191f1

Please sign in to comment.