Skip to content

Commit

Permalink
Use common labelers instead of local ones (#14867)
Browse files Browse the repository at this point in the history
* Uses `common` labelers

* go mod tidy

* Adds changeset

* Matches `head_tracker_current_head` from common

* Fixes changeset

* Fixes CI - WIP

* Updates to `common` HEAD + make gomodtidy

* Fixes lint

* Fixes CI

* make gomodtidy

* make gomodtidy

* make gomodtidy

* bumps chainlink-common

* bumps chainlink-ccip + make gomodtidy

* bumps chainlink-common

* bumps chainlink-common

* bumps chainlink-common

* make gomodtidy
  • Loading branch information
vyzaldysanchez authored Oct 25, 2024
1 parent da5910e commit 2d28b4e
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 176 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-spies-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#updated Use labelers from `chainlink-common`
115 changes: 0 additions & 115 deletions core/monitoring/monitoring.go

This file was deleted.

16 changes: 0 additions & 16 deletions core/monitoring/monitoring_test.go

This file was deleted.

10 changes: 6 additions & 4 deletions core/services/registrysyncer/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"go.opentelemetry.io/otel/metric"

"github.com/smartcontractkit/chainlink-common/pkg/beholder"
"github.com/smartcontractkit/chainlink/v2/core/monitoring"
"github.com/smartcontractkit/chainlink-common/pkg/metrics"

localMonitoring "github.com/smartcontractkit/chainlink/v2/core/monitoring"
)

var remoteRegistrySyncFailureCounter metric.Int64Counter
Expand All @@ -30,19 +32,19 @@ func initMonitoringResources() (err error) {
// syncerMetricLabeler wraps monitoring.MetricsLabeler to provide workflow specific utilities
// for monitoring resources
type syncerMetricLabeler struct {
monitoring.MetricsLabeler
metrics.Labeler
}

func (c syncerMetricLabeler) with(keyValues ...string) syncerMetricLabeler {
return syncerMetricLabeler{c.With(keyValues...)}
}

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

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

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/monitoring"
"github.com/smartcontractkit/chainlink-common/pkg/metrics"
)

func Test_InitMonitoringResources(t *testing.T) {
require.NoError(t, initMonitoringResources())
}

