-
Notifications
You must be signed in to change notification settings - Fork 59
feat: add a new feature enablement mechanism #1689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shollyman
merged 11 commits into
googleapis:main
from
shollyman:experimental-enablement
Jan 30, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3b73ebe
feat: add a new feature enablement mechanism
shollyman d7fd903
add missing files
shollyman a785af9
add tests
shollyman 4fa9396
update bazel rules
shollyman ca11036
address reviewer feedback
shollyman 762c020
Merge branch 'main' into experimental-enablement
shollyman a8f555d
update comment
shollyman d825208
updates based on reviewer feedback
shollyman e0a73d0
docs
shollyman bcc7e87
bool -> struct{} for feature map
shollyman 88944ca
add bugref
shollyman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package gengapic | ||
|
|
||
| import "google.golang.org/protobuf/types/pluginpb" | ||
|
|
||
| // We use a custom type for feature ID to clarify that features are setup explicitly. | ||
| type featureID string | ||
|
|
||
| // featureInfo contains basic information about features, and provides an extensible mechanism | ||
| // for adding more infomation down the line (maturity level, warning about stale experiments, etc) | ||
| type featureInfo struct { | ||
| // Short summary of feature. | ||
| Description string | ||
|
|
||
| // Tracking ID for more information. Github issue, internal b/ issue, etc. | ||
| TrackingID string | ||
| } | ||
|
|
||
| // Define feature ID strings here. More details about features are kept in the featureRegistry map. | ||
| const ( | ||
| WrapperTypesForPageSizeFeature featureID = "wrapper_types_for_page_size" | ||
| OrderedRoutingHeadersFeature featureID = "ordered_routing_headers" | ||
| MTLSHardBoundTokensFeature featureID = "mtls_hard_bound_tokens" | ||
| ) | ||
|
|
||
| // featureRegistry contains the registry of defined features. | ||
| // Introducing a new capability to the generator generally starts here, as features | ||
| // must be registered to be enabled. This should not be modified at runtime. Those | ||
| // who attempt to do so will be given a stern talking to. | ||
| var featureRegistry = map[featureID]*featureInfo{ | ||
| MTLSHardBoundTokensFeature: { | ||
| Description: "support MTLS hard bound tokens", | ||
|
shollyman marked this conversation as resolved.
|
||
| TrackingID: "b/327916505", | ||
| }, | ||
| OrderedRoutingHeadersFeature: { | ||
| Description: "Specify that routing headers are emitted in a deterministic fashion. Primarily used for firestore.", | ||
| }, | ||
| WrapperTypesForPageSizeFeature: { | ||
| Description: "Allow List RPCs to generator with support for protobuf wrapper types (e.g. Int32Value, etc).", | ||
| TrackingID: "b/352331075", | ||
| }, | ||
| } | ||
|
|
||
| // legacyFeatureEnablementByPackage is temporary bridge functionality. Features should be enabled via protoc flags, but | ||
|
quartzmo marked this conversation as resolved.
|
||
| // to bootstrap without breaking generation we keep the legacy definitions enabled here until we can move | ||
| // configuration upstream into tools like librarian/bazel/etc as needed. | ||
| var legacyFeatureEnablementByPackage = map[featureID][]string{ | ||
| OrderedRoutingHeadersFeature: []string{ | ||
| "google.firestore.v1", | ||
| "google.firestore.admin.v1", | ||
| }, | ||
| WrapperTypesForPageSizeFeature: []string{ | ||
| "google.cloud.bigquery.v2", | ||
| }, | ||
| } | ||
|
|
||
| // similar to legacyFeatureEnablementByPackage, this is legacy feature enablement using the "name" field from the API | ||
| // service config. | ||
| var legacyFeatureEnablementByAPIName = map[featureID][]string{ | ||
| MTLSHardBoundTokensFeature: []string{ | ||
| "bigquery.googleapis.com", | ||
| "cloudasset.googleapis.com", | ||
| "clouderrorreporting.googleapis.com", | ||
| "cloudkms.googleapis.com", | ||
| "cloudresourcemanager.googleapis.com", | ||
| "cloudtasks.googleapis.com", | ||
| "cloudtrace.googleapis.com", | ||
| "dataflow.googleapis.com", | ||
| "datastore.googleapis.com", | ||
| "essentialcontacts.googleapis.com", | ||
| "firestore.googleapis.com", | ||
| "iam.googleapis.com", | ||
| "iamcredentials.googleapis.com", | ||
| "logging.googleapis.com", | ||
| "monitoring.googleapis.com", | ||
| "orgpolicy.googleapis.com", | ||
| "pubsub.googleapis.com", | ||
| "recommender.googleapis.com", | ||
| "secretmanager.googleapis.com", | ||
| "showcase.googleapis.com", | ||
| }, | ||
| } | ||
|
|
||
| // This function consolidates legacy processing of feature enablements. | ||
| // Like the associated allowlists, it should go away once librarian and bazel can pass feature enablements directly. | ||
| func processLegacyEnablements(cfg *generatorConfig, req *pluginpb.CodeGeneratorRequest) { | ||
| // Use the first proto file in the FileDescriptorSet to handle legacy enablement by package name. | ||
|
quartzmo marked this conversation as resolved.
|
||
| if len(req.GetProtoFile()) > 0 { | ||
| probePackage := req.GetProtoFile()[0].GetPackage() | ||
| for f, packages := range legacyFeatureEnablementByPackage { | ||
| for _, v := range packages { | ||
| if probePackage == v { // matched | ||
| if cfg.featureEnablement == nil { | ||
| cfg.featureEnablement = make(map[featureID]struct{}) | ||
| } | ||
| cfg.featureEnablement[f] = struct{}{} | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // Now, process legacy feature enablements based on API name. | ||
| if cfg.APIServiceConfig != nil { | ||
| probeName := cfg.APIServiceConfig.GetName() | ||
| for f, apis := range legacyFeatureEnablementByAPIName { | ||
| for _, v := range apis { | ||
| if probeName == v { // matched | ||
| if cfg.featureEnablement == nil { | ||
| cfg.featureEnablement = make(map[featureID]struct{}) | ||
| } | ||
| cfg.featureEnablement[f] = struct{}{} | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package gengapic | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "google.golang.org/genproto/googleapis/api/serviceconfig" | ||
| "google.golang.org/protobuf/proto" | ||
| "google.golang.org/protobuf/types/descriptorpb" | ||
| "google.golang.org/protobuf/types/pluginpb" | ||
| ) | ||
|
|
||
| func TestProcessLegacyEnablements(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| desc string | ||
| protoPkg string | ||
| apiName string | ||
| wantFeaturesEnabled []featureID | ||
| wantFeatureDisabled []featureID | ||
| }{ | ||
| { | ||
| desc: "default", | ||
| wantFeatureDisabled: []featureID{ | ||
| MTLSHardBoundTokensFeature, | ||
| OrderedRoutingHeadersFeature, | ||
| WrapperTypesForPageSizeFeature, | ||
| }, | ||
| }, | ||
| { | ||
| desc: "bigquery package", | ||
| protoPkg: "google.cloud.bigquery.v2", | ||
| wantFeaturesEnabled: []featureID{WrapperTypesForPageSizeFeature}, | ||
| }, | ||
| { | ||
| desc: "bigquery package only", | ||
| protoPkg: "google.cloud.bigquery.v2", | ||
| wantFeaturesEnabled: []featureID{WrapperTypesForPageSizeFeature}, | ||
| wantFeatureDisabled: []featureID{OrderedRoutingHeadersFeature, MTLSHardBoundTokensFeature}, | ||
| }, | ||
| { | ||
| desc: "firestore admin package only", | ||
| protoPkg: "google.firestore.admin.v1", | ||
| wantFeaturesEnabled: []featureID{OrderedRoutingHeadersFeature}, | ||
| wantFeatureDisabled: []featureID{WrapperTypesForPageSizeFeature, MTLSHardBoundTokensFeature}, | ||
| }, | ||
| { | ||
| desc: "cloud kms api name", | ||
| apiName: "cloudkms.googleapis.com", | ||
| wantFeaturesEnabled: []featureID{MTLSHardBoundTokensFeature}, | ||
| wantFeatureDisabled: []featureID{WrapperTypesForPageSizeFeature, OrderedRoutingHeadersFeature}, | ||
| }, | ||
| } { | ||
| t.Run(tc.desc, func(t *testing.T) { | ||
| req := &pluginpb.CodeGeneratorRequest{ | ||
| Parameter: proto.String("go-gapic-package=foo/bar/baz;baz"), | ||
| ProtoFile: []*descriptorpb.FileDescriptorProto{ | ||
| { | ||
| Package: proto.String("foo"), | ||
| }, | ||
| }, | ||
| } | ||
| if tc.protoPkg != "" { | ||
| req.ProtoFile[0].Package = proto.String(tc.protoPkg) | ||
| } | ||
| cfg, err := configFromRequest(req.Parameter) | ||
| if err != nil { | ||
| t.Fatalf("configFromRequest err: %v", err) | ||
| } | ||
| if tc.apiName != "" { | ||
| cfg.APIServiceConfig = &serviceconfig.Service{ | ||
| Name: tc.apiName, | ||
| } | ||
| } | ||
| g := &generator{cfg: cfg} | ||
| processLegacyEnablements(cfg, req) | ||
| for _, f := range tc.wantFeaturesEnabled { | ||
| if !g.featureEnabled(f) { | ||
| t.Errorf("expected feature %q enabled, was not", f) | ||
| } | ||
| } | ||
| for _, f := range tc.wantFeatureDisabled { | ||
| if g.featureEnabled(f) { | ||
| t.Errorf("expected feature %q to be disabled, was enabled", f) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.