Skip to content

Commit 91d9af7

Browse files
committed
fix(monitoring): rename function to coexist with upstream features.metrics fix
Upstream c355bca added ensureMetricsEnabled() for features.metrics=true, deliberately a SAFE NO-OP on templates without a prometheus block (nile/private — tracked in upstream issue #167) so it never synthesises into those templates. Our monitoring path needs the opposite behaviour: when monitoring.enabled is true, we must actively synthesise the prometheus block on nile/private (otherwise java-tron never exposes 9527 and Grafana stays empty on private networks — the most common monitoring use-case). Rename our function to ensureMetricsForMonitoring() so both behaviours coexist without changing upstream's contract. Once upstream resolves #167 by adding a prometheus block to nile/private templates, the two functions can be merged in a follow-up.
1 parent cc67a4d commit 91d9af7

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

internal/render/hocon.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func RenderHOCON(templateDir string, i *intent.Intent, node *intent.NodeSpec) (s
4646

4747
// Monitoring: auto-enable prometheus metrics in HOCON.
4848
if i.Monitoring != nil && i.Monitoring.Enabled != nil && *i.Monitoring.Enabled {
49-
config = ensureMetricsEnabled(config)
49+
config = ensureMetricsForMonitoring(config)
5050
}
5151

5252
// 2. Trailing override block (network_overrides + witness_key + config_overrides).
@@ -482,12 +482,19 @@ func ensureJSONRPCEnabled(config string) string {
482482
return config
483483
}
484484

485-
// ensureMetricsEnabled sets node.metrics.prometheus.enable = true in the HOCON
486-
// config. It handles three cases:
485+
// ensureMetricsForMonitoring sets node.metrics.prometheus.enable = true in
486+
// the HOCON config, synthesising the surrounding blocks when missing. This
487+
// is the active form used when monitoring.enabled=true — the user has
488+
// explicitly opted in to monitoring, so we *do* want to inject a prometheus
489+
// block into templates (nile/private) that lack one. Compare the simpler
490+
// SAFE NO-OP variant `ensureMetricsEnabled` used by features.metrics, which
491+
// only flips an existing flag and never synthesises blocks.
492+
//
493+
// Three cases:
487494
// 1. node.metrics { prometheus { enable = false } } → set to true
488495
// 2. node.metrics { prometheus { ... } } (no enable) → insert enable = true
489496
// 3. node.metrics block missing entirely → append a new block
490-
func ensureMetricsEnabled(config string) string {
497+
func ensureMetricsForMonitoring(config string) string {
491498
lines := strings.Split(config, "\n")
492499
inMetrics := false
493500
inPrometheus := false

internal/render/hocon_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,44 +286,44 @@ func TestReplaceHOCONValue(t *testing.T) {
286286
}
287287
}
288288

289-
func TestEnsureMetricsEnabled_ExistingEnableFalse(t *testing.T) {
289+
func TestEnsureMetricsForMonitoring_ExistingEnableFalse(t *testing.T) {
290290
in := `node.metrics {
291291
prometheus {
292292
enable = false
293293
port = 9527
294294
}
295295
}`
296-
out := ensureMetricsEnabled(in)
296+
out := ensureMetricsForMonitoring(in)
297297
if !strings.Contains(out, "enable = true") {
298298
t.Errorf("expected enable = true, got:\n%s", out)
299299
}
300300
}
301301

302-
func TestEnsureMetricsEnabled_NoEnableField(t *testing.T) {
302+
func TestEnsureMetricsForMonitoring_NoEnableField(t *testing.T) {
303303
in := `node.metrics {
304304
prometheus {
305305
port = 9527
306306
}
307307
}`
308-
out := ensureMetricsEnabled(in)
308+
out := ensureMetricsForMonitoring(in)
309309
if !strings.Contains(out, "enable = true") {
310310
t.Errorf("expected enable = true inserted, got:\n%s", out)
311311
}
312312
}
313313

314-
func TestEnsureMetricsEnabled_NoPrometheusBlock(t *testing.T) {
314+
func TestEnsureMetricsForMonitoring_NoPrometheusBlock(t *testing.T) {
315315
in := `node.metrics {
316316
something = else
317317
}`
318-
out := ensureMetricsEnabled(in)
318+
out := ensureMetricsForMonitoring(in)
319319
if !strings.Contains(out, "prometheus {") || !strings.Contains(out, "enable = true") {
320320
t.Errorf("expected prometheus block inserted, got:\n%s", out)
321321
}
322322
}
323323

324-
func TestEnsureMetricsEnabled_MissingMetricsBlock(t *testing.T) {
324+
func TestEnsureMetricsForMonitoring_MissingMetricsBlock(t *testing.T) {
325325
in := `some.config = value`
326-
out := ensureMetricsEnabled(in)
326+
out := ensureMetricsForMonitoring(in)
327327
if !strings.Contains(out, "node.metrics {") || !strings.Contains(out, "prometheus {") {
328328
t.Errorf("expected full metrics block appended, got:\n%s", out)
329329
}

0 commit comments

Comments
 (0)