Skip to content

Commit 086b1d4

Browse files
Hayim.Shaul@ibm.comAkramBitar
authored andcommitted
docs: document exported metric names and coverage gaps
The SDK never spells out the metric names Prometheus exports. The fully-qualified name is assembled at registration time from the Go package of the caller, and the TMS-scoped provider in token/core/common/metrics adds a stack frame, so metrics created through it are exported under that package rather than their own. Documentation written from the bare Name field of the options therefore lists names no query matches. Add docs/development/metrics.md: the derivation rules, every metric under the name Prometheus actually serves, its type, labels, meaning and source, example queries, and a ranked analysis of what a node still cannot report. Guard the page with token/services/metricsdoc, which instantiates every metrics constructor the way production wires it, reads the resulting names back out of a Prometheus registry, and compares them against a golden file and against the page itself. Renaming, adding or relocating a metric fails the test until the documentation is updated. Which provider a constructor receives is as much a part of the exported name as the opts are, so it is checked rather than assumed. The token drivers are pinned as the only files in the repository that build a TMS-scoped provider, and as building it from the container's provider, so the scope of each group follows by exhaustion; dropping the wrapper fails the test instead of quietly renaming twenty-one metrics. Every production call site a group claims must also still contain that call. Two ways the guard could reject a correct page are fixed: the PromQL suffix fold now applies only onto registered histogram families, so a metric whose own name ends in _count, _sum or _bucket survives it; and the reverse check uses an explicit prose allowlist rather than accepting any documented name that is a prefix of a registered one, which had let truncations through. Each group is instantiated against its own provider and registry, so the declared and exported metrics cannot be mispaired by the provider's deduplication, and a genuine clash is reported by name. Add the Grafana overview dashboard, revived from #1749 with the names this change pins. That dashboard closed unmerged because every one of its 51 panel queries and 4 variable queries named the bare Name field from the Go source and so matched nothing. The substitution here is derived from the golden file rather than transcribed. A row is added for the four identity signer-resolution metrics that had no panel, so every exported metric is now covered. The dashboard's queries are guarded too. Each check covers a failure Grafana does not report as an error - it renders "No data", which is indistinguishable from an idle node: every metric named must be registered, every name must carry its package prefix, every label filtered or grouped on must be declared by that metric, and every variable must be a Grafana built-in or declared by the dashboard. Run against #1749's original file, the guard reports 53 findings. PromQL syntax is deliberately not parsed: it would need a new dependency, the exprs contain Grafana variables that are not valid PromQL, and it is the one failure mode Grafana surfaces itself. The guard checks names, not rendering; the file has not been imported into a live Grafana, so panel presentation is unverified. Export NewMetrics/NewClientMetrics in the auditor, certification and Fabric-X queue packages so the guard can build their instrumentation without constructing the surrounding service. Correct docs/drivers/metrics.md, which listed declared names as if they were queryable, and make docs/development/monitoring.md the entry point. Signed-off-by: Hayim.Shaul@ibm.com <hayimsha@fhe03.vpc.cloud9.ibm.com> Signed-off-by: AkramBitar <akram@il.ibm.com> Signed-off-by: Hayim.Shaul@ibm.com <hayimsha@fhe03.vpc.cloud9.ibm.com>
1 parent f4fb939 commit 086b1d4

16 files changed

Lines changed: 2887 additions & 23 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ linters:
120120
- github.com/hyperledger/fabric-lib-go/common/metrics.Gauge
121121
- github.com/hyperledger/fabric-lib-go/common/metrics.Histogram
122122
- github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics.Gauge
123+
- github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics.Histogram
123124
- github.com/hyperledger-labs/fabric-smart-client/platform/common/driver.ConfigService
124125
- github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api.ViewClient
125126
- github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api.Platform

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ If you are developing *using* Panurus or contributing *to* Panurus, check out th
3535
* [General Guidelines](development/general.md)
3636
* [Idiomatic Go](development/idiomatic.md)
3737
* [Testing](development/testing.md)
38+
* [Monitoring](development/monitoring.md), the [Metrics Reference](development/metrics.md) and the
39+
[Grafana dashboards](monitoring/grafana/README.md)
3840
* [Test & Benchmark Profiler](../cmd/profiler/README.md)
3941

