Skip to content

Commit

Permalink
CCIP-4447 Publishing status of the OCR3 plugin (based on the config d…
Browse files Browse the repository at this point in the history
…igest) (#15544)

* Publishing status of the OCR3 plugin (based on the config digest)

* Publishing status of the OCR3 plugin (based on the config digest)
  • Loading branch information
mateusz-sekara authored Dec 9, 2024
1 parent 49b7704 commit 036cb20
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-readers-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Reporting number of OCR3 instances running using promwrapper #internal
2 changes: 2 additions & 0 deletions core/services/ocr3/promwrapper/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func (r ReportingPluginFactory[RI]) NewReportingPlugin(ctx context.Context, conf
plugin,
r.chainID,
r.plugin,
config.ConfigDigest.String(),
promOCR3ReportsGenerated,
promOCR3Durations,
promOCR3PluginStatus,
)
return wrapped, info, err
}
28 changes: 22 additions & 6 deletions core/services/ocr3/promwrapper/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ var _ ocr3types.ReportingPlugin[any] = &reportingPlugin[any]{}

type reportingPlugin[RI any] struct {
ocr3types.ReportingPlugin[RI]
chainID string
plugin string
chainID string
plugin string
configDigest string

// Prometheus components for tracking metrics
reportsGenerated *prometheus.CounterVec
durations *prometheus.HistogramVec
status *prometheus.GaugeVec
}

func newReportingPlugin[RI any](
origin ocr3types.ReportingPlugin[RI],
chainID string,
plugin string,
configDigest string,
reportsGenerated *prometheus.CounterVec,
durations *prometheus.HistogramVec,
status *prometheus.GaugeVec,
) *reportingPlugin[RI] {
return &reportingPlugin[RI]{
ReportingPlugin: origin,
chainID: chainID,
plugin: plugin,
configDigest: configDigest,
reportsGenerated: reportsGenerated,
durations: durations,
status: status,
}
}

Expand Down Expand Up @@ -88,15 +94,23 @@ func (p *reportingPlugin[RI]) ShouldTransmitAcceptedReport(ctx context.Context,
return result, err
}

func (p *reportingPlugin[RI]) trackReports(
function functionType,
count int,
) {
func (p *reportingPlugin[RI]) Close() error {
p.updateStatus(false)
return p.ReportingPlugin.Close()
}

func (p *reportingPlugin[RI]) trackReports(function functionType, count int) {
p.reportsGenerated.
WithLabelValues(p.chainID, p.plugin, string(function)).
Add(float64(count))
}

func (p *reportingPlugin[RI]) updateStatus(status bool) {
p.status.
WithLabelValues(p.chainID, p.plugin, p.configDigest).
Set(float64(boolToInt(status)))
}

func boolToInt(arg bool) int {
if arg {
return 1
Expand All @@ -118,5 +132,7 @@ func withObservedExecution[RI, R any](
WithLabelValues(p.chainID, p.plugin, string(function), strconv.FormatBool(success)).
Observe(float64(time.Since(start)))

p.updateStatus(true)

return result, err
}
19 changes: 13 additions & 6 deletions core/services/ocr3/promwrapper/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
func Test_ReportsGeneratedGauge(t *testing.T) {
plugin1 := newReportingPlugin(
fakePlugin[uint]{reports: make([]ocr3types.ReportPlus[uint], 2)},
"123", "empty", promOCR3ReportsGenerated, promOCR3Durations,
"123", "empty", "abc", promOCR3ReportsGenerated, promOCR3Durations, promOCR3PluginStatus,
)
plugin2 := newReportingPlugin(
fakePlugin[bool]{reports: make([]ocr3types.ReportPlus[bool], 10)},
"solana", "different_plugin", promOCR3ReportsGenerated, promOCR3Durations,
"solana", "different_plugin", "abc", promOCR3ReportsGenerated, promOCR3Durations, promOCR3PluginStatus,
)
plugin3 := newReportingPlugin(
fakePlugin[string]{err: errors.New("error")},
"1234", "empty", promOCR3ReportsGenerated, promOCR3Durations,
"1234", "empty", "abc", promOCR3ReportsGenerated, promOCR3Durations, promOCR3PluginStatus,
)

r1, err := plugin1.Reports(tests.Context(t), 1, nil)
Expand Down Expand Up @@ -57,20 +57,27 @@ func Test_ReportsGeneratedGauge(t *testing.T) {

g4 := testutil.ToFloat64(promOCR3ReportsGenerated.WithLabelValues("1234", "empty", "reports"))
require.Equal(t, 0, int(g4))

pluginHealth := testutil.ToFloat64(promOCR3PluginStatus.WithLabelValues("123", "empty", "abc"))
require.Equal(t, 1, int(pluginHealth))

require.NoError(t, plugin1.Close())
pluginHealth = testutil.ToFloat64(promOCR3PluginStatus.WithLabelValues("123", "empty", "abc"))
require.Equal(t, 0, int(pluginHealth))
}

func Test_DurationHistograms(t *testing.T) {
plugin1 := newReportingPlugin(
fakePlugin[uint]{},
"123", "empty", promOCR3ReportsGenerated, promOCR3Durations,
"123", "empty", "abc", promOCR3ReportsGenerated, promOCR3Durations, promOCR3PluginStatus,
)
plugin2 := newReportingPlugin(
fakePlugin[uint]{err: errors.New("error")},
"123", "empty", promOCR3ReportsGenerated, promOCR3Durations,
"123", "empty", "abc", promOCR3ReportsGenerated, promOCR3Durations, promOCR3PluginStatus,
)
plugin3 := newReportingPlugin(
fakePlugin[uint]{},
"solana", "commit", promOCR3ReportsGenerated, promOCR3Durations,
"solana", "commit", "abc", promOCR3ReportsGenerated, promOCR3Durations, promOCR3PluginStatus,
)

for _, p := range []*reportingPlugin[uint]{plugin1, plugin2, plugin3} {
Expand Down
7 changes: 7 additions & 0 deletions core/services/ocr3/promwrapper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ var (
},
[]string{"chainID", "plugin", "function", "success"},
)
promOCR3PluginStatus = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ocr3_reporting_plugin_status",
Help: "Gauge indicating whether plugin is up and running or not",
},
[]string{"chainID", "plugin", "configDigest"},
)
)

0 comments on commit 036cb20

Please sign in to comment.