Skip to content

Commit

Permalink
feat(jobs): instrument job errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Oct 4, 2022
1 parent 633b4ef commit 371496e
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
19 changes: 19 additions & 0 deletions pkg/exporter/jobs/chainlink_data_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ChainlinkDataFeed struct {
client api.ExecutionClient
log logrus.FieldLogger
ChainlinkDataFeedBalance prometheus.GaugeVec
ChainlinkDataFeedError prometheus.CounterVec
addresses []*AddressChainlinkDataFeed
labelsMap map[string]int
}
Expand Down Expand Up @@ -72,9 +73,19 @@ func NewChainlinkDataFeed(client api.ExecutionClient, log logrus.FieldLogger, na
},
labels,
),
ChainlinkDataFeedError: *prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "The total errors when getting the balance of a ethereum chainlink data feed contract.",
ConstLabels: constLabels,
},
labels,
),
}

prometheus.MustRegister(instance.ChainlinkDataFeedBalance)
prometheus.MustRegister(instance.ChainlinkDataFeedError)

return instance
}
Expand Down Expand Up @@ -129,6 +140,14 @@ func (n *ChainlinkDataFeed) getLabelValues(address *AddressChainlinkDataFeed) []
}

func (n *ChainlinkDataFeed) getBalance(address *AddressChainlinkDataFeed) error {
var err error

defer func() {
if err != nil {
n.ChainlinkDataFeedError.WithLabelValues(n.getLabelValues(address)...).Inc()
}
}()

// call latestAnswer() which is 0x50d25bcd
latestAnswerData := "0x50d25bcd000000000000000000000000"

Expand Down
19 changes: 19 additions & 0 deletions pkg/exporter/jobs/eoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type EOA struct {
client api.ExecutionClient
log logrus.FieldLogger
EOABalance prometheus.GaugeVec
EOAError prometheus.CounterVec
addresses []*AddressEOA
labelsMap map[string]int
}
Expand Down Expand Up @@ -67,9 +68,19 @@ func NewEOA(client api.ExecutionClient, log logrus.FieldLogger, namespace string
},
labels,
),
EOAError: *prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "The total errors when getting the balance of a ethereum externally owned account address.",
ConstLabels: constLabels,
},
labels,
),
}

prometheus.MustRegister(instance.EOABalance)
prometheus.MustRegister(instance.EOAError)

return instance
}
Expand Down Expand Up @@ -120,6 +131,14 @@ func (n *EOA) getLabelValues(address *AddressEOA) []string {
}

func (n *EOA) getBalance(address *AddressEOA) error {
var err error

defer func() {
if err != nil {
n.EOAError.WithLabelValues(n.getLabelValues(address)...).Inc()
}
}()

balance, err := n.client.ETHGetBalance(address.Address, "latest")
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions pkg/exporter/jobs/erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ERC1155 struct {
client api.ExecutionClient
log logrus.FieldLogger
ERC1155Balance prometheus.GaugeVec
ERC1155Error prometheus.CounterVec
addresses []*AddressERC1155
labelsMap map[string]int
}
Expand Down Expand Up @@ -74,9 +75,19 @@ func NewERC1155(client api.ExecutionClient, log logrus.FieldLogger, namespace st
},
labels,
),
ERC1155Error: *prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "The total errors when getting the balance of a ethereum ERC115 contract by address and token id.",
ConstLabels: constLabels,
},
labels,
),
}

prometheus.MustRegister(instance.ERC1155Balance)
prometheus.MustRegister(instance.ERC1155Error)

return instance
}
Expand Down Expand Up @@ -131,6 +142,14 @@ func (n *ERC1155) getLabelValues(address *AddressERC1155) []string {
}

