Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Jan 10, 2025
1 parent d4519a9 commit 0dbca8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ type ApplicationHeartbeat struct {
eng *commonservices.Engine

beat time.Duration
lggr logger.Logger
}

func NewApplicationHeartbeat(lggr logger.Logger) ApplicationHeartbeat {
Expand Down Expand Up @@ -231,33 +230,32 @@ func (h *ApplicationHeartbeat) start(_ context.Context) error {
cme := custmsg.NewLabeler()

// Define tick functions
beatFn := func(engCtx context.Context) {
beatFn := func(ctx context.Context) {
// TODO allow override of tracer provider into engine for beholder
_, innerSpan := beholder.GetTracer().Start(engCtx, "heartbeat.beat")
_, innerSpan := beholder.GetTracer().Start(ctx, "heartbeat.beat")
defer innerSpan.End()

gauge.Record(engCtx, 1)
count.Record(engCtx, 1)
gauge.Record(ctx, 1)
count.Record(ctx, 1)

err = cme.Emit(engCtx, "heartbeat")
err = cme.Emit(ctx, "heartbeat")
if err != nil {
h.eng.Errorw("heartbeat emit failed", "err", err)
}
}

// consistent tick period
constantTickFn := func() time.Duration {
return h.beat
}

h.eng.GoTick(timeutil.NewTicker(constantTickFn), beatFn)
h.eng.GoTick(timeutil.NewTicker(h.getBeat), beatFn)
return nil
}

func (h *ApplicationHeartbeat) close() error {
return nil
}

func (h *ApplicationHeartbeat) getBeat() time.Duration {
return h.beat
}

// NewApplication initializes a new store if one is not already
// present at the configured root directory (default: ~/.chainlink),
// the logger at the same directory and returns the Application to
Expand Down
4 changes: 2 additions & 2 deletions core/services/chainlink/config_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestTelemetryConfig_ResourceAttributes(t *testing.T) {
map[string]string{
"service.name": "chainlink",
"service.sha": "unset",
"service.shortversion": "unset",
"service.shortversion": "unset@unset",
"service.version": static.Version,
},
},
Expand All @@ -109,7 +109,7 @@ func TestTelemetryConfig_ResourceAttributes(t *testing.T) {
map[string]string{
"service.name": "chainlink",
"service.sha": "unset",
"service.shortversion": "unset",
"service.shortversion": "unset@unset",
"service.version": static.Version,
"custom.key": "custom.value",
},
Expand Down

0 comments on commit 0dbca8a

Please sign in to comment.