Skip to content

Commit b767977

Browse files
authored
feat: operator liveness metric (#1621)
1 parent 9ca55fb commit b767977

File tree

6 files changed

+181
-19
lines changed

6 files changed

+181
-19
lines changed

grafana/provisioning/dashboards/aligned/aggregator_batcher.json

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,123 @@
27212721
],
27222722
"type": "timeseries"
27232723
},
2724+
{
2725+
"datasource": {
2726+
"type": "prometheus",
2727+
"uid": "prometheus"
2728+
},
2729+
"fieldConfig": {
2730+
"defaults": {
2731+
"color": {
2732+
"mode": "continuous-GrYlRd"
2733+
},
2734+
"custom": {
2735+
"align": "auto",
2736+
"cellOptions": {
2737+
"type": "auto"
2738+
},
2739+
"inspect": false
2740+
},
2741+
"mappings": [],
2742+
"noValue": "none",
2743+
"thresholds": {
2744+
"mode": "absolute",
2745+
"steps": [
2746+
{
2747+
"color": "green",
2748+
"value": null
2749+
},
2750+
{
2751+
"color": "red",
2752+
"value": 80
2753+
}
2754+
]
2755+
}
2756+
},
2757+
"overrides": [
2758+
{
2759+
"matcher": {
2760+
"id": "byName",
2761+
"options": "Max"
2762+
},
2763+
"properties": [
2764+
{
2765+
"id": "custom.cellOptions",
2766+
"value": {
2767+
"type": "gauge"
2768+
}
2769+
}
2770+
]
2771+
}
2772+
]
2773+
},
2774+
"gridPos": {
2775+
"h": 8,
2776+
"w": 12,
2777+
"x": 12,
2778+
"y": 61
2779+
},
2780+
"id": 49,
2781+
"options": {
2782+
"cellHeight": "sm",
2783+
"footer": {
2784+
"countRows": false,
2785+
"fields": "",
2786+
"reducer": [
2787+
"sum"
2788+
],
2789+
"show": false
2790+
},
2791+
"showHeader": false
2792+
},
2793+
"pluginVersion": "10.1.10",
2794+
"targets": [
2795+
{
2796+
"datasource": {
2797+
"type": "prometheus",
2798+
"uid": "prometheus"
2799+
},
2800+
"disableTextWrap": false,
2801+
"editorMode": "code",
2802+
"exemplar": false,
2803+
"expr": "floor(increase(missing_operator_count{job=\"aligned-tracker\"}[$__range]))",
2804+
"format": "time_series",
2805+
"fullMetaSearch": false,
2806+
"includeNullMetadata": true,
2807+
"instant": false,
2808+
"interval": "1",
2809+
"legendFormat": "{{operator}}",
2810+
"range": true,
2811+
"refId": "A",
2812+
"useBackend": false
2813+
}
2814+
],
2815+
"title": "# Operator Missing Tasks",
2816+
"transformations": [
2817+
{
2818+
"id": "reduce",
2819+
"options": {
2820+
"labelsToFields": false,
2821+
"reducers": [
2822+
"max"
2823+
]
2824+
}
2825+
},
2826+
{
2827+
"id": "sortBy",
2828+
"options": {
2829+
"fields": {},
2830+
"sort": [
2831+
{
2832+
"desc": true,
2833+
"field": "Max"
2834+
}
2835+
]
2836+
}
2837+
}
2838+
],
2839+
"type": "table"
2840+
},
27242841
{
27252842
"datasource": {
27262843
"type": "prometheus",
@@ -3176,13 +3293,13 @@
31763293
"list": []
31773294
},
31783295
"time": {
3179-
"from": "now-5m",
3296+
"from": "now-30m",
31803297
"to": "now"
31813298
},
31823299
"timepicker": {},
31833300
"timezone": "browser",
31843301
"title": "System Data",
31853302
"uid": "aggregator",
3186-
"version": 7,
3303+
"version": 1,
31873304
"weekStart": ""
31883305
}

telemetry_api/lib/telemetry_api/ethereum_metrics.ex

Lines changed: 0 additions & 12 deletions
This file was deleted.

telemetry_api/lib/telemetry_api/operators.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule TelemetryApi.Operators do
99
alias TelemetryApi.Operators.Operator
1010
alias TelemetryApi.ContractManagers.OperatorStateRetriever
1111
alias TelemetryApi.ContractManagers.DelegationManager
12+
alias TelemetryApi.PrometheusMetrics
1213

