Skip to content

Commit

Permalink
pkg/logger/lk: new package for log key glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Jan 21, 2025
1 parent e56b78c commit 9135169
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
11 changes: 6 additions & 5 deletions pkg/capabilities/consensus/ocr3/datafeeds/feeds_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/types"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/datastreams"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/logger/lk"
"github.com/smartcontractkit/chainlink-common/pkg/values"
)

Expand Down Expand Up @@ -112,12 +113,12 @@ func (a *dataFeedsAggregator) Aggregate(lggr logger.Logger, previousOutcome *typ
previousReportInfo := currentState.FeedInfo[feedIDStr]
feedID, err2 := datastreams.NewFeedID(feedIDStr)
if err2 != nil {
lggr.Errorw("could not convert %s to feedID", "feedID", feedID)
lggr.Errorw("could not convert %s to feedID", lk.FeedID, feedID)
continue
}
latestReport, ok := latestReportPerFeed[feedID]
if !ok {
lggr.Errorw("no new Mercury report for feed", "feedID", feedID)
lggr.Errorw("no new Mercury report for feed", lk.FeedID, feedID)
continue
}
config := a.config.Feeds[feedID]
Expand All @@ -126,7 +127,7 @@ func (a *dataFeedsAggregator) Aggregate(lggr logger.Logger, previousOutcome *typ
currDeviation := deviation(oldPrice, newPrice)
currStaleness := latestReport.ObservationTimestamp - previousReportInfo.ObservationTimestamp
lggr.Debugw("checking deviation and heartbeat",
"feedID", feedID,
lk.FeedID, feedID,
"currentTs", latestReport.ObservationTimestamp,
"oldTs", previousReportInfo.ObservationTimestamp,
"currStaleness", currStaleness,
Expand Down Expand Up @@ -213,14 +214,14 @@ func (a *dataFeedsAggregator) initializeCurrentState(lggr logger.Logger, previou
ObservationTimestamp: 0, // will always trigger an update
BenchmarkPrice: big.NewInt(0).Bytes(),
}
lggr.Debugw("initializing empty onchain state for feed", "feedID", feedID.String())
lggr.Debugw("initializing empty onchain state for feed", lk.FeedID, feedID.String())
}
}
// remove obsolete feeds from state
for feedID := range currentState.FeedInfo {
if _, ok := a.config.Feeds[datastreams.FeedID(feedID)]; !ok {
delete(currentState.FeedInfo, feedID)
lggr.Debugw("removed obsolete feedID from state", "feedID", feedID)
lggr.Debugw("removed obsolete feedID from state", lk.FeedID, feedID)
}
}
lggr.Debugw("current state initialized", "state", currentState, "previousOutcome", previousOutcome)
Expand Down
10 changes: 10 additions & 0 deletions pkg/logger/lk/logkey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lk

const (
ChainID = "chainID" // string
ContractID = "contractID" // string
FeedID = "feedID" // string - hex-encoded 32-byte value, prefixed with "0x", all lowercase
JobID = "jobID" // int32
JobName = "jobName" // string
TransmitterID = "transmitterID" // string
)
16 changes: 10 additions & 6 deletions pkg/loop/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package loop

import "context"
import (
"context"

"github.com/smartcontractkit/chainlink-common/pkg/logger/lk"
)

type ctxKey int

Expand All @@ -25,19 +29,19 @@ type ContextValues struct {
// Args returns a slice of args to pass to [logger.Logger.With].
func (v *ContextValues) Args() (a []any) {
if v.JobID != nil {
a = append(a, "jobID", v.JobID)
a = append(a, lk.JobID, v.JobID)
}
if v.JobName != nil {
a = append(a, "jobName", v.JobName)
a = append(a, lk.JobName, v.JobName)
}
if v.ContractID != nil {
a = append(a, "contractID", v.ContractID)
a = append(a, lk.ContractID, v.ContractID)
}
if v.FeedID != nil {
a = append(a, "feedID", v.FeedID)
a = append(a, lk.FeedID, v.FeedID)
}
if v.TransmitterID != nil {
a = append(a, "transmitterID", v.TransmitterID)
a = append(a, lk.TransmitterID, v.TransmitterID)
}
return
}
Expand Down

0 comments on commit 9135169

Please sign in to comment.