Repository navigation
[metrics] Switch dist.proto to proto2 - #1519
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Switch
metrics/proto/dist.protofrom proto3 to proto2, like most of our config protos (it was one of nine proto3 ones). This came up in the review of #1514.scale_factor,baseandnum_bucketsofexponential_buckets, andschemaofnative_buckets, have[default = ...].NewDistributionFromProtono longer applies defaults by hand, and the generated config docs will show them.schemaneeds (0 is a valid schema, and the default is 3). It was a proto3optionalfield 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: 0is an error (base has to be at least 1.01).scale_factor: 0gives all-zero bucket bounds, andnum_buckets: 0gives 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 asscale_factor:1 base:2 num_buckets:20in theListProbesgRPC response, the saved probes config file and the status page. It shows up asexponential_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/protoin Go; nothing in this repo is affected:ExponentialBucketsfields are pointers now, so code that sets them directly needsproto.Float32(...)etc.GetSchema()returns 3 instead of 0, andGetScaleFactor(),GetBase()andGetNumBuckets()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.protoandmetrics/payload/proto/config.protoare proto2 already.dist.pb.gois regenerated for this proto alone, with the same versions as before (protoc 33.5, protoc-gen-go v1.36.12).Testing
tools/test_example_configs.sh.-configtestwith textproto and YAML configs:exponential_bucketswith defaults and with custom values, andnative_bucketswith the default schema and withschema: 0.base: 0.