Skip to content

[metrics] Switch dist.proto to proto2 - #1519

Merged
manugarg merged 2 commits into
mainfrom
dist-proto2
Oct 4, 2026
Merged

manugarg merged 2 commits into
mainfrom
dist-proto2

Conversation

@manugarg

@manugarg manugarg commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Switch metrics/proto/dist.proto from proto3 to proto2, like most of our config protos (it was one of nine proto3 ones). This came up in the review of #1514.

  • Defaults are in the proto now — scale_factor, base and num_buckets of exponential_buckets, and schema of native_buckets, have [default = ...]. NewDistributionFromProto no longer applies defaults by hand, and the generated config docs will show them.
  • Unset vs zero — proto2 tells them apart, which the native buckets schema needs (0 is a valid schema, and the default is 3). It was a proto3 optional field for that reason.

Compatibility

  • Config files — textproto, YAML and JSON configs parse the same. Field names and numbers don't change.

  • Explicit zeros in exponential_buckets — they used to mean "use the default"; they're taken as is now:

    • base: 0 is an error (base has to be at least 1.01).
    • scale_factor: 0 gives all-zero bucket bounds, and num_buckets: 0 gives only the (-Inf, 0) and [0, +Inf) buckets.

    I didn't keep the old fallback, as nobody should be setting these to zero explicitly.

  • Config dumps don't have the defaults filled in anymore — the old code wrote the defaults into the parsed config, so exponential_buckets {} showed up as scale_factor:1 base:2 num_buckets:20 in the ListProbes gRPC response, the saved probes config file and the status page. It shows up as exponential_buckets:{} now. Nothing reads these values back, and parsing it again gives the same distribution. A gRPC client built with the old proto would read zeros for these fields.

  • Go API — for those who use github.com/cloudprober/cloudprober/metrics/proto in Go; nothing in this repo is affected:

    • ExponentialBuckets fields are pointers now, so code that sets them directly needs proto.Float32(...) etc.
    • Getters return the defaults for unset fields: GetSchema() returns 3 instead of 0, and GetScaleFactor(), GetBase() and GetNumBuckets() return 1, 2 and 20 instead of 0. Code that takes 0 to mean "unset" changes behaviour without a compile error.
  • Importers — probes/proto/config.proto and metrics/payload/proto/config.proto are proto2 already.

dist.pb.go is regenerated for this proto alone, with the same versions as before (protoc 33.5, protoc-gen-go v1.36.12).

Testing

  • All tests pass, and so does tools/test_example_configs.sh.
  • -configtest with textproto and YAML configs: exponential_buckets with defaults and with custom values, and native_buckets with the default schema and with schema: 0.
  • Explicit zeros behave as described above; there's a test for base: 0.

Most of our config protos are proto2. With proto2, we can specify the
defaults in the proto itself, instead of applying them in the code, and
config docs show them. It also takes care of telling an unset field
from a zero, which we need for the native buckets schema.

This doesn't change how configs are parsed, except for explicit zeros
in exponential_buckets. They used to mean "use the default", and are
taken as is now: "base: 0" is an error, as base has to be at least 1.01.

For Go users of the proto package, ExponentialBuckets fields are now
pointers.
@manugarg
manugarg marked this pull request as ready for review October 4, 2026 07:51
@manugarg
manugarg merged commit 2018427 into main Oct 4, 2026
13 checks passed
@manugarg
manugarg deleted the dist-proto2 branch October 4, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant