-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
prom.go
64 lines (52 loc) · 2.22 KB
/
prom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package ocrcommon
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/spf13/cast"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
var (
PromBridgeJsonParseValues = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "bridge_json_parse_values",
Help: "Values returned by json_parse for bridge task",
},
[]string{"job_id", "job_name", "bridge_name", "task_id"})
PromOcrMedianValues = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "ocr_median_values",
Help: "Median value returned by ocr job",
},
[]string{"job_id", "job_name"})
)
// promSetBridgeParseMetrics will parse pipeline.TaskRunResults for bridge tasks, get the pipeline.TaskTypeJSONParse task and update prometheus metrics with it
func promSetBridgeParseMetrics(ds *inMemoryDataSource, trrs *pipeline.TaskRunResults) {
if ds.jb.Type.String() != pipeline.OffchainReportingJobType && ds.jb.Type.String() != pipeline.OffchainReporting2JobType {
return
}
for _, trr := range *trrs {
if trr.Task.Type() == pipeline.TaskTypeBridge {
nextTask := trrs.GetNextTaskOf(trr)
if nextTask != nil && nextTask.Task.Type() == pipeline.TaskTypeJSONParse {
fetchedValue := cast.ToFloat64(nextTask.Result.Value)
PromBridgeJsonParseValues.WithLabelValues(fmt.Sprintf("%d", ds.jb.ID), ds.jb.Name.String, trr.Task.(*pipeline.BridgeTask).Name, trr.Task.DotID()).Set(fetchedValue)
}
}
}
}
// promSetFinalResultMetrics will check if job is pipeline.OffchainReportingJobType or pipeline.OffchainReporting2JobType then send the pipeline.FinalResult to prometheus
func promSetFinalResultMetrics(ds *inMemoryDataSource, finalResult *pipeline.FinalResult) {
if ds.jb.Type.String() != pipeline.OffchainReportingJobType && ds.jb.Type.String() != pipeline.OffchainReporting2JobType {
return
}
singularResult, err := finalResult.SingularResult()
if err != nil {
return
}
finalResultDecimal, err := utils.ToDecimal(singularResult.Value)
if err != nil {
return
}
finalResultFloat, _ := finalResultDecimal.Float64()
PromOcrMedianValues.WithLabelValues(fmt.Sprintf("%d", ds.jb.ID), ds.jb.Name.String).Set(finalResultFloat)
}