Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Nov 13, 2024
1 parent 973adb5 commit cdf31a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
39 changes: 19 additions & 20 deletions core/services/registrysyncer/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,38 @@ import (
localMonitoring "github.com/smartcontractkit/chainlink/v2/core/monitoring"
)

var remoteRegistrySyncFailureCounter metric.Int64Counter
var launcherFailureCounter metric.Int64Counter
// syncerMetricLabeler wraps monitoring.MetricsLabeler to provide workflow specific utilities
// for monitoring resources
type syncerMetricLabeler struct {
metrics.Labeler
remoteRegistrySyncFailureCounter metric.Int64Counter
launcherFailureCounter metric.Int64Counter
}

func initMonitoringResources() (err error) {
remoteRegistrySyncFailureCounter, err = beholder.GetMeter().Int64Counter("platform_registrysyncer_sync_failures")
func newSyncerMetricLabeler() (*syncerMetricLabeler, error) {
remoteRegistrySyncFailureCounter, err := beholder.GetMeter().Int64Counter("RemoteRegistrySyncFailure")
if err != nil {
return fmt.Errorf("failed to register sync failure counter: %w", err)
return nil, fmt.Errorf("failed to register sync failure counter: %w", err)
}

launcherFailureCounter, err = beholder.GetMeter().Int64Counter("platform_registrysyncer_launch_failures")
launcherFailureCounter, err := beholder.GetMeter().Int64Counter("LauncherFailureCounter")
if err != nil {
return fmt.Errorf("failed to register launcher failure counter: %w", err)
return nil, fmt.Errorf("failed to register launcher failure counter: %w", err)
}

return nil
}

// syncerMetricLabeler wraps monitoring.MetricsLabeler to provide workflow specific utilities
// for monitoring resources
type syncerMetricLabeler struct {
metrics.Labeler
return &syncerMetricLabeler{remoteRegistrySyncFailureCounter: remoteRegistrySyncFailureCounter, launcherFailureCounter: launcherFailureCounter}, nil
}

func (c syncerMetricLabeler) with(keyValues ...string) syncerMetricLabeler {
return syncerMetricLabeler{c.With(keyValues...)}
func (c *syncerMetricLabeler) with(keyValues ...string) syncerMetricLabeler {
return syncerMetricLabeler{c.With(keyValues...), c.remoteRegistrySyncFailureCounter, c.launcherFailureCounter}
}

func (c syncerMetricLabeler) incrementRemoteRegistryFailureCounter(ctx context.Context) {
func (c *syncerMetricLabeler) incrementRemoteRegistryFailureCounter(ctx context.Context) {
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
remoteRegistrySyncFailureCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
c.remoteRegistrySyncFailureCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}

func (c syncerMetricLabeler) incrementLauncherFailureCounter(ctx context.Context) {
func (c *syncerMetricLabeler) incrementLauncherFailureCounter(ctx context.Context) {
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
launcherFailureCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
c.launcherFailureCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}
5 changes: 3 additions & 2 deletions core/services/registrysyncer/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
)

func Test_InitMonitoringResources(t *testing.T) {
require.NoError(t, initMonitoringResources())
_, err := newSyncerMetricLabeler()
require.NoError(t, err)
}

func Test_SyncerMetricsLabeler(t *testing.T) {
testSyncerMetricLabeler := syncerMetricLabeler{metrics.NewLabeler()}
testSyncerMetricLabeler := syncerMetricLabeler{metrics.NewLabeler(), nil, nil}
testSyncerMetricLabeler2 := testSyncerMetricLabeler.with("foo", "baz")
require.EqualValues(t, testSyncerMetricLabeler2.Labels["foo"], "baz")
}
14 changes: 8 additions & 6 deletions core/services/registrysyncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type RegistrySyncer interface {

type registrySyncer struct {
services.StateMachine
metrics syncerMetricLabeler
metrics *syncerMetricLabeler
stopCh services.StopChan
launchers []Launcher
reader types.ContractReader
Expand Down Expand Up @@ -76,7 +76,14 @@ func New(
registryAddress string,
orm ORM,
) (RegistrySyncer, error) {

metricLabeler, err := newSyncerMetricLabeler()
if err != nil {
return nil, fmt.Errorf("failed to create syncer metric labeler: %w", err)
}

return &registrySyncer{
metrics: metricLabeler,
stopCh: make(services.StopChan),
updateChan: make(chan *LocalRegistry),
lggr: lggr.Named("RegistrySyncer"),
Expand Down Expand Up @@ -131,11 +138,6 @@ func newReader(ctx context.Context, lggr logger.Logger, relayer ContractReaderFa

func (s *registrySyncer) Start(ctx context.Context) error {
return s.StartOnce("RegistrySyncer", func() error {
err := initMonitoringResources()
if err != nil {
return err
}

s.wg.Add(1)
go func() {
defer s.wg.Done()
Expand Down

0 comments on commit cdf31a3

Please sign in to comment.