googleapis / google-cloud-go

Google Cloud Client Libraries for Go.
https://cloud.google.com/go/docs/reference
Apache License 2.0
3.8k stars 1.31k forks source link

compute/computepb: Missing *Server interfaces #11192

Open krousey opened 6 days ago

krousey commented 6 days ago

Client

Compute

Environment

go version go1.23.9 linux/amd64

Code and Dependencies

package main

import  "cloud.google.com/go/compute/apiv1/computepb"

var server computpb.NetworksServer

func main() {}
go.mod ```text module modname go 1.23.0 require ( cloud.google.com/go/compute v1.28.3 ) ```

Expected behavior

I expect it to find the type and compile.

Actual behavior

It does not find the type.

main.go:5:11 undefined: computepb.NetworksServer

Additional context

If I checkout v1.28.2 of the package, everything works fine.

This commit: https://github.com/googleapis/google-cloud-go/commit/706ecb2c813da3109035b986a642ca891a33847f removed all of the generated *Server interfaces from the computepb package, and code referencing these types no longer builds with the latest versions.

Many of the interfaces were removed in this change: ```text $ git diff 706ecb2c81~ 706ecb2c81 -- compute/apiv1/computepb/compute.pb.go | grep -E -- '-type [[:upper:]]' -type AcceleratorTypesClient interface { -type AcceleratorTypesServer interface { -type UnimplementedAcceleratorTypesServer struct { -type AddressesClient interface { -type AddressesServer interface { -type UnimplementedAddressesServer struct { -type AutoscalersClient interface { -type AutoscalersServer interface { -type UnimplementedAutoscalersServer struct { -type BackendBucketsClient interface { -type BackendBucketsServer interface { -type UnimplementedBackendBucketsServer struct { -type BackendServicesClient interface { -type BackendServicesServer interface { -type UnimplementedBackendServicesServer struct { -type DiskTypesClient interface { -type DiskTypesServer interface { -type UnimplementedDiskTypesServer struct { -type DisksClient interface { -type DisksServer interface { -type UnimplementedDisksServer struct { -type ExternalVpnGatewaysClient interface { -type ExternalVpnGatewaysServer interface { -type UnimplementedExternalVpnGatewaysServer struct { -type FirewallPoliciesClient interface { -type FirewallPoliciesServer interface { -type UnimplementedFirewallPoliciesServer struct { -type FirewallsClient interface { -type FirewallsServer interface { -type UnimplementedFirewallsServer struct { -type ForwardingRulesClient interface { -type ForwardingRulesServer interface { -type UnimplementedForwardingRulesServer struct { -type GlobalAddressesClient interface { -type GlobalAddressesServer interface { -type UnimplementedGlobalAddressesServer struct { -type GlobalForwardingRulesClient interface { -type GlobalForwardingRulesServer interface { -type UnimplementedGlobalForwardingRulesServer struct { -type GlobalNetworkEndpointGroupsClient interface { -type GlobalNetworkEndpointGroupsServer interface { -type UnimplementedGlobalNetworkEndpointGroupsServer struct { -type GlobalOperationsClient interface { -type GlobalOperationsServer interface { -type UnimplementedGlobalOperationsServer struct { -type GlobalOrganizationOperationsClient interface { -type GlobalOrganizationOperationsServer interface { -type UnimplementedGlobalOrganizationOperationsServer struct { -type GlobalPublicDelegatedPrefixesClient interface { -type GlobalPublicDelegatedPrefixesServer interface { -type UnimplementedGlobalPublicDelegatedPrefixesServer struct { -type HealthChecksClient interface { -type HealthChecksServer interface { -type UnimplementedHealthChecksServer struct { -type ImageFamilyViewsClient interface { -type ImageFamilyViewsServer interface { -type UnimplementedImageFamilyViewsServer struct { -type ImagesClient interface { -type ImagesServer interface { -type UnimplementedImagesServer struct { -type InstanceGroupManagerResizeRequestsClient interface { -type InstanceGroupManagerResizeRequestsServer interface { -type UnimplementedInstanceGroupManagerResizeRequestsServer struct { -type InstanceGroupManagersClient interface { -type InstanceGroupManagersServer interface { -type UnimplementedInstanceGroupManagersServer struct { -type InstanceGroupsClient interface { -type InstanceGroupsServer interface { -type UnimplementedInstanceGroupsServer struct { -type InstanceSettingsServiceClient interface { -type InstanceSettingsServiceServer interface { -type UnimplementedInstanceSettingsServiceServer struct { -type InstanceTemplatesClient interface { -type InstanceTemplatesServer interface { -type UnimplementedInstanceTemplatesServer struct { -type InstancesClient interface { -type InstancesServer interface { -type UnimplementedInstancesServer struct { -type InstantSnapshotsClient interface { -type InstantSnapshotsServer interface { -type UnimplementedInstantSnapshotsServer struct { -type InterconnectAttachmentsClient interface { -type InterconnectAttachmentsServer interface { -type UnimplementedInterconnectAttachmentsServer struct { -type InterconnectLocationsClient interface { -type InterconnectLocationsServer interface { -type UnimplementedInterconnectLocationsServer struct { -type InterconnectRemoteLocationsClient interface { -type InterconnectRemoteLocationsServer interface { -type UnimplementedInterconnectRemoteLocationsServer struct { -type InterconnectsClient interface { -type InterconnectsServer interface { -type UnimplementedInterconnectsServer struct { -type LicenseCodesClient interface { -type LicenseCodesServer interface { -type UnimplementedLicenseCodesServer struct { -type LicensesClient interface { -type LicensesServer interface { -type UnimplementedLicensesServer struct { -type MachineImagesClient interface { -type MachineImagesServer interface { -type UnimplementedMachineImagesServer struct { -type MachineTypesClient interface { -type MachineTypesServer interface { -type UnimplementedMachineTypesServer struct { -type NetworkAttachmentsClient interface { -type NetworkAttachmentsServer interface { -type UnimplementedNetworkAttachmentsServer struct { -type NetworkEdgeSecurityServicesClient interface { -type NetworkEdgeSecurityServicesServer interface { -type UnimplementedNetworkEdgeSecurityServicesServer struct { -type NetworkEndpointGroupsClient interface { -type NetworkEndpointGroupsServer interface { -type UnimplementedNetworkEndpointGroupsServer struct { -type NetworkFirewallPoliciesClient interface { -type NetworkFirewallPoliciesServer interface { -type UnimplementedNetworkFirewallPoliciesServer struct { -type NetworksClient interface { -type NetworksServer interface { -type UnimplementedNetworksServer struct { -type NodeGroupsClient interface { -type NodeGroupsServer interface { -type UnimplementedNodeGroupsServer struct { -type NodeTemplatesClient interface { -type NodeTemplatesServer interface { -type UnimplementedNodeTemplatesServer struct { -type NodeTypesClient interface { -type NodeTypesServer interface { -type UnimplementedNodeTypesServer struct { -type PacketMirroringsClient interface { -type PacketMirroringsServer interface { -type UnimplementedPacketMirroringsServer struct { -type ProjectsClient interface { -type ProjectsServer interface { -type UnimplementedProjectsServer struct { -type PublicAdvertisedPrefixesClient interface { -type PublicAdvertisedPrefixesServer interface { -type UnimplementedPublicAdvertisedPrefixesServer struct { -type PublicDelegatedPrefixesClient interface { -type PublicDelegatedPrefixesServer interface { -type UnimplementedPublicDelegatedPrefixesServer struct { -type RegionAutoscalersClient interface { -type RegionAutoscalersServer interface { -type UnimplementedRegionAutoscalersServer struct { -type RegionBackendServicesClient interface { -type RegionBackendServicesServer interface { -type UnimplementedRegionBackendServicesServer struct { -type RegionCommitmentsClient interface { -type RegionCommitmentsServer interface { -type UnimplementedRegionCommitmentsServer struct { -type RegionDiskTypesClient interface { -type RegionDiskTypesServer interface { -type UnimplementedRegionDiskTypesServer struct { -type RegionDisksClient interface { -type RegionDisksServer interface { -type UnimplementedRegionDisksServer struct { -type RegionHealthCheckServicesClient interface { -type RegionHealthCheckServicesServer interface { -type UnimplementedRegionHealthCheckServicesServer struct { -type RegionHealthChecksClient interface { -type RegionHealthChecksServer interface { -type UnimplementedRegionHealthChecksServer struct { -type RegionInstanceGroupManagersClient interface { -type RegionInstanceGroupManagersServer interface { -type UnimplementedRegionInstanceGroupManagersServer struct { -type RegionInstanceGroupsClient interface { -type RegionInstanceGroupsServer interface { -type UnimplementedRegionInstanceGroupsServer struct { -type RegionInstanceTemplatesClient interface { -type RegionInstanceTemplatesServer interface { -type UnimplementedRegionInstanceTemplatesServer struct { -type RegionInstancesClient interface { -type RegionInstancesServer interface { -type UnimplementedRegionInstancesServer struct { -type RegionInstantSnapshotsClient interface { -type RegionInstantSnapshotsServer interface { -type UnimplementedRegionInstantSnapshotsServer struct { -type RegionNetworkEndpointGroupsClient interface { -type RegionNetworkEndpointGroupsServer interface { -type UnimplementedRegionNetworkEndpointGroupsServer struct { -type RegionNetworkFirewallPoliciesClient interface { -type RegionNetworkFirewallPoliciesServer interface { -type UnimplementedRegionNetworkFirewallPoliciesServer struct { -type RegionNotificationEndpointsClient interface { -type RegionNotificationEndpointsServer interface { -type UnimplementedRegionNotificationEndpointsServer struct { -type RegionOperationsClient interface { -type RegionOperationsServer interface { -type UnimplementedRegionOperationsServer struct { -type RegionSecurityPoliciesClient interface { -type RegionSecurityPoliciesServer interface { -type UnimplementedRegionSecurityPoliciesServer struct { -type RegionSslCertificatesClient interface { -type RegionSslCertificatesServer interface { -type UnimplementedRegionSslCertificatesServer struct { -type RegionSslPoliciesClient interface { -type RegionSslPoliciesServer interface { -type UnimplementedRegionSslPoliciesServer struct { -type RegionTargetHttpProxiesClient interface { -type RegionTargetHttpProxiesServer interface { -type UnimplementedRegionTargetHttpProxiesServer struct { -type RegionTargetHttpsProxiesClient interface { -type RegionTargetHttpsProxiesServer interface { -type UnimplementedRegionTargetHttpsProxiesServer struct { -type RegionTargetTcpProxiesClient interface { -type RegionTargetTcpProxiesServer interface { -type UnimplementedRegionTargetTcpProxiesServer struct { -type RegionUrlMapsClient interface { -type RegionUrlMapsServer interface { -type UnimplementedRegionUrlMapsServer struct { -type RegionZonesClient interface { -type RegionZonesServer interface { -type UnimplementedRegionZonesServer struct { -type RegionsClient interface { -type RegionsServer interface { -type UnimplementedRegionsServer struct { -type ReservationsClient interface { -type ReservationsServer interface { -type UnimplementedReservationsServer struct { -type ResourcePoliciesClient interface { -type ResourcePoliciesServer interface { -type UnimplementedResourcePoliciesServer struct { -type RoutersClient interface { -type RoutersServer interface { -type UnimplementedRoutersServer struct { -type RoutesClient interface { -type RoutesServer interface { -type UnimplementedRoutesServer struct { -type SecurityPoliciesClient interface { -type SecurityPoliciesServer interface { -type UnimplementedSecurityPoliciesServer struct { -type ServiceAttachmentsClient interface { -type ServiceAttachmentsServer interface { -type UnimplementedServiceAttachmentsServer struct { -type SnapshotSettingsServiceClient interface { -type SnapshotSettingsServiceServer interface { -type UnimplementedSnapshotSettingsServiceServer struct { -type SnapshotsClient interface { -type SnapshotsServer interface { -type UnimplementedSnapshotsServer struct { -type SslCertificatesClient interface { -type SslCertificatesServer interface { -type UnimplementedSslCertificatesServer struct { -type SslPoliciesClient interface { -type SslPoliciesServer interface { -type UnimplementedSslPoliciesServer struct { -type StoragePoolTypesClient interface { -type StoragePoolTypesServer interface { -type UnimplementedStoragePoolTypesServer struct { -type StoragePoolsClient interface { -type StoragePoolsServer interface { -type UnimplementedStoragePoolsServer struct { -type SubnetworksClient interface { -type SubnetworksServer interface { -type UnimplementedSubnetworksServer struct { -type TargetGrpcProxiesClient interface { -type TargetGrpcProxiesServer interface { -type UnimplementedTargetGrpcProxiesServer struct { -type TargetHttpProxiesClient interface { -type TargetHttpProxiesServer interface { -type UnimplementedTargetHttpProxiesServer struct { -type TargetHttpsProxiesClient interface { -type TargetHttpsProxiesServer interface { -type UnimplementedTargetHttpsProxiesServer struct { -type TargetInstancesClient interface { -type TargetInstancesServer interface { -type UnimplementedTargetInstancesServer struct { -type TargetPoolsClient interface { -type TargetPoolsServer interface { -type UnimplementedTargetPoolsServer struct { -type TargetSslProxiesClient interface { -type TargetSslProxiesServer interface { -type UnimplementedTargetSslProxiesServer struct { -type TargetTcpProxiesClient interface { -type TargetTcpProxiesServer interface { -type UnimplementedTargetTcpProxiesServer struct { -type TargetVpnGatewaysClient interface { -type TargetVpnGatewaysServer interface { -type UnimplementedTargetVpnGatewaysServer struct { -type UrlMapsClient interface { -type UrlMapsServer interface { -type UnimplementedUrlMapsServer struct { -type VpnGatewaysClient interface { -type VpnGatewaysServer interface { -type UnimplementedVpnGatewaysServer struct { -type VpnTunnelsClient interface { -type VpnTunnelsServer interface { -type UnimplementedVpnTunnelsServer struct { -type ZoneOperationsClient interface { -type ZoneOperationsServer interface { -type UnimplementedZoneOperationsServer struct { -type ZonesClient interface { -type ZonesServer interface { -type UnimplementedZonesServer struct { ```
codyoss commented 5 days ago

