Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/logger/lk: new package for log key glossary #986

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading