Skip to content

Commit fbd000a

Browse files
authored
feat: support running in a dingo container (#364)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent efc8d77 commit fbd000a

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

config.yaml.example

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ node:
2121
# Name of the node you are running.
2222
#
2323
# Valid values are:
24+
# - `amaru`
2425
# - `cardano-node`
25-
# - `amaru`
26+
# - `dingo`
2627
#
2728
# This can also be set via the CARDANO_NODE_BINARY environment variable
2829
binary: cardano-node
@@ -59,13 +60,14 @@ node:
5960
# This can also be set via the CARDANO_NODE_SOCKET_PATH environment variable
6061
socketPath:
6162

62-
# The path to the PID File of your running node
63+
# Path to the PID file for the node
6364
#
6465
# This is only used when the `binary` value is `amaru`.
6566
# Otherwise it is ignored.
67+
#
68+
# This can also be set via the CARDANO_NODE_PID_FILE environment variable
6669
pidFile:
6770

68-
6971
prometheus:
7072
# host/port for the node Prometheus metrics
7173
#

main.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ import (
3838
)
3939

4040
const (
41-
CARADNO_NODE_BINARY = "cardano-node"
4241
AMARU_BINARY = "amaru"
42+
CARDANO_NODE_BINARY = "cardano-node"
43+
DINGO_BINARY = "dingo"
4344
)
4445

4546
// Global command line flags
@@ -1187,14 +1188,45 @@ func getResourceText(ctx context.Context) string {
11871188
func getProcessMetrics(ctx context.Context) (*process.Process, error) {
11881189
cfg := config.GetConfig()
11891190

1190-
if cfg.Node.Binary == AMARU_BINARY {
1191-
return getProcessMetricsByPidFile(cfg, ctx)
1192-
} else {
1193-
return getProcessMetricsByNameAndPort(cfg, ctx)
1191+
switch cfg.Node.Binary {
1192+
case AMARU_BINARY:
1193+
return getProcessMetricsByPidFile(ctx, cfg)
1194+
case DINGO_BINARY:
1195+
return getProcessMetricsByPid(ctx, 1)
1196+
default:
1197+
return getProcessMetricsByNameAndPort(ctx, cfg)
11941198
}
11951199
}
11961200

1197-
func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*process.Process, error) {
1201+
func getProcessMetricsByPid(
1202+
ctx context.Context,
1203+
pid int32,
1204+
) (*process.Process, error) {
1205+
proc, err := process.NewProcessWithContext(ctx, pid)
1206+
if err != nil {
1207+
return nil, fmt.Errorf("failed to get process %d: %w", pid, err)
1208+
}
1209+
1210+
exists, err := proc.IsRunning()
1211+
if err != nil {
1212+
return nil, fmt.Errorf(
1213+
"failed to check if process %d is running: %w",
1214+
pid,
1215+
err,
1216+
)
1217+
}
1218+
1219+
if !exists {
1220+
return nil, fmt.Errorf("process %d is not running", pid)
1221+
}
1222+
1223+
return proc, nil
1224+
}
1225+
1226+
func getProcessMetricsByPidFile(
1227+
ctx context.Context,
1228+
cfg *config.Config,
1229+
) (*process.Process, error) {
11981230
data, err := os.ReadFile(cfg.Node.PidFile)
11991231
if err != nil {
12001232
return nil, fmt.Errorf("failed to read pid file: %w", err)
@@ -1207,8 +1239,6 @@ func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*proce
12071239
if pid <= 0 || pid > math.MaxInt32 {
12081240
return nil, fmt.Errorf("invalid pid %d: out of int32 range", pid)
12091241
}
1210-
1211-
// the overflow is checked above
12121242
//nolint:gosec
12131243
proc, err := process.NewProcessWithContext(ctx, int32(pid))
12141244
if err != nil {
@@ -1217,7 +1247,11 @@ func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*proce
12171247

12181248
exists, err := proc.IsRunning()
12191249
if err != nil {
1220-
return nil, fmt.Errorf("failed to check if process %d is running: %w", pid, err)
1250+
return nil, fmt.Errorf(
1251+
"failed to check if process %d is running: %w",
1252+
pid,
1253+
err,
1254+
)
12211255
}
12221256

12231257
if !exists {
@@ -1227,7 +1261,10 @@ func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*proce
12271261
return proc, nil
12281262
}
12291263

1230-
func getProcessMetricsByNameAndPort(cfg *config.Config, ctx context.Context) (*process.Process, error) {
1264+
func getProcessMetricsByNameAndPort(
1265+
ctx context.Context,
1266+
cfg *config.Config,
1267+
) (*process.Process, error) {
12311268
r, _ := process.NewProcessWithContext(ctx, 0)
12321269
processes, err := process.ProcessesWithContext(ctx)
12331270
if err != nil {

peers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ func pingPeers(ctx context.Context) error {
208208
return
209209
}
210210
}
211+
if len(peerStats.RTTresultsMap) == 0 {
212+
peerStats.RTTresultsMap = make(
213+
peerRTTresultsMap,
214+
len(peersFiltered),
215+
)
216+
}
211217

212218
// Start RTT loop
213219
// for tool in ... return peerRTT

prometheus.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
dto "github.com/prometheus/client_model/go"
2525
"github.com/prometheus/common/expfmt"
26+
"github.com/prometheus/common/model"
2627
)
2728

2829
// Track current epoch
@@ -108,7 +109,7 @@ func prom2json(prom []byte) ([]byte, error) {
108109
// {"name": 0}
109110
out := make(map[string]any)
110111
b := []byte{}
111-
parser := &expfmt.TextParser{}
112+
parser := expfmt.NewTextParser(model.UTF8Validation)
112113
families, err := parser.TextToMetricFamilies(
113114
strings.NewReader(string(prom)),
114115
)

0 commit comments

Comments
 (0)