Conversation
Component authors had the metric registry and the cardinality rules but no single place that says how to add an instrument: which kind to pick, how to name it, which labels are allowed, how the Go is shaped, how to test it with a ManualReader, and how to register it. Each of those conventions existed only as a pattern in one of the metrics.go files. The guide sits beside tracing.md and otel-collector.md. It uses the instruments already in the tree as the examples, ends with a worked example of a node-local snapshot cache (a counter by outcome, a fill histogram, a size gauge and an eviction counter, and what is deliberately not a label). The registry snippets in the guide pass `weaver registry check` when appended to the real registry. observability.md and AGENTS.md now point at the guide from the place that already told contributors to update the registry.
| attrs := []attribute.KeyValue{ateattr.SnapshotCacheOutcomeKey.String(outcome)} | ||
| if outcome == ateattr.SnapshotCacheOutcomeError { | ||
| attrs = append(attrs, ateattr.ErrorTypeKey.String(errorType(err))) | ||
| } | ||
| i.requests.Add(context.WithoutCancel(ctx), 1, metric.WithAttributes(attrs...)) |
There was a problem hiding this comment.
ate.snapshot.kind is marked required in the Weaver Registry definition below but the code doesn't say so.
Use
attrs := []attribute.KeyValue{
ateattr.SnapshotCacheOutcomeKey.String(outcome),
ateattr.SnapshotKindKey.String(kind),
}
There was a problem hiding this comment.
Good catch. I added kind as a parameter of recordRequest and set ate.snapshot.kind next to the outcome, so every path carries it and the code matches the registry. I also added a short note after the snippet on why a required label must be known on every path.
| The `annotations.substrate` block is substrate's own and Weaver passes it | ||
| through: `emitted_by` names the binaries, `code_anchor` the file that creates | ||
| the instrument, `cuj` the question an operator answers with it, and `buckets` | ||
| the histogram boundaries. Fill all of them; a reader of the registry should not |
There was a problem hiding this comment.
Make it more specific and clear
Fill all of them -> Fill all applicable fields (including buckets for histograms); a reader of the registry should not need the code.
There was a problem hiding this comment.
Done. Changed it to: Fill all applicable fields, including buckets for a histogram.
…reement The registry entry for the example counter marked ate.snapshot.kind as required, but the record method in the Go snippet never set it. Thread kind through the method and say why a required label has to be known on every path, since that is the rule the example is meant to demonstrate. Also make the annotations guidance say which fields apply, rather than "all of them".
| Use `context.WithoutCancel(ctx)` on the `Record` or `Add` call for that case, | ||
| so the SDK does not drop the measurement along with the request. |
There was a problem hiding this comment.
Add never checks ctx.Err(),, so nothing gets dropped. Real reason is exemplars, WithoutCancel keeps the span.
There was a problem hiding this comment.
You are right. I checked the SDK, Add and Record never look at ctx.Err(), and the only thing they read from the context is the span for exemplars. I removed the WithoutCancel advice and now say to pass the request context as is. The snippet is updated too. The same wrong comment is in internal/imagecache/metrics.go, I will fix that in a separate small PR.
| |---|---|---| | ||
| | Is it helping? | `ate.snapshotcache.requests` counter, by outcome | `ate.snapshotcache.outcome`, `ate.snapshot.kind`, `error.type` on error | | ||
| | What does a miss cost? | `ate.snapshotcache.fill.duration` histogram, seconds, `snapshotPhaseBuckets` | `ate.snapshot.kind`, `ate.template.atespace`, `ate.template.name`, failure pair on failure | | ||
| | How much does it hold? | `ate.snapshotcache.size` observable gauge, bytes, plus an `ate.snapshotcache.evictions` counter | `ate.snapshot.kind`; evictions also carry an `ate.snapshotcache.eviction.reason` enum (`capacity`, `ttl`, `explicit`) | |
There was a problem hiding this comment.
This should be an UpDownCounter.
There was a problem hiding this comment.
Agreed. Bytes per kind sum to the total cache size on the node, so by our own rule it is an UpDownCounter. Changed it to an observable UpDownCounter in the example.
| Before adding a label, ask what the dashboard groups by. A label nobody will | ||
| group or filter by multiplies the series count for nothing. Three or four | ||
| labels is typical; the restore histogram, with the most, has eight, and several | ||
| are conditional. |
There was a problem hiding this comment.
Can we mention the SDK's hard limit of 2000 series per instrument here?
There was a problem hiding this comment.
Good idea. Added a paragraph on the 2000 attribute sets per instrument limit, that extra series fold into one with otel.metric.overflow=true, and that the limit is per process.
| |---|---|---|---| | ||
| | How many times something happened, and its rate | Counter | `Int64Counter` | `ate.imagecache.requests` (`internal/imagecache/metrics.go`) | | ||
| | How long or how big each occurrence was, as a distribution | Histogram | `Float64Histogram` (seconds), `Int64Histogram` (bytes) | `ate.actor.restore.duration` (`cmd/atelet/metrics.go`), `atelet.snapshot.size` (`cmd/atelet/main.go`) | | ||
| | How many things exist right now, where the sum across labels is meaningful | UpDownCounter | `Int64UpDownCounter` (you own the increments), `Int64ObservableUpDownCounter` (you can enumerate them on demand) | `atenet.router.parking.active` (`cmd/atenet/internal/router/ingress/metrics.go`), `ate.workerpool.workers` (`cmd/ateapi/internal/controlapi/metrics.go`) | |
There was a problem hiding this comment.
Can we use the examples at internal/imagecache and cmd/ateapi/internal/controlapi, which do follow the rules instead of ingress?
There was a problem hiding this comment.
Done. The table now points at ate.workerpool.workers for UpDownCounter and no longer mentions the parking instruments. The synchronous form has no clean example in the tree, so the table just notes it is rare.
| The `annotations.substrate` block is substrate's own and Weaver passes it | ||
| through: `emitted_by` names the binaries, `code_anchor` the file that creates | ||
| the instrument, `cuj` the question an operator answers with it, and `buckets` | ||
| the histogram boundaries. Fill all applicable fields, including `buckets` for a | ||
| histogram; a reader of the registry should not | ||
| need the code. |
There was a problem hiding this comment.
Should we explain golden_signals as well?
There was a problem hiding this comment.
Yes. Added a sentence on golden_signals, the four values, and that you list every one that applies so dashboard authors can find instruments by signal.
| * Follow the upstream pattern when one exists: `*.operation.name`, | ||
| `*.duration`, `error.type`. Reuse an upstream attribute verbatim rather than | ||
| aliasing it into `ate.*` (`error.type` and `file.name` are used as is). | ||
| * A label key that belongs to a subsystem is rooted at the subsystem | ||
| (`ate.imagecache.outcome`), not under `actor`, when every actor shares the | ||
| thing it describes. |
There was a problem hiding this comment.
Can we add a line mentioned to use upstream metrics, if available? Also ate.workerpool.desired_workers/ready_workers mirroring k8s.deployment.desired_pods/available_pods is a good example for the case where semconv has the shape but not the name.
There was a problem hiding this comment.
Added. The naming section now says to use the upstream semconv metric when one exists, and to mirror its shape under an ate name when only the shape fits, with desired_workers and ready_workers mirroring k8s.deployment.desired_pods and available_pods as the example.
…review The guide said to pass a context.WithoutCancel context to Add and Record so a cancelled request would not drop the measurement. The SDK never checks the context's error; it reads only the span, for exemplars. Say that instead, and pass the request context as it is in the example. Also: point the UpDownCounter row at ate.workerpool.workers rather than the parking instruments, whose label predates the ateattr rule; say to use the upstream semantic-convention metric when one exists and to mirror its shape when only the shape fits, with the desired and ready worker instruments as the example; state the SDK's 2000 attribute-set limit per instrument and what overflow looks like; explain the golden_signals annotation; and make the snapshot cache size an UpDownCounter in the worked example, since bytes per kind sum to the node's total.
| than tracking increments: | ||
|
|
||
| ```go | ||
| gauge, err := meter.Int64ObservableGauge(entriesMetric, |
There was a problem hiding this comment.
Should be an observable UpDownCounter, right?
There was a problem hiding this comment.
Yes, same mistake as the size row. Fixed it to an observable UpDownCounter. I also went through the whole doc once more against its own rules and fixed a few more things: the worked example said three instruments but listed four, the package path should be cmd/atelet/internal/snapshotcache per the code layout rules, the gauge rule of thumb had a reason for the memory gauges that the code does not actually give, and the 2000 limit is per reader. All in the latest commit.
…wn rule A full pass over the guide after review, checking each instrument choice, label, snippet and claim against the rules the guide states and against the code. The observable-instrument snippet counted snapshots per kind with a gauge. Counts per kind sum to the total, so by the guide's own rule it is an UpDownCounter; make it one. The gauge rule of thumb justified the stats memory gauges with a reason the code does not give; state the rule without that claim. The worked example said three instruments and listed four, and placed the package at cmd/atelet/snapshotcache, which the code-layout rules put under cmd/atelet/internal/. The cardinality-limit paragraph now says the limit is held per reader and names the environment variable. Smaller wording fixes in the bucket paragraph, the snippet comment and step 6.
| * **Do not use a gauge for something that is a sum.** Worker counts are an | ||
| UpDownCounter because idle plus assigned is the pool and the pools sum to the | ||
| fleet. Reserve a gauge for a level whose sum across labels means nothing: a | ||
| ratio, an age, a temperature. If you find yourself writing `sum by` over it | ||
| in a query, it was an UpDownCounter. |
There was a problem hiding this comment.
This makes your gauge example below wrong, since summing working_set per node is the normal query, and upstream sums k8s.pod.memory.usage across pods and still calls it a gauge. Better question is whether the labels split a total you own (idle plus assigned is the pool, so UpDownCounter) or just tag separate readings you sampled from elsewhere (gauge).
There was a problem hiding this comment.
Agreed and TBH this is confusing. The rule is now: did you get the number by adding and subtracting (UpDownCounter) or by reading it (gauge)? Fixed the rule, the table rows, and the two spots in the example.
… summability The guide told readers a value that gets summed is an UpDownCounter. That made its own gauge example wrong: the usual query sums memory working set per node, and upstream sums k8s.pod.memory.usage across pods and still types it as a gauge. The real test is whether the labels split a total the component owns and accounts for, or only tag readings sampled from elsewhere. State that test in the table and the rule of thumb, and reword the two places in the example that leaned on summability so they give the ownership reason.
The observable snippet instrumented a snapshot count that the worked example does not list; make it the example's own size instrument. The checklist said every label value comes from a bounded set, which the label rules contradict for template and pool names; align the two. The naming section said the exporter appends unit suffixes, which is true of the Prometheus exporter on kind and false of Cloud Monitoring, where the shipped dashboards query the OpenTelemetry name; describe both. The synchronous UpDownCounter guidance said to use it only when there is no state to enumerate, but the router's parked-request count has such state and is synchronous because the change is in hand on the request path; say that.
… dial The previous wording argued at length about whether a value gets summed, which is the point the review had just shown to be beside the point. State the one test a contributor can apply at the keyboard, explain each in-tree example by who does the adding and subtracting, and say once that downstream aggregation does not decide the instrument.
The table rows for UpDownCounter and gauge kept the earlier wording while the rule of thumb below them moved to counting versus reading a dial. Use one vocabulary in both places.
…support A line-by-line check of the guide against the tree. The working set comes from the sandbox through ateom, from a cgroup or the guest agent, not from "the cgroup". snapshotPhaseBuckets is unexported in package main, so the worked example under cmd/atelet/internal cannot reference it. ateom boots its meter provider through InitMetricsPushOnlyVia, not InitMetricsPushOnly. The router's parking label is declared locally, a recorded lint exception, so "never" needed the exception named. Not every package keeps its instruments in a metrics.go. The verify script errors on a mismatched local weaver rather than falling back. No instrument in the tree uses the ratio unit.
4a4c59a
into
agent-substrate:main
Component authors had the metric registry and the cardinality rules but no single place that says how to add an instrument: which kind to pick, how to name it, which labels are allowed, how the Go is shaped, how to test it with a ManualReader, and how to register it. Each of those conventions existed only as a pattern in one of the metrics.go files.
The guide sits beside tracing.md and otel-collector.md. It uses the instruments already in the tree as the examples, ends with a worked example of a node-local snapshot cache (a counter by outcome, a fill histogram, a size gauge and an eviction counter, and what is deliberately not a label). The registry snippets in the guide pass
weaver registry checkwhen appended to the real registry.observability.md and AGENTS.md now point at the guide from the place that already told contributors to update the registry.
Fixes #1552