Update dependencies

Among others, this updates minio-go, so that the new "eu-west-3" zone
for AWS is supported.
This commit is contained in:
Alexander Neumann
2018-01-23 19:40:42 +01:00
parent b63de7c798
commit 2b39f9f4b2
3435 changed files with 1317989 additions and 315639 deletions
+4 -2
View File
@@ -1,10 +1,10 @@
// Copyright 2017, Google Inc. All rights reserved.
// Copyright 2018 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
// 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,
@@ -21,6 +21,7 @@ import (
)
import (
"fmt"
"strconv"
"testing"
"time"
@@ -31,6 +32,7 @@ import (
"google.golang.org/api/option"
)
var _ = fmt.Sprintf
var _ = iterator.Done
var _ = strconv.FormatUint
var _ = time.Now
+10 -8
View File
@@ -1,10 +1,10 @@
// Copyright 2017, Google Inc. All rights reserved.
// Copyright 2018 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
// 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,
@@ -17,13 +17,15 @@
// Package trace is an auto-generated package for the
// Stackdriver Trace API.
//
// NOTE: This package is in alpha. It is not stable, and is likely to be subject to changes.
// NOTE: This package is in alpha. It is not stable, and is likely to change.
//
// Send and retrieve trace data from Stackdriver Trace. Data is generated and
// available by default for all App Engine applications. Data from other
// applications can be written to Stackdriver Trace for display, reporting,
// and
// analysis.
// Sends application trace data to Stackdriver Trace for viewing. Trace data
// is
// collected for all App Engine applications by default. Trace data from
// other
// applications can be provided using this API.
//
// Use the client at cloud.google.com/go/trace in preference to this.
package trace // import "cloud.google.com/go/trace/apiv1"
import (
+123 -123
View File
@@ -1,10 +1,10 @@
// Copyright 2017, Google Inc. All rights reserved.
// Copyright 2018 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
// 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,
@@ -126,6 +126,127 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func TestTraceServicePatchTraces(t *testing.T) {
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
mockTrace.err = nil
mockTrace.reqs = nil
mockTrace.resps = append(mockTrace.resps[:0], expectedResponse)
var projectId string = "projectId-1969970175"
var traces *cloudtracepb.Traces = &cloudtracepb.Traces{}
var request = &cloudtracepb.PatchTracesRequest{
ProjectId: projectId,
Traces: traces,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.PatchTraces(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockTrace.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
}
func TestTraceServicePatchTracesError(t *testing.T) {
errCode := codes.PermissionDenied
mockTrace.err = gstatus.Error(errCode, "test error")
var projectId string = "projectId-1969970175"
var traces *cloudtracepb.Traces = &cloudtracepb.Traces{}
var request = &cloudtracepb.PatchTracesRequest{
ProjectId: projectId,
Traces: traces,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.PatchTraces(context.Background(), request)
if st, ok := gstatus.FromError(err); !ok {
t.Errorf("got error %v, expected grpc error", err)
} else if c := st.Code(); c != errCode {
t.Errorf("got error code %q, want %q", c, errCode)
}
}
func TestTraceServiceGetTrace(t *testing.T) {
var projectId2 string = "projectId2939242356"
var traceId2 string = "traceId2987826376"
var expectedResponse = &cloudtracepb.Trace{
ProjectId: projectId2,
TraceId: traceId2,
}
mockTrace.err = nil
mockTrace.reqs = nil
mockTrace.resps = append(mockTrace.resps[:0], expectedResponse)
var projectId string = "projectId-1969970175"
var traceId string = "traceId1270300245"
var request = &cloudtracepb.GetTraceRequest{
ProjectId: projectId,
TraceId: traceId,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetTrace(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockTrace.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestTraceServiceGetTraceError(t *testing.T) {
errCode := codes.PermissionDenied
mockTrace.err = gstatus.Error(errCode, "test error")
var projectId string = "projectId-1969970175"
var traceId string = "traceId1270300245"
var request = &cloudtracepb.GetTraceRequest{
ProjectId: projectId,
TraceId: traceId,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetTrace(context.Background(), request)
if st, ok := gstatus.FromError(err); !ok {
t.Errorf("got error %v, expected grpc error", err)
} else if c := st.Code(); c != errCode {
t.Errorf("got error code %q, want %q", c, errCode)
}
_ = resp
}
func TestTraceServiceListTraces(t *testing.T) {
var nextPageToken string = ""
var tracesElement *cloudtracepb.Trace = &cloudtracepb.Trace{}
@@ -198,124 +319,3 @@ func TestTraceServiceListTracesError(t *testing.T) {
}
_ = resp
}
func TestTraceServiceGetTrace(t *testing.T) {
var projectId2 string = "projectId2939242356"
var traceId2 string = "traceId2987826376"
var expectedResponse = &cloudtracepb.Trace{
ProjectId: projectId2,
TraceId: traceId2,
}
mockTrace.err = nil
mockTrace.reqs = nil
mockTrace.resps = append(mockTrace.resps[:0], expectedResponse)
var projectId string = "projectId-1969970175"
var traceId string = "traceId1270300245"
var request = &cloudtracepb.GetTraceRequest{
ProjectId: projectId,
TraceId: traceId,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetTrace(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockTrace.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestTraceServiceGetTraceError(t *testing.T) {
errCode := codes.PermissionDenied
mockTrace.err = gstatus.Error(errCode, "test error")
var projectId string = "projectId-1969970175"
var traceId string = "traceId1270300245"
var request = &cloudtracepb.GetTraceRequest{
ProjectId: projectId,
TraceId: traceId,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetTrace(context.Background(), request)
if st, ok := gstatus.FromError(err); !ok {
t.Errorf("got error %v, expected grpc error", err)
} else if c := st.Code(); c != errCode {
t.Errorf("got error code %q, want %q", c, errCode)
}
_ = resp
}
func TestTraceServicePatchTraces(t *testing.T) {
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
mockTrace.err = nil
mockTrace.reqs = nil
mockTrace.resps = append(mockTrace.resps[:0], expectedResponse)
var projectId string = "projectId-1969970175"
var traces *cloudtracepb.Traces = &cloudtracepb.Traces{}
var request = &cloudtracepb.PatchTracesRequest{
ProjectId: projectId,
Traces: traces,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.PatchTraces(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockTrace.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
}
func TestTraceServicePatchTracesError(t *testing.T) {
errCode := codes.PermissionDenied
mockTrace.err = gstatus.Error(errCode, "test error")
var projectId string = "projectId-1969970175"
var traces *cloudtracepb.Traces = &cloudtracepb.Traces{}
var request = &cloudtracepb.PatchTracesRequest{
ProjectId: projectId,
Traces: traces,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.PatchTraces(context.Background(), request)
if st, ok := gstatus.FromError(err); !ok {
t.Errorf("got error %v, expected grpc error", err)
} else if c := st.Code(); c != errCode {
t.Errorf("got error code %q, want %q", c, errCode)
}
}
+45 -45
View File
@@ -1,10 +1,10 @@
// Copyright 2017, Google Inc. All rights reserved.
// Copyright 2018 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
// 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,
@@ -34,9 +34,9 @@ import (
// CallOptions contains the retry settings for each method of Client.
type CallOptions struct {
ListTraces []gax.CallOption
GetTrace []gax.CallOption
PatchTraces []gax.CallOption
GetTrace []gax.CallOption
ListTraces []gax.CallOption
}
func defaultClientOptions() []option.ClientOption {
@@ -62,9 +62,9 @@ func defaultCallOptions() *CallOptions {
},
}
return &CallOptions{
ListTraces: retry[[2]string{"default", "idempotent"}],
PatchTraces: retry[[2]string{"default", "idempotent"}],
GetTrace: retry[[2]string{"default", "idempotent"}],
PatchTraces: retry[[2]string{"write_sink", "non_idempotent"}],
ListTraces: retry[[2]string{"default", "idempotent"}],
}
}
@@ -79,8 +79,8 @@ type Client struct {
// The call options for this service.
CallOptions *CallOptions
// The metadata to be sent with each request.
Metadata metadata.MD
// The x-goog-* metadata to be sent with each request.
xGoogMetadata metadata.MD
}
// NewClient creates a new trace service client.
@@ -101,7 +101,7 @@ func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error
client: cloudtracepb.NewTraceServiceClient(conn),
}
c.setGoogleClientInfo()
c.SetGoogleClientInfo()
return c, nil
}
@@ -116,18 +116,50 @@ func (c *Client) Close() error {
return c.conn.Close()
}
// setGoogleClientInfo sets the name and version of the application in
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *Client) setGoogleClientInfo(keyval ...string) {
func (c *Client) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
c.Metadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
}
// PatchTraces sends new traces to Stackdriver Trace or updates existing traces. If the ID
// of a trace that you send matches that of an existing trace, any fields
// in the existing trace and its spans are overwritten by the provided values,
// and any new fields provided are merged with the existing trace data. If the
// ID does not match, a new trace is created.
func (c *Client) PatchTraces(ctx context.Context, req *cloudtracepb.PatchTracesRequest, opts ...gax.CallOption) error {
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append(c.CallOptions.PatchTraces[0:len(c.CallOptions.PatchTraces):len(c.CallOptions.PatchTraces)], opts...)
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
_, err = c.client.PatchTraces(ctx, req, settings.GRPC...)
return err
}, opts...)
return err
}
// GetTrace gets a single trace by its ID.
func (c *Client) GetTrace(ctx context.Context, req *cloudtracepb.GetTraceRequest, opts ...gax.CallOption) (*cloudtracepb.Trace, error) {
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append(c.CallOptions.GetTrace[0:len(c.CallOptions.GetTrace):len(c.CallOptions.GetTrace)], opts...)
var resp *cloudtracepb.Trace
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.GetTrace(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// ListTraces returns of a list of traces that match the specified filter conditions.
func (c *Client) ListTraces(ctx context.Context, req *cloudtracepb.ListTracesRequest, opts ...gax.CallOption) *TraceIterator {
ctx = insertMetadata(ctx, c.Metadata)
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append(c.CallOptions.ListTraces[0:len(c.CallOptions.ListTraces):len(c.CallOptions.ListTraces)], opts...)
it := &TraceIterator{}
it.InternalFetch = func(pageSize int, pageToken string) ([]*cloudtracepb.Trace, string, error) {
@@ -160,38 +192,6 @@ func (c *Client) ListTraces(ctx context.Context, req *cloudtracepb.ListTracesReq
return it
}
// GetTrace gets a single trace by its ID.
func (c *Client) GetTrace(ctx context.Context, req *cloudtracepb.GetTraceRequest, opts ...gax.CallOption) (*cloudtracepb.Trace, error) {
ctx = insertMetadata(ctx, c.Metadata)
opts = append(c.CallOptions.GetTrace[0:len(c.CallOptions.GetTrace):len(c.CallOptions.GetTrace)], opts...)
var resp *cloudtracepb.Trace
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.GetTrace(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// PatchTraces sends new traces to Stackdriver Trace or updates existing traces. If the ID
// of a trace that you send matches that of an existing trace, any fields
// in the existing trace and its spans are overwritten by the provided values,
// and any new fields provided are merged with the existing trace data. If the
// ID does not match, a new trace is created.
func (c *Client) PatchTraces(ctx context.Context, req *cloudtracepb.PatchTracesRequest, opts ...gax.CallOption) error {
ctx = insertMetadata(ctx, c.Metadata)
opts = append(c.CallOptions.PatchTraces[0:len(c.CallOptions.PatchTraces):len(c.CallOptions.PatchTraces)], opts...)
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
_, err = c.client.PatchTraces(ctx, req, settings.GRPC...)
return err
}, opts...)
return err
}
// TraceIterator manages a stream of *cloudtracepb.Trace.
type TraceIterator struct {
items []*cloudtracepb.Trace
+37 -37
View File
@@ -1,10 +1,10 @@
// Copyright 2017, Google Inc. All rights reserved.
// Copyright 2018 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
// 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,
@@ -33,6 +33,40 @@ func ExampleNewClient() {
_ = c
}
func ExampleClient_PatchTraces() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &cloudtracepb.PatchTracesRequest{
// TODO: Fill request struct fields.
}
err = c.PatchTraces(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func ExampleClient_GetTrace() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &cloudtracepb.GetTraceRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetTrace(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleClient_ListTraces() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
@@ -41,7 +75,7 @@ func ExampleClient_ListTraces() {
}
req := &cloudtracepb.ListTracesRequest{
// TODO: Fill request struct fields.
// TODO: Fill request struct fields.
}
it := c.ListTraces(ctx, req)
for {
@@ -56,37 +90,3 @@ func ExampleClient_ListTraces() {
_ = resp
}
}
func ExampleClient_GetTrace() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &cloudtracepb.GetTraceRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetTrace(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleClient_PatchTraces() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &cloudtracepb.PatchTracesRequest{
// TODO: Fill request struct fields.
}
err = c.PatchTraces(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
+66
View File
@@ -0,0 +1,66 @@
// Copyright 2018 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.
// AUTO-GENERATED CODE. DO NOT EDIT.
package trace
import (
cloudtracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
)
import (
"fmt"
"strconv"
"testing"
"time"
"cloud.google.com/go/internal/testutil"
"golang.org/x/net/context"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
var _ = fmt.Sprintf
var _ = iterator.Done
var _ = strconv.FormatUint
var _ = time.Now
func TestTraceServiceSmoke(t *testing.T) {
if testing.Short() {
t.Skip("skipping smoke test in short mode")
}
ctx := context.Background()
ts := testutil.TokenSource(ctx, DefaultAuthScopes()...)
if ts == nil {
t.Skip("Integration tests skipped. See CONTRIBUTING.md for details")
}
projectId := testutil.ProjID()
_ = projectId
c, err := NewClient(ctx, option.WithTokenSource(ts))
if err != nil {
t.Fatal(err)
}
var formattedName string = fmt.Sprintf("projects/%s", projectId)
var request = &cloudtracepb.BatchWriteSpansRequest{
Name: formattedName,
}
if err := c.BatchWriteSpans(ctx, request); err != nil {
t.Error(err)
}
}
+51
View File
@@ -0,0 +1,51 @@
// Copyright 2018 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.
// AUTO-GENERATED CODE. DO NOT EDIT.
// Package trace is an auto-generated package for the
// Stackdriver Trace API.
//
// NOTE: This package is in alpha. It is not stable, and is likely to change.
//
// Sends application trace data to Stackdriver Trace for viewing. Trace data
// is
// collected for all App Engine applications by default. Trace data from
// other
// applications can be provided using this API.
package trace // import "cloud.google.com/go/trace/apiv2"
import (
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
)
func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
out = out.Copy()
for _, md := range mds {
for k, v := range md {
out[k] = append(out[k], v...)
}
}
return metadata.NewOutgoingContext(ctx, out)
}
// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
func DefaultAuthScopes() []string {
return []string{
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/trace.append",
}
}
+252
View File
@@ -0,0 +1,252 @@
// Copyright 2018 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.
// AUTO-GENERATED CODE. DO NOT EDIT.
package trace
import (
emptypb "github.com/golang/protobuf/ptypes/empty"
timestamppb "github.com/golang/protobuf/ptypes/timestamp"
cloudtracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
)
import (
"flag"
"fmt"
"io"
"log"
"net"
"os"
"strings"
"testing"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"golang.org/x/net/context"
"google.golang.org/api/option"
status "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
gstatus "google.golang.org/grpc/status"
)
var _ = io.EOF
var _ = ptypes.MarshalAny
var _ status.Status
type mockTraceServer struct {
// Embed for forward compatibility.
// Tests will keep working if more methods are added
// in the future.
cloudtracepb.TraceServiceServer
reqs []proto.Message
// If set, all calls return this error.
err error
// responses to return if err == nil
resps []proto.Message
}
func (s *mockTraceServer) BatchWriteSpans(ctx context.Context, req *cloudtracepb.BatchWriteSpansRequest) (*emptypb.Empty, error) {
md, _ := metadata.FromIncomingContext(ctx)
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
}
s.reqs = append(s.reqs, req)
if s.err != nil {
return nil, s.err
}
return s.resps[0].(*emptypb.Empty), nil
}
func (s *mockTraceServer) CreateSpan(ctx context.Context, req *cloudtracepb.Span) (*cloudtracepb.Span, error) {
md, _ := metadata.FromIncomingContext(ctx)
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
}
s.reqs = append(s.reqs, req)
if s.err != nil {
return nil, s.err
}
return s.resps[0].(*cloudtracepb.Span), nil
}
// clientOpt is the option tests should use to connect to the test server.
// It is initialized by TestMain.
var clientOpt option.ClientOption
var (
mockTrace mockTraceServer
)
func TestMain(m *testing.M) {
flag.Parse()
serv := grpc.NewServer()
cloudtracepb.RegisterTraceServiceServer(serv, &mockTrace)
lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
log.Fatal(err)
}
go serv.Serve(lis)
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
clientOpt = option.WithGRPCConn(conn)
os.Exit(m.Run())
}
func TestTraceServiceBatchWriteSpans(t *testing.T) {
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
mockTrace.err = nil
mockTrace.reqs = nil
mockTrace.resps = append(mockTrace.resps[:0], expectedResponse)
var formattedName string = fmt.Sprintf("projects/%s", "[PROJECT]")
var spans []*cloudtracepb.Span = nil
var request = &cloudtracepb.BatchWriteSpansRequest{
Name: formattedName,
Spans: spans,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.BatchWriteSpans(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockTrace.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
}
func TestTraceServiceBatchWriteSpansError(t *testing.T) {
errCode := codes.PermissionDenied
mockTrace.err = gstatus.Error(errCode, "test error")
var formattedName string = fmt.Sprintf("projects/%s", "[PROJECT]")
var spans []*cloudtracepb.Span = nil
var request = &cloudtracepb.BatchWriteSpansRequest{
Name: formattedName,
Spans: spans,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.BatchWriteSpans(context.Background(), request)
if st, ok := gstatus.FromError(err); !ok {
t.Errorf("got error %v, expected grpc error", err)
} else if c := st.Code(); c != errCode {
t.Errorf("got error code %q, want %q", c, errCode)
}
}
func TestTraceServiceCreateSpan(t *testing.T) {
var name2 string = "name2-1052831874"
var spanId2 string = "spanId2-643891741"
var parentSpanId string = "parentSpanId-1757797477"
var expectedResponse = &cloudtracepb.Span{
Name: name2,
SpanId: spanId2,
ParentSpanId: parentSpanId,
}
mockTrace.err = nil
mockTrace.reqs = nil
mockTrace.resps = append(mockTrace.resps[:0], expectedResponse)
var formattedName string = fmt.Sprintf("projects/%s/traces/%s/spans/%s", "[PROJECT]", "[TRACE]", "[SPAN]")
var spanId string = "spanId-2011840976"
var displayName *cloudtracepb.TruncatableString = &cloudtracepb.TruncatableString{}
var startTime *timestamppb.Timestamp = &timestamppb.Timestamp{}
var endTime *timestamppb.Timestamp = &timestamppb.Timestamp{}
var request = &cloudtracepb.Span{
Name: formattedName,
SpanId: spanId,
DisplayName: displayName,
StartTime: startTime,
EndTime: endTime,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.CreateSpan(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockTrace.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestTraceServiceCreateSpanError(t *testing.T) {
errCode := codes.PermissionDenied
mockTrace.err = gstatus.Error(errCode, "test error")
var formattedName string = fmt.Sprintf("projects/%s/traces/%s/spans/%s", "[PROJECT]", "[TRACE]", "[SPAN]")
var spanId string = "spanId-2011840976"
var displayName *cloudtracepb.TruncatableString = &cloudtracepb.TruncatableString{}
var startTime *timestamppb.Timestamp = &timestamppb.Timestamp{}
var endTime *timestamppb.Timestamp = &timestamppb.Timestamp{}
var request = &cloudtracepb.Span{
Name: formattedName,
SpanId: spanId,
DisplayName: displayName,
StartTime: startTime,
EndTime: endTime,
}
c, err := NewClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.CreateSpan(context.Background(), request)
if st, ok := gstatus.FromError(err); !ok {
t.Errorf("got error %v, expected grpc error", err)
} else if c := st.Code(); c != errCode {
t.Errorf("got error code %q, want %q", c, errCode)
}
_ = resp
}
+43
View File
@@ -0,0 +1,43 @@
// Copyright 2018 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 trace
// ProjectPath returns the path for the project resource.
//
// Deprecated: Use
// fmt.Sprintf("projects/%s", project)
// instead.
func ProjectPath(project string) string {
return "" +
"projects/" +
project +
""
}
// SpanPath returns the path for the span resource.
//
// Deprecated: Use
// fmt.Sprintf("projects/%s/traces/%s/spans/%s", project, trace, span)
// instead.
func SpanPath(project, trace, span string) string {
return "" +
"projects/" +
project +
"/traces/" +
trace +
"/spans/" +
span +
""
}
+151
View File
@@ -0,0 +1,151 @@
// Copyright 2018 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.
// AUTO-GENERATED CODE. DO NOT EDIT.
package trace
import (
"time"
"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
"google.golang.org/api/option"
"google.golang.org/api/transport"
cloudtracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
)
// CallOptions contains the retry settings for each method of Client.
type CallOptions struct {
BatchWriteSpans []gax.CallOption
CreateSpan []gax.CallOption
}
func defaultClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("cloudtrace.googleapis.com:443"),
option.WithScopes(DefaultAuthScopes()...),
}
}
func defaultCallOptions() *CallOptions {
retry := map[[2]string][]gax.CallOption{
{"default", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 1000 * time.Millisecond,
Multiplier: 1.2,
})
}),
},
}
return &CallOptions{
BatchWriteSpans: retry[[2]string{"default", "non_idempotent"}],
CreateSpan: retry[[2]string{"default", "idempotent"}],
}
}
// Client is a client for interacting with Stackdriver Trace API.
type Client struct {
// The connection to the service.
conn *grpc.ClientConn
// The gRPC API client.
client cloudtracepb.TraceServiceClient
// The call options for this service.
CallOptions *CallOptions
// The x-goog-* metadata to be sent with each request.
xGoogMetadata metadata.MD
}
// NewClient creates a new trace service client.
//
// This file describes an API for collecting and viewing traces and spans
// within a trace. A Trace is a collection of spans corresponding to a single
// operation or set of operations for an application. A span is an individual
// timed event which forms a node of the trace tree. A single trace may
// contain span(s) from multiple services.
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
conn, err := transport.DialGRPC(ctx, append(defaultClientOptions(), opts...)...)
if err != nil {
return nil, err
}
c := &Client{
conn: conn,
CallOptions: defaultCallOptions(),
client: cloudtracepb.NewTraceServiceClient(conn),
}
c.setGoogleClientInfo()
return c, nil
}
// Connection returns the client's connection to the API service.
func (c *Client) Connection() *grpc.ClientConn {
return c.conn
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *Client) Close() error {
return c.conn.Close()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *Client) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
}
// BatchWriteSpans sends new spans to new or existing traces. You cannot update
// existing spans.
func (c *Client) BatchWriteSpans(ctx context.Context, req *cloudtracepb.BatchWriteSpansRequest, opts ...gax.CallOption) error {
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append(c.CallOptions.BatchWriteSpans[0:len(c.CallOptions.BatchWriteSpans):len(c.CallOptions.BatchWriteSpans)], opts...)
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
_, err = c.client.BatchWriteSpans(ctx, req, settings.GRPC...)
return err
}, opts...)
return err
}
// CreateSpan creates a new span.
func (c *Client) CreateSpan(ctx context.Context, req *cloudtracepb.Span, opts ...gax.CallOption) (*cloudtracepb.Span, error) {
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append(c.CallOptions.CreateSpan[0:len(c.CallOptions.CreateSpan):len(c.CallOptions.CreateSpan)], opts...)
var resp *cloudtracepb.Span
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.CreateSpan(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
+67
View File
@@ -0,0 +1,67 @@
// Copyright 2018 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.
// AUTO-GENERATED CODE. DO NOT EDIT.
package trace_test
import (
"cloud.google.com/go/trace/apiv2"
"golang.org/x/net/context"
cloudtracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
)
func ExampleNewClient() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use client.
_ = c
}
func ExampleClient_BatchWriteSpans() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &cloudtracepb.BatchWriteSpansRequest{
// TODO: Fill request struct fields.
}
err = c.BatchWriteSpans(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func ExampleClient_CreateSpan() {
ctx := context.Background()
c, err := trace.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &cloudtracepb.Span{
// TODO: Fill request struct fields.
}
resp, err := c.CreateSpan(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
+2
View File
@@ -28,6 +28,8 @@ import (
)
func TestGRPCInterceptors(t *testing.T) {
t.Skip("hangs forever for go < 1.9")
tc := newTestClient(&noopTransport{})
// default sampling with global=1.
+40 -15
View File
@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// This package is OBSOLETE. See https://godoc.org/go.opencensus.io/trace.
//
// Package trace is a Google Stackdriver Trace library.
//
// This package is still experimental and subject to change.
//
// See https://cloud.google.com/trace/api/#data_model for a discussion of traces
// and spans.
//
@@ -175,13 +176,31 @@ const (
spanKindServer = `RPC_SERVER`
spanKindUnspecified = `SPAN_KIND_UNSPECIFIED`
maxStackFrames = 20
labelHost = `trace.cloud.google.com/http/host`
labelMethod = `trace.cloud.google.com/http/method`
labelStackTrace = `trace.cloud.google.com/stacktrace`
labelStatusCode = `trace.cloud.google.com/http/status_code`
labelURL = `trace.cloud.google.com/http/url`
labelSamplingPolicy = `trace.cloud.google.com/sampling_policy`
labelSamplingWeight = `trace.cloud.google.com/sampling_weight`
)
// Stackdriver Trace API predefined labels.
const (
LabelAgent = `trace.cloud.google.com/agent`
LabelComponent = `trace.cloud.google.com/component`
LabelErrorMessage = `trace.cloud.google.com/error/message`
LabelErrorName = `trace.cloud.google.com/error/name`
LabelHTTPClientCity = `trace.cloud.google.com/http/client_city`
LabelHTTPClientCountry = `trace.cloud.google.com/http/client_country`
LabelHTTPClientProtocol = `trace.cloud.google.com/http/client_protocol`
LabelHTTPClientRegion = `trace.cloud.google.com/http/client_region`
LabelHTTPHost = `trace.cloud.google.com/http/host`
LabelHTTPMethod = `trace.cloud.google.com/http/method`
LabelHTTPRedirectedURL = `trace.cloud.google.com/http/redirected_url`
LabelHTTPRequestSize = `trace.cloud.google.com/http/request/size`
LabelHTTPResponseSize = `trace.cloud.google.com/http/response/size`
LabelHTTPStatusCode = `trace.cloud.google.com/http/status_code`
LabelHTTPURL = `trace.cloud.google.com/http/url`
LabelHTTPUserAgent = `trace.cloud.google.com/http/user_agent`
LabelPID = `trace.cloud.google.com/pid`
LabelSamplingPolicy = `trace.cloud.google.com/sampling_policy`
LabelSamplingWeight = `trace.cloud.google.com/sampling_weight`
LabelStackTrace = `trace.cloud.google.com/stacktrace`
LabelTID = `trace.cloud.google.com/tid`
)
const (
@@ -428,8 +447,8 @@ func configureSpanFromPolicy(s *Span, p SamplingPolicy, ok bool) {
}
if d.Sample {
// This trace is in the random sample, so set the labels.
s.SetLabel(labelSamplingPolicy, d.Policy)
s.SetLabel(labelSamplingWeight, fmt.Sprint(d.Weight))
s.SetLabel(LabelSamplingPolicy, d.Policy)
s.SetLabel(LabelSamplingWeight, fmt.Sprint(d.Weight))
}
}
@@ -543,11 +562,17 @@ func (t *trace) constructTrace(spans []*Span) *api.Trace {
if t.localOptions&optionStack != 0 {
sp.setStackLabel()
}
sp.SetLabel(labelHost, sp.host)
sp.SetLabel(labelURL, sp.url)
sp.SetLabel(labelMethod, sp.method)
if sp.host != "" {
sp.SetLabel(LabelHTTPHost, sp.host)
}
if sp.url != "" {
sp.SetLabel(LabelHTTPURL, sp.url)
}
if sp.method != "" {
sp.SetLabel(LabelHTTPMethod, sp.method)
}
if sp.statusCode != 0 {
sp.SetLabel(labelStatusCode, strconv.Itoa(sp.statusCode))
sp.SetLabel(LabelHTTPStatusCode, strconv.Itoa(sp.statusCode))
}
apiSpans[i] = &sp.span
}
@@ -813,6 +838,6 @@ func (s *Span) setStackLabel() {
lastSigPanic = fn.Name() == "runtime.sigpanic"
}
if label, err := json.Marshal(stack); err == nil {
s.SetLabel(labelStackTrace, string(label))
s.SetLabel(LabelStackTrace, string(label))
}
}