4042
## Evolution

docs/development/development.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This page contains link to the development guidelines and more.
88
- [Development Tools](./tools.md)
99
- [Linting](./linting.md)
1010
- [Monitoring](./monitoring.md)
11+
- [Metrics Reference](./metrics.md)
12+
- [Grafana dashboards](../monitoring/grafana/README.md)
1113
- [Mock Files Generation](./mock.md)
1214
- [AI Agents Best Practices](./ai_agents.md)
1315
- [Tools: tokengen](./tokengen.md)

docs/development/metrics.md

Lines changed: 413 additions & 0 deletions
Large diffs are not rendered by default.

docs/development/monitoring.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
# Monitoring
22

3-
We adopt the monitoring infrastructure provided by the [`Fabric Smart Client`](https://github.com/hyperledger-labs/fabric-smart-client/blob/main/docs/platform/view/monitoring.md).
3+
We adopt the monitoring infrastructure provided by the [`Fabric Smart Client`](https://github.com/hyperledger-labs/fabric-smart-client/blob/main/docs/platform/view/services/monitoring.md).
44

55
We use the following two methods to monitor the performance of the application:
66
* **Metrics** provide an overview of the overall system performance using aggregated results, e.g. total requests, requests per second, current state of a variable, average duration, percentile of duration
77
* **Traces** help us analyze single requests by breaking down their lifecycles into smaller components
8+
9+
## Where to look next
10+
11+
* [Metrics Reference](./metrics.md) — every metric Panurus exports, under the exact name Prometheus
12+
serves it, plus how those names are derived, example queries, and the current coverage gaps.
13+
* [Grafana dashboards](../monitoring/grafana/README.md) — an importable overview dashboard covering
14+
every exported metric, and what to run after editing a query.
15+
* [Driver Metrics](../drivers/metrics.md) — how the driver service wrappers are built and which
16+
methods they instrument.
17+
* [Fabric Smart Client monitoring](https://github.com/hyperledger-labs/fabric-smart-client/blob/main/docs/platform/view/services/monitoring.md)
18+
— the platform metrics and traces Panurus inherits (views, sessions, gRPC, process), and how to
19+
enable the Prometheus endpoint and the tracing exporter.

docs/drivers/metrics.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ implementation, and records three metrics per method invocation:
2020
| **Histogram** (`*_duration_seconds`) | Execution duration of each call |
2121
| **Counter** (`*_errors_total`) | Total number of calls that returned an error |
2222

23+
The metric names in this page are the **declared** names, as written in the wrapper sources.
24+
Prometheus exports them under a prefix derived from the package that creates them; because the driver
25+
wrappers receive a TMS-scoped provider, every metric below is exported as
26+
`panurus_core_common_metrics_<declared name>` — for instance `issue_service_operations_total` is
27+
queried as `panurus_core_common_metrics_issue_service_operations_total`. See
28+
[Metrics Reference](../development/metrics.md) for the derivation rules and the exported names of
29+
every metric in the SDK.
30+
2331
All metrics carry four labels for multi-TMS filtering:
2432

2533
| Label | Description |
@@ -136,27 +144,12 @@ Metrics emitted:
136144

137145
## Metric Reference
138146

139-
The full list of metrics emitted by the driver wrappers:
140-
141-
| Metric Name | Type | Description |
142-
|-------------|------|-------------|
143-
| `issue_service_operations_total` | Counter | Total `IssueService` method invocations |
144-
| `issue_service_duration_seconds` | Histogram | Duration of `IssueService` method calls |
145-
| `issue_service_errors_total` | Counter | Total `IssueService` method errors |
146-
| `transfer_service_operations_total` | Counter | Total `TransferService` method invocations |
147-
| `transfer_service_duration_seconds` | Histogram | Duration of `TransferService` method calls |
148-
| `transfer_service_errors_total` | Counter | Total `TransferService` method errors |
149-
| `auditor_service_operations_total` | Counter | Total `AuditorService` method invocations |
150-
| `auditor_service_duration_seconds` | Histogram | Duration of `AuditorService` method calls |
151-
| `auditor_service_errors_total` | Counter | Total `AuditorService` method errors |
152-
| `tokens_service_operations_total` | Counter | Total `TokensService` method invocations |
153-
| `tokens_service_duration_seconds` | Histogram | Duration of `TokensService` method calls |
154-
| `tokens_service_errors_total` | Counter | Total `TokensService` method errors |
155-
| `tokens_upgrade_service_operations_total` | Counter | Total `TokensUpgradeService` method invocations |
156-
| `tokens_upgrade_service_duration_seconds` | Histogram | Duration of `TokensUpgradeService` method calls |
157-
| `tokens_upgrade_service_errors_total` | Counter | Total `TokensUpgradeService` method errors |
158-
159-
All metrics use labels: `network`, `channel`, `namespace`, `method`.
147+
The exported names, types and labels of the fifteen driver metrics are listed in
148+
[Metrics Reference — Driver services](../development/metrics.md#driver-services). That page is kept in
149+
step with the code by `token/services/metricsdoc`, so it is the authoritative list; this page describes
150+
only how the wrappers work and which methods they instrument.
151+
152+
All driver metrics use labels: `network`, `channel`, `namespace`, `method`.
160153

161154
## Source
162155

docs/monitoring/grafana/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Grafana dashboards
2+
3+
## `panurus.json` — Panurus Overview
4+
5+
A single overview dashboard covering every metric Panurus exports: 20 panels across 9 rows, one row per
6+
subsystem (driver services, transaction lifecycle, finality listener, envelope sessions, auditor, token
7+
selection, certification and identity caches, signer resolution and cache provisioning, Fabric-X finality
8+
queue).
9+
10+
### Import
11+
12+
1. Grafana → **Dashboards****New****Import***Upload JSON file*.
13+
2. Pick the Prometheus data source that scrapes the node's metrics endpoint when prompted for
14+
`DS_PROMETHEUS`.
15+
16+
The dashboard declares four template variables — `network`, `channel`, `namespace` and `method` — whose
17+
values are discovered with `label_values` against
18+
`panurus_core_common_metrics_transfer_service_operations_total`. A node that has never issued or
19+
transferred a token exports no series for that metric, so the pickers stay empty until the first
20+
transaction; the unfiltered panels still work.
21+
22+
Requires Grafana 9.0 or later (`schemaVersion` 37).
23+
24+
### Not covered
25+
26+
- **FSC platform metrics** (views, sessions, gRPC, process) — these come from
27+
[Fabric Smart Client](https://github.com/hyperledger-labs/fabric-smart-client/blob/main/docs/platform/view/services/monitoring.md)
28+
and are exported under `fsc_*`, not `panurus_*`.
29+
- **Traces.** The dashboard is metrics-only.
30+
- Panels are built from metric *names*, so they show what a node reports, not whether the reported
31+
numbers are healthy: there are no thresholds or alert rules here.
32+
33+
### Changing it
34+
35+
Every query in this file is checked by `token/services/metricsdoc`, which asserts that
36+
37+
- each metric a query names is one the SDK registers, under the name Prometheus actually exports;
38+
- each metric name carries its package prefix, so a bare `Name` from the Go source fails the build
39+
rather than rendering an empty panel;
40+
- each label a query filters or groups on is declared by the metric it is applied to;
41+
- each `$variable` a query interpolates is either a Grafana built-in or declared in this dashboard.
42+
43+
These are the failure modes a dashboard cannot report itself: Grafana does not error on an unknown
44+
metric or an absent label, it renders **No data**, which is indistinguishable from an idle node. An
45+
earlier version of this dashboard ([#1749](https://github.com/LFDT-Panurus/panurus/pull/1749)) had every
46+
one of its 51 panel queries and 4 variable queries written against bare option names from the Go source,
47+
so not one of them matched a series; it closed unmerged.
48+
49+
So: after editing a query, run
50+
51+
```bash
52+
go test ./token/services/metricsdoc/...
53+
```
54+
55+
If you add a panel for a metric that does not exist yet, add the metric first — see
56+
[Metrics Reference](../../development/metrics.md) for the exported names and
57+
[`testdata/metrics.golden`](../../../token/services/metricsdoc/testdata/metrics.golden) for the
58+
machine-readable list.

0 commit comments

Comments
 (0)