func Test_SyncerMetricsLabeler(t *testing.T) {
testSyncerMetricLabeler := syncerMetricLabeler{monitoring.NewMetricsLabeler()}
testSyncerMetricLabeler := syncerMetricLabeler{metrics.NewLabeler()}
testSyncerMetricLabeler2 := testSyncerMetricLabeler.with("foo", "baz")
require.EqualValues(t, testSyncerMetricLabeler2.Labels["foo"], "baz")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/jmoiron/sqlx"
"github.com/smartcontractkit/libocr/commontypes"
"github.com/stretchr/testify/require"

commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
. "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with .
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
Expand All @@ -26,13 +27,11 @@ import (
evmtxmgr "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/chain_reader_tester"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
_ "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" // force binding for tx type
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"

gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
)

const (
Expand Down
15 changes: 7 additions & 8 deletions core/services/workflows/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import (
"sync"
"time"

"github.com/smartcontractkit/chainlink/v2/core/monitoring"

"github.com/jonboulle/clockwork"

"github.com/smartcontractkit/chainlink-common/pkg/workflows/exec"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
"github.com/smartcontractkit/chainlink-common/pkg/custmsg"
"github.com/smartcontractkit/chainlink-common/pkg/metrics"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/values"
"github.com/smartcontractkit/chainlink-common/pkg/workflows"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/exec"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/transmission"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -92,7 +91,7 @@ func (sucm *stepUpdateManager) len() int64 {
// Engine handles the lifecycle of a single workflow and its executions.
type Engine struct {
services.StateMachine
cma monitoring.CustomMessageLabeler
cma custmsg.Labeler
metrics workflowsMetricLabeler
logger logger.Logger
registry core.CapabilitiesRegistry
Expand Down Expand Up @@ -1162,8 +1161,8 @@ func NewEngine(cfg Config) (engine *Engine, err error) {

engine = &Engine{
logger: cfg.Lggr.Named("WorkflowEngine").With("workflowID", cfg.WorkflowID),
cma: monitoring.NewCustomMessageLabeler().With(wIDKey, cfg.WorkflowID, woIDKey, cfg.WorkflowOwner, wnKey, workflow.name),
metrics: workflowsMetricLabeler{monitoring.NewMetricsLabeler().With(wIDKey, cfg.WorkflowID, woIDKey, cfg.WorkflowOwner, wnKey, workflow.name)},
cma: custmsg.NewLabeler().With(wIDKey, cfg.WorkflowID, woIDKey, cfg.WorkflowOwner, wnKey, workflow.name),
metrics: workflowsMetricLabeler{metrics.NewLabeler().With(wIDKey, cfg.WorkflowID, woIDKey, cfg.WorkflowOwner, wnKey, workflow.name)},
registry: cfg.Registry,
workflow: workflow,
env: exec.Env{
Expand Down
16 changes: 9 additions & 7 deletions core/services/workflows/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"go.opentelemetry.io/otel/metric"

"github.com/smartcontractkit/chainlink-common/pkg/beholder"
"github.com/smartcontractkit/chainlink/v2/core/monitoring"
"github.com/smartcontractkit/chainlink-common/pkg/metrics"

localMonitoring "github.com/smartcontractkit/chainlink/v2/core/monitoring"
)

var registerTriggerFailureCounter metric.Int64Counter
Expand Down Expand Up @@ -48,35 +50,35 @@ func initMonitoringResources() (err error) {
// workflowsMetricLabeler wraps monitoring.MetricsLabeler to provide workflow specific utilities
// for monitoring resources
type workflowsMetricLabeler struct {
monitoring.MetricsLabeler
metrics.Labeler
}

func (c workflowsMetricLabeler) with(keyValues ...string) workflowsMetricLabeler {
return workflowsMetricLabeler{c.With(keyValues...)}
}

func (c workflowsMetricLabeler) incrementRegisterTriggerFailureCounter(ctx context.Context) {
otelLabels := monitoring.KvMapToOtelAttributes(c.Labels)
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
registerTriggerFailureCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}

func (c workflowsMetricLabeler) incrementCapabilityInvocationCounter(ctx context.Context) {
otelLabels := monitoring.KvMapToOtelAttributes(c.Labels)
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
capabilityInvocationCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}

func (c workflowsMetricLabeler) updateWorkflowExecutionLatencyGauge(ctx context.Context, val int64) {
otelLabels := monitoring.KvMapToOtelAttributes(c.Labels)
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
workflowExecutionLatencyGauge.Record(ctx, val, metric.WithAttributes(otelLabels...))
}

func (c workflowsMetricLabeler) incrementTotalWorkflowStepErrorsCounter(ctx context.Context) {
otelLabels := monitoring.KvMapToOtelAttributes(c.Labels)
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
workflowStepErrorCounter.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}

func (c workflowsMetricLabeler) updateTotalWorkflowsGauge(ctx context.Context, val int64) {
otelLabels := monitoring.KvMapToOtelAttributes(c.Labels)
otelLabels := localMonitoring.KvMapToOtelAttributes(c.Labels)
workflowsRunningGauge.Record(ctx, val, metric.WithAttributes(otelLabels...))
}

Expand Down
4 changes: 2 additions & 2 deletions core/services/workflows/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/monitoring"
"github.com/smartcontractkit/chainlink-common/pkg/metrics"
)

func Test_InitMonitoringResources(t *testing.T) {
require.NoError(t, initMonitoringResources())
}

func Test_WorkflowMetricsLabeler(t *testing.T) {
testWorkflowsMetricLabeler := workflowsMetricLabeler{monitoring.NewMetricsLabeler()}
testWorkflowsMetricLabeler := workflowsMetricLabeler{metrics.NewLabeler()}
testWorkflowsMetricLabeler2 := testWorkflowsMetricLabeler.with("foo", "baz")
require.EqualValues(t, testWorkflowsMetricLabeler2.Labels["foo"], "baz")
}
6 changes: 3 additions & 3 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ require (
github.com/cosmos/ibc-go/v7 v7.5.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down Expand Up @@ -354,8 +354,8 @@ require (
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/spdystream v0.4.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5s
github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M=
github.com/cosmos/rosetta-sdk-go v0.10.0 h1:E5RhTruuoA7KTIXUcMicL76cffyeoyvNybzUGSKFTcM=
github.com/cosmos/rosetta-sdk-go v0.10.0/go.mod h1:SImAZkb96YbwvoRkzSMQB6noNJXFgWl/ENIznEoYQI4=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA=
github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
Expand Down Expand Up @@ -1152,10 +1152,10 @@ github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkV
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8=
github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo=
github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg=
github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU=
github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo=
github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs=
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
Expand Down
Loading

0 comments on commit 2d28b4e

Please sign in to comment.