1314
@doc """
1415
Returns the list of operators.
@@ -95,6 +96,18 @@ defmodule TelemetryApi.Operators do
9596
|> Enum.filter(fn {status, _} -> status == :ok end)
9697
|> Enum.map(fn {_, data} -> data end)
9798

99+
# Initialize new_operators metrics
100+
Enum.map(new_operators, fn {_, op_data} ->
101+
op_name_address = op_data.name <> " - " <> String.slice(op_data.address, 0..7)
102+
PrometheusMetrics.initialize_operator_metrics(op_name_address)
103+
end)
104+
105+
# If the server was restarted, initialize old_operators metrics
106+
Enum.map(old_operators, fn {op, _} ->
107+
op_name_address = op.name <> " - " <> String.slice(op.address, 0..7)
108+
PrometheusMetrics.initialize_operator_metrics(op_name_address)
109+
end)
110+
98111
# Merge both lists
99112
operators = (new_operators ++ old_operators)
100113

telemetry_api/lib/telemetry_api/periodically.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule TelemetryApi.Periodically do
22
use GenServer
33
alias TelemetryApi.Operators
4-
alias TelemetryApi.EthereumMetrics
4+
alias TelemetryApi.PrometheusMetrics
55
alias TelemetryApi.ContractManagers.RegistryCoordinatorManager
66
require Logger
77

@@ -45,7 +45,7 @@ defmodule TelemetryApi.Periodically do
4545
def handle_info(:gas_price, _state) do
4646
case Ethers.current_gas_price() do
4747
{:ok, gas_price} ->
48-
EthereumMetrics.new_gas_price(gas_price)
48+
PrometheusMetrics.new_gas_price(gas_price)
4949

5050
{:error, error} ->
5151
IO.inspect("Error fetching gas price: #{error}")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
defmodule TelemetryApi.PrometheusMetrics do
2+
use Prometheus.Metric
3+
4+
@gauge [name: :gas_price, help: "Ethereum Gas Price.", labels: []]
5+
@counter [name: :missing_operator_count, help: "Missing Operators", labels: [:operator]]
6+
7+
def new_gas_price(gas_price) do
8+
Gauge.set(
9+
[name: :gas_price, labels: []],
10+
gas_price
11+
)
12+
end
13+
14+
def missing_operator(operator) do
15+
Counter.inc(
16+
name: :missing_operator_count,
17+
labels: [operator]
18+
)
19+
end
20+
21+
def initialize_operator_metrics(operator) do
22+
value =
23+
Counter.value(
24+
name: :missing_operator_count,
25+
labels: [operator]
26+
)
27+
28+
if value == :undefined do
29+
Counter.inc(
30+
[name: :missing_operator_count, labels: [operator]],
31+
0
32+
)
33+
end
34+
end
35+
end

telemetry_api/lib/telemetry_api/traces.ex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule TelemetryApi.Traces do
55
alias TelemetryApi.Traces.Trace
66
alias TelemetryApi.Operators
77
alias TelemetryApi.ContractManagers.StakeRegistry
8+
alias TelemetryApi.PrometheusMetrics
89

910
require OpenTelemetry.Tracer
1011
require OpenTelemetry.Ctx
@@ -208,7 +209,6 @@ defmodule TelemetryApi.Traces do
208209
:ok
209210
end
210211
end
211-
212212

213213
@doc """
214214
Registers the sending of a batcher task to Ethereum in the task trace.
@@ -298,7 +298,7 @@ defmodule TelemetryApi.Traces do
298298
:ok
299299
end
300300
end
301-
301+
302302
@doc """
303303
Registers a set gas price when the aggregator tries to respond to a task in the task trace.
304304
@@ -368,8 +368,17 @@ defmodule TelemetryApi.Traces do
368368
defp add_missing_operators([]), do: :ok
369369

370370
defp add_missing_operators(missing_operators) do
371+
# Concatenate name + address
372+
missing_operators =
373+
missing_operators
374+
|> Enum.map(fn op -> op.name <> " - " <> String.slice(op.address, 0..7) end)
375+
376+
# Send to prometheus
377+
missing_operators
378+
|> Enum.map(fn o -> PrometheusMetrics.missing_operator(o) end)
379+
371380
missing_operators =
372-
missing_operators |> Enum.map(fn o -> o.name end) |> Enum.join(";")
381+
missing_operators |> Enum.join(";")
373382

374383
Tracer.add_event("Missing Operators", [{:operators, missing_operators}])
375384
end

0 commit comments

Comments
 (0)