Skip to content

Commit

Permalink
Merge branch 'main' into trace-otel-default
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzmo authored May 31, 2024
2 parents 81a9472 + 4832e10 commit 7875926
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 3 deletions.
2 changes: 0 additions & 2 deletions ai/generativelanguage/apiv1beta/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package generativelanguage

//go:generate ./gen_info.sh info.go

func (c *DiscussClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}
Expand Down
136 changes: 136 additions & 0 deletions aiplatform/apiv1beta1/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,142 @@

package aiplatform

func (c *DatasetClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *DeploymentResourcePoolClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *EndpointClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *EvaluationClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ExtensionExecutionClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ExtensionRegistryClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *FeatureOnlineStoreAdminClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *FeatureOnlineStoreClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *FeatureRegistryClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *FeaturestoreClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *FeaturestoreOnlineServingClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *GenAiCacheClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *GenAiTuningClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *IndexClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *IndexEndpointClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *JobClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *LlmUtilityClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *MatchClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *MetadataClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *MigrationClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ModelClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ModelGardenClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ModelMonitoringClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *NotebookClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *PersistentResourceClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *PipelineClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *PredictionClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ReasoningEngineClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ReasoningEngineExecutionClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *ScheduleClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *SpecialistPoolClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *TensorboardClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *VertexRagClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *VertexRagDataClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}

func (c *VizierClient) SetGoogleClientInfo(keyval ...string) {
c.setGoogleClientInfo(keyval...)
}
46 changes: 46 additions & 0 deletions internal/gen_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

# Script to generate info.go files with methods for all clients.

if [[ $# != 2 ]]; then
echo >&2 "usage: $0 DIR PACKAGE"
exit 1
fi

outfile=info.go

cd $1

cat <<'EOF' > $outfile
// Copyright 2023 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
//
// http://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.
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Also passes any
// provided key-value pairs. Intended for use by Google-written clients.
//
// Internal use only.
EOF

echo -e >> $outfile "package $2\n"


awk '/^func \(c \*[A-Z].*\) setGoogleClientInfo/ {
printf("func (c %s SetGoogleClientInfo(keyval ...string) {\n", $3);
printf(" c.setGoogleClientInfo(keyval...)\n");
printf("}\n\n");
}' *_client.go >> $outfile

gofmt -w $outfile
12 changes: 11 additions & 1 deletion internal/protoveneer/cmd/protoveneer/protoveneer.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func buildConverterMap(typeInfos []*typeInfo, conf *config) (map[string]converte

// Add converters for used external types to the map.
for _, et := range externalTypes {
if et.used {
if et.used && et.convertTo != "" {
converters[et.qualifiedName] = customConverter{et.convertTo, et.convertFrom}
}
}
Expand Down Expand Up @@ -849,13 +849,23 @@ var externalTypes = []*externalType{
convertTo: "timestamppb.New",
convertFrom: "support.TimeFromProto",
},
{
qualifiedName: "*apierror.APIError",
replaces: "*status.Status",
importPaths: []string{"github.com/googleapis/gax-go/v2/apierror"},
convertTo: "support.APIErrorToProto",
convertFrom: "support.APIErrorFromProto",
},
}

var protoTypeToExternalType = map[string]*externalType{}

func init() {
var err error
for _, et := range externalTypes {
if et.replaces == "" {
continue
}
et.typeExpr, err = parser.ParseExpr(et.qualifiedName)
if err != nil {
panic(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package basic

import (
_ "google.golang.org/genproto/googleapis/api/annotations"
status "google.golang.org/genproto/googleapis/rpc/status"
date "google.golang.org/genproto/googleapis/type/date"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -133,3 +134,9 @@ type Pop struct {
X int
Y unexported
}

// Status converts to itself.

type File struct {
Error *status.Status
}
23 changes: 23 additions & 0 deletions internal/protoveneer/cmd/protoveneer/testdata/basic/golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"cloud.google.com/go/civil"
pb "example.com/basic"
"example.com/protoveneer/support"
"github.com/googleapis/gax-go/v2/apierror"
"google.golang.org/protobuf/types/known/timestamppb"
"time"
)
Expand Down Expand Up @@ -103,6 +104,28 @@ func (CitationMetadata) fromProto(p *pb.CitationMetadata) *CitationMetadata {
}
}

type File struct {
Error *apierror.APIError
}

func (v *File) toProto() *pb.File {
if v == nil {
return nil
}
return &pb.File{
Error: support.APIErrorToProto(v.Error),
}
}

func (File) fromProto(p *pb.File) *File {
if p == nil {
return nil
}
return &File{
Error: support.APIErrorFromProto(p.Error),
}
}

// FinishReason is the reason why the model stopped generating tokens.
// If empty, the model has not stopped generating the tokens.
type FinishReason int32
Expand Down
5 changes: 5 additions & 0 deletions internal/protoveneer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ go 1.20
require (
cloud.google.com/go v0.114.0
github.com/google/go-cmp v0.6.0
github.com/googleapis/gax-go/v2 v2.12.4
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/kr/pretty v0.3.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/sys v0.20.0 // indirect
google.golang.org/api v0.180.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
12 changes: 12 additions & 0 deletions internal/protoveneer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cloud.google.com/go v0.114.0/go.mod h1:ZV9La5YYxctro1HTPug5lXH/GefROyW8PPD4T8n9J
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/googleapis/gax-go/v2 v2.12.4 h1:9gWcmF85Wvq4ryPFvGFaOgPIs1AQX0d0bcbGw4Z96qg=
github.com/googleapis/gax-go/v2 v2.12.4/go.mod h1:KYEYLorsnIGDi/rPC8b5TdlB9kbKoFubselGIoBMCwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand All @@ -14,8 +16,18 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
google.golang.org/api v0.180.0 h1:M2D87Yo0rGBPWpo1orwfCLehUUL6E7/TYe5gvMQWDh4=
google.golang.org/api v0.180.0/go.mod h1:51AiyoEg1MJPSZ9zvklA8VnRILPXxn1iVen9v25XHAE=
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda h1:wu/KJm9KJwpfHWhkkZGohVC6KRrc1oJNr4jwtQMOQXw=
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda/go.mod h1:g2LLCvCeCSir/JJSWosk19BR4NVxGqHUC6rxIRsd7Aw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
22 changes: 22 additions & 0 deletions internal/protoveneer/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"time"

"cloud.google.com/go/civil"
"github.com/googleapis/gax-go/v2/apierror"
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/genproto/googleapis/type/date"
gstatus "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down Expand Up @@ -119,3 +122,22 @@ func TimeFromProto(ts *timestamppb.Timestamp) time.Time {
}
return ts.AsTime()
}

// APIErrorToProto converts an APIError to a proto Status.
func APIErrorToProto(ae *apierror.APIError) *spb.Status {
if ae == nil {
return nil
}
return ae.GRPCStatus().Proto()
}

// APIErrorFromProto converts a proto Status to an APIError.
func APIErrorFromProto(s *spb.Status) *apierror.APIError {
err := gstatus.ErrorProto(s)
aerr, ok := apierror.ParseError(err, true)
if !ok {
// Should be impossible.
return nil
}
return aerr
}
Loading

0 comments on commit 7875926

Please sign in to comment.