This was an intentional change as those generated bindings were published by mistake. compute is not a gRPC based service and should never have generated those types. How/why were you referencing this type?

krousey commented 5 days ago

We are using this in test harnesses. The service definitions in the proto source contain google.api.* annotations that can be used (by projects like gRPC-Gateway and https://cloud.google.com/endpoints/docs/grpc/transcoding) to automatically map REST requests to a gRPC service. We use https://github.com/emcfarlane/larking to do this in our test harness. We spin up a gRPC implementation of one of these services, register it with larking, and it uses proto-reflection to extract all the rest mappings for us. It saves us a TON of time in not having to hand-craft REST fakes/mappings for each API call. And best of all, it's nearly identical to how we test gRPC fakes.

I'm open to other suggestions for in-memory testing that let's us use REAL clients against fake backends (edit) without handwriting a bunch of REST mappings myself.

example annotation from the Networks gRPC service:

  // Returns the specified network.
  rpc Get(GetNetworkRequest) returns (Network) {
    option (google.api.http) = {
      get: "/compute/v1/projects/{project}/global/networks/{network}"
    };
    option (google.api.method_signature) = "project,network";
  }
codyoss commented 5 days ago

It looks like we need to update our testing.md in this repo for a good example of that, but the same strategy that is outlined in our older client libs should work here as well for compute: https://github.com/googleapis/google-api-go-client/blob/main/testing.md#testing-http-services-using-fakes

krousey commented 5 days ago

Yes, that's the avenue of hand-crafting REST fakes. It is tedious and repetitive to get right, especially when all the mappings are already defined in the proto service. The example fake in the documentation has a single handler that does no input interpolation for proper faking. A more serious example for say the Networks service defined in the compute proto would have to define a mux that properly handles the following REST endpoints and pulls appropriate parameters out of the paths:

That's a lot of unnecessary work to hand-write especially when the mappings are already in the service definition. And then there's 97 more services just like this in this one proto. Before this change, the gRPC interfaces were helping bridge this usability gap. Is there any downside to generating them?

codyoss commented 5 days ago

Is there any downside to generating them?

The main reasons we made these changes:

I am not familiar with the project you listed about to suggest a better workaround.

We had considered this may be referenced in test code, but did not fully consider transcoding style use cases you have mentioned in this issue.