func (n *ERC1155) getBalance(address *AddressERC1155) error {
var err error

defer func() {
if err != nil {
n.ERC1155Error.WithLabelValues(n.getLabelValues(address)...).Inc()
}
}()

// call balanceOf(address,uint256) which is 0x00fdd58e
balanceOfData := "0x00fdd58e000000000000000000000000" + address.Address[2:] + fmt.Sprintf("%064x", &address.TokenID)

Expand Down
23 changes: 22 additions & 1 deletion pkg/exporter/jobs/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ERC20 struct {
client api.ExecutionClient
log logrus.FieldLogger
ERC20Balance prometheus.GaugeVec
ERC20Error prometheus.CounterVec
addresses []*AddressERC20
labelsMap map[string]int
}
Expand Down Expand Up @@ -71,9 +72,19 @@ func NewERC20(client api.ExecutionClient, log logrus.FieldLogger, namespace stri
},
labels,
),
ERC20Error: *prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "The total errors when getting the balance of a ethereum ERC20 contract by address.",
ConstLabels: constLabels,
},
labels,
),
}

prometheus.MustRegister(instance.ERC20Balance)
prometheus.MustRegister(instance.ERC20Error)

return instance
}
Expand Down Expand Up @@ -128,6 +139,16 @@ func (n *ERC20) getLabelValues(address *AddressERC20, symbol string) []string {
}

func (n *ERC20) getBalance(address *AddressERC20) error {
var err error

symbol := ""

defer func() {
if err != nil {
n.ERC20Error.WithLabelValues(n.getLabelValues(address, symbol)...).Inc()
}
}()

// call balanceOf(address) which is 0x70a08231
balanceOfData := "0x70a08231000000000000000000000000" + address.Address[2:]

Expand All @@ -150,7 +171,7 @@ func (n *ERC20) getBalance(address *AddressERC20) error {
return err
}

symbol, err := hexStringToString(symbolHex)
symbol, err = hexStringToString(symbolHex)
if err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/exporter/jobs/erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ERC721 struct {
client api.ExecutionClient
log logrus.FieldLogger
ERC721Balance prometheus.GaugeVec
ERC721Error prometheus.CounterVec
addresses []*AddressERC721
labelsMap map[string]int
}
Expand Down Expand Up @@ -70,9 +71,19 @@ func NewERC721(client api.ExecutionClient, log logrus.FieldLogger, namespace str
},
labels,
),
ERC721Error: *prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "The total errors when getting the balance of a ethereum ERC721 contract by address.",
ConstLabels: constLabels,
},
labels,
),
}

prometheus.MustRegister(instance.ERC721Balance)
prometheus.MustRegister(instance.ERC721Error)

return instance
}
Expand Down Expand Up @@ -125,6 +136,14 @@ func (n *ERC721) getLabelValues(address *AddressERC721) []string {
}

func (n *ERC721) getBalance(address *AddressERC721) error {
var err error

defer func() {
if err != nil {
n.ERC721Error.WithLabelValues(n.getLabelValues(address)...).Inc()
}
}()

// call balanceOf(address) which is 0x70a08231
balanceOfData := "0x70a08231000000000000000000000000" + address.Address[2:]

Expand Down
19 changes: 19 additions & 0 deletions pkg/exporter/jobs/uniswap_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type UniswapPair struct {
client api.ExecutionClient
log logrus.FieldLogger
UniswapPairBalance prometheus.GaugeVec
UniswapPairError prometheus.CounterVec
addresses []*AddressUniswapPair
labelsMap map[string]int
}
Expand Down Expand Up @@ -72,9 +73,19 @@ func NewUniswapPair(client api.ExecutionClient, log logrus.FieldLogger, namespac
},
labels,
),
UniswapPairError: *prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "errors_total",
Help: "The total errors when getting the balance of a ethereum uniswap pair contract.",
ConstLabels: constLabels,
},
labels,
),
}

prometheus.MustRegister(instance.UniswapPairBalance)
prometheus.MustRegister(instance.UniswapPairError)

return instance
}
Expand Down Expand Up @@ -129,6 +140,14 @@ func (n *UniswapPair) getLabelValues(address *AddressUniswapPair) []string {
}

func (n *UniswapPair) getBalance(address *AddressUniswapPair) error {
var err error

defer func() {
if err != nil {
n.UniswapPairError.WithLabelValues(n.getLabelValues(address)...).Inc()
}
}()

// call getReserves() which is 0x0902f1ac
getReservesData := "0x0902f1ac000000000000000000000000"

Expand Down

0 comments on commit 371496e

Please sign in to comment.