Skip to content

Commit a752363

Browse files
author
Hayim.Shaul@ibm.com
committed
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. 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>
1 parent 276f27e commit a752363

12 files changed

Lines changed: 1054 additions & 22 deletions

File tree

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ If you are developing *using* Panurus or contributing *to* Panurus, check out th
3030
* [General Guidelines](development/general.md)
3131
* [Idiomatic Go](development/idiomatic.md)
3232
* [Testing](development/testing.md)
33+
* [Monitoring](development/monitoring.md) and the [Metrics Reference](development/metrics.md)
3334
* [Test & Benchmark Profiler](../cmd/profiler/README.md)
3435

3536
## Evolution

docs/development/development.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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)
1112
- [Mock Files Generation](./mock.md)
1213
- [AI Agents Best Practices](./ai_agents.md)
1314
- [Tools: tokengen](./tokengen.md)

docs/development/metrics.md

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

docs/development/monitoring.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ We adopt the monitoring infrastructure provided by the [`Fabric Smart Client`](h
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+
* [Driver Metrics](../drivers/metrics.md) — how the driver service wrappers are built and which
14+
methods they instrument.
15+
* [Fabric Smart Client monitoring](https://github.com/hyperledger-labs/fabric-smart-client/blob/main/docs/platform/view/monitoring.md)
16+
— the platform metrics and traces Panurus inherits (views, sessions, gRPC, process), and how to
17+
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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/jackc/pgxlisten v0.0.0-20250802141604-12b92425684c
2323
github.com/onsi/ginkgo/v2 v2.32.0
2424
github.com/onsi/gomega v1.42.1
25+
github.com/prometheus/client_golang v1.24.1
2526
github.com/stretchr/testify v1.11.1
2627
github.com/tidwall/gjson v1.19.0
2728
go.opentelemetry.io/otel/trace v1.44.0
@@ -100,7 +101,6 @@ require (
100101
github.com/pelletier/go-toml/v2 v2.3.1 // indirect
101102
github.com/pkg/errors v0.9.1 // indirect
102103
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
103-
github.com/prometheus/client_golang v1.24.1 // indirect
104104
github.com/prometheus/client_model v0.6.2 // indirect
105105
github.com/prometheus/common v0.70.1 // indirect
106106
github.com/prometheus/procfs v0.21.1 // indirect

token/services/auditor/metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ func newMetrics(p metrics.Provider) *Metrics {
7070
}
7171
}
7272

73+
// NewMetrics creates a new Metrics instance with the given provider.
74+
// It is exported so that the metrics reference guard can instantiate the
75+
// auditor instrumentation without building a full Service; see
76+
// docs/development/metrics.md.
77+
func NewMetrics(p metrics.Provider) *Metrics {
78+
return newMetrics(p)
79+
}
80+
7381
// noopProvider discards all observations. Used when no provider is configured.
7482
type noopProvider struct{}
7583

token/services/certifier/interactive/metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ type ClientMetrics struct {
6868
DroppedTokens metrics.Counter
6969
}
7070

71+
// NewClientMetrics creates a new ClientMetrics instance with the given provider.
72+
// It is exported so that the metrics reference guard can instantiate the
73+
// certification client instrumentation without building a full
74+
// CertificationClient; see docs/development/metrics.md.
75+
func NewClientMetrics(p metrics.Provider) *ClientMetrics {
76+
return newClientMetrics(p)
77+
}
78+
7179
func newClientMetrics(p metrics.Provider) *ClientMetrics {
7280
return &ClientMetrics{
7381
RequestDuration: p.NewHistogram(certificationRequestDuration),

token/services/metricsdoc/doc.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// Package metricsdoc guards the metrics reference in docs/development/metrics.md.
8+
//
9+
// The SDK never spells out the metric names it exports: the fully-qualified
10+
// Prometheus name of a metric is assembled at registration time from the Go
11+
// package that creates it, so the same CounterOpts produce different exported
12+
// names depending on which package - and which provider wrapper - the metric
13+
// travels through. Documentation written from the bare Name field of the opts
14+
// therefore lists names that no Prometheus query will ever match.
15+
//
16+
// The test in this package instantiates every metrics constructor of the SDK
17+
// the way production wiring does, reads the resulting names back out of a
18+
// Prometheus registry, and compares them both against a golden file and against
19+
// the reference documentation. Adding, renaming or relocating a metric fails the
20+
// test until the documentation is updated.
21+
package metricsdoc

0 commit comments

Comments
 (0)