mirror of
https://github.com/restic/restic.git
synced 2026-08-03 12:42:17 +00:00
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:
+5
-3
@@ -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
|
||||
@@ -54,7 +56,7 @@ func TestLoggingServiceV2Smoke(t *testing.T) {
|
||||
}
|
||||
|
||||
var entries []*loggingpb.LogEntry = nil
|
||||
var formattedLogName string = LogPath(projectId, "test-"+strconv.FormatInt(time.Now().UnixNano(), 10)+"")
|
||||
var formattedLogName string = fmt.Sprintf("projects/%s/logs/%s", projectId, "test-"+strconv.FormatInt(time.Now().UnixNano(), 10)+"")
|
||||
var request = &loggingpb.WriteLogEntriesRequest{
|
||||
Entries: entries,
|
||||
LogName: formattedLogName,
|
||||
|
||||
+17
-47
@@ -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,
|
||||
@@ -94,8 +94,8 @@ type ConfigClient struct {
|
||||
// The call options for this service.
|
||||
CallOptions *ConfigCallOptions
|
||||
|
||||
// The metadata to be sent with each request.
|
||||
Metadata metadata.MD
|
||||
// The x-goog-* metadata to be sent with each request.
|
||||
xGoogMetadata metadata.MD
|
||||
}
|
||||
|
||||
// NewConfigClient creates a new config service v2 client.
|
||||
@@ -134,40 +134,12 @@ func (c *ConfigClient) Close() error {
|
||||
func (c *ConfigClient) 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...))
|
||||
}
|
||||
|
||||
// ConfigProjectPath returns the path for the project resource.
|
||||
func ConfigProjectPath(project string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
""
|
||||
}
|
||||
|
||||
// ConfigSinkPath returns the path for the sink resource.
|
||||
func ConfigSinkPath(project, sink string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/sinks/" +
|
||||
sink +
|
||||
""
|
||||
}
|
||||
|
||||
// ConfigExclusionPath returns the path for the exclusion resource.
|
||||
func ConfigExclusionPath(project, exclusion string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/exclusions/" +
|
||||
exclusion +
|
||||
""
|
||||
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
|
||||
}
|
||||
|
||||
// ListSinks lists sinks.
|
||||
func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest, opts ...gax.CallOption) *LogSinkIterator {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.ListSinks[0:len(c.CallOptions.ListSinks):len(c.CallOptions.ListSinks)], opts...)
|
||||
it := &LogSinkIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogSink, string, error) {
|
||||
@@ -202,7 +174,7 @@ func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRe
|
||||
|
||||
// GetSink gets a sink.
|
||||
func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.GetSink[0:len(c.CallOptions.GetSink):len(c.CallOptions.GetSink)], opts...)
|
||||
var resp *loggingpb.LogSink
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -217,12 +189,11 @@ func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkReques
|
||||
}
|
||||
|
||||
// CreateSink creates a sink that exports specified log entries to a destination. The
|
||||
// export of newly-ingested log entries begins immediately, unless the current
|
||||
// time is outside the sink's start and end times or the sink's
|
||||
// export of newly-ingested log entries begins immediately, unless the sink's
|
||||
// writer_identity is not permitted to write to the destination. A sink can
|
||||
// export log entries only from the resource owning the sink.
|
||||
func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.CreateSink[0:len(c.CallOptions.CreateSink):len(c.CallOptions.CreateSink)], opts...)
|
||||
var resp *loggingpb.LogSink
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -237,12 +208,11 @@ func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSink
|
||||
}
|
||||
|
||||
// UpdateSink updates a sink. This method replaces the following fields in the existing
|
||||
// sink with values from the new sink: destination, filter,
|
||||
// output_version_format, start_time, and end_time.
|
||||
// sink with values from the new sink: destination, and filter.
|
||||
// The updated sink might also have a new writer_identity; see the
|
||||
// unique_writer_identity field.
|
||||
func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.UpdateSink[0:len(c.CallOptions.UpdateSink):len(c.CallOptions.UpdateSink)], opts...)
|
||||
var resp *loggingpb.LogSink
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -259,7 +229,7 @@ func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSink
|
||||
// DeleteSink deletes a sink. If the sink has a unique writer_identity, then that
|
||||
// service account is also deleted.
|
||||
func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.DeleteSink[0:len(c.CallOptions.DeleteSink):len(c.CallOptions.DeleteSink)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
@@ -271,7 +241,7 @@ func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSink
|
||||
|
||||
// ListExclusions lists all the exclusions in a parent resource.
|
||||
func (c *ConfigClient) ListExclusions(ctx context.Context, req *loggingpb.ListExclusionsRequest, opts ...gax.CallOption) *LogExclusionIterator {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.ListExclusions[0:len(c.CallOptions.ListExclusions):len(c.CallOptions.ListExclusions)], opts...)
|
||||
it := &LogExclusionIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogExclusion, string, error) {
|
||||
@@ -306,7 +276,7 @@ func (c *ConfigClient) ListExclusions(ctx context.Context, req *loggingpb.ListEx
|
||||
|
||||
// GetExclusion gets the description of an exclusion.
|
||||
func (c *ConfigClient) GetExclusion(ctx context.Context, req *loggingpb.GetExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.GetExclusion[0:len(c.CallOptions.GetExclusion):len(c.CallOptions.GetExclusion)], opts...)
|
||||
var resp *loggingpb.LogExclusion
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -324,7 +294,7 @@ func (c *ConfigClient) GetExclusion(ctx context.Context, req *loggingpb.GetExclu
|
||||
// Only log entries belonging to that resource can be excluded.
|
||||
// You can have up to 10 exclusions in a resource.
|
||||
func (c *ConfigClient) CreateExclusion(ctx context.Context, req *loggingpb.CreateExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.CreateExclusion[0:len(c.CallOptions.CreateExclusion):len(c.CallOptions.CreateExclusion)], opts...)
|
||||
var resp *loggingpb.LogExclusion
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -340,7 +310,7 @@ func (c *ConfigClient) CreateExclusion(ctx context.Context, req *loggingpb.Creat
|
||||
|
||||
// UpdateExclusion changes one or more properties of an existing exclusion.
|
||||
func (c *ConfigClient) UpdateExclusion(ctx context.Context, req *loggingpb.UpdateExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.UpdateExclusion[0:len(c.CallOptions.UpdateExclusion):len(c.CallOptions.UpdateExclusion)], opts...)
|
||||
var resp *loggingpb.LogExclusion
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -356,7 +326,7 @@ func (c *ConfigClient) UpdateExclusion(ctx context.Context, req *loggingpb.Updat
|
||||
|
||||
// DeleteExclusion deletes an exclusion.
|
||||
func (c *ConfigClient) DeleteExclusion(ctx context.Context, req *loggingpb.DeleteExclusionRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.DeleteExclusion[0:len(c.CallOptions.DeleteExclusion):len(c.CallOptions.DeleteExclusion)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
|
||||
+12
-12
@@ -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,
|
||||
@@ -41,7 +41,7 @@ func ExampleConfigClient_ListSinks() {
|
||||
}
|
||||
|
||||
req := &loggingpb.ListSinksRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
it := c.ListSinks(ctx, req)
|
||||
for {
|
||||
@@ -65,7 +65,7 @@ func ExampleConfigClient_GetSink() {
|
||||
}
|
||||
|
||||
req := &loggingpb.GetSinkRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.GetSink(ctx, req)
|
||||
if err != nil {
|
||||
@@ -83,7 +83,7 @@ func ExampleConfigClient_CreateSink() {
|
||||
}
|
||||
|
||||
req := &loggingpb.CreateSinkRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.CreateSink(ctx, req)
|
||||
if err != nil {
|
||||
@@ -101,7 +101,7 @@ func ExampleConfigClient_UpdateSink() {
|
||||
}
|
||||
|
||||
req := &loggingpb.UpdateSinkRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.UpdateSink(ctx, req)
|
||||
if err != nil {
|
||||
@@ -119,7 +119,7 @@ func ExampleConfigClient_DeleteSink() {
|
||||
}
|
||||
|
||||
req := &loggingpb.DeleteSinkRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
err = c.DeleteSink(ctx, req)
|
||||
if err != nil {
|
||||
@@ -135,7 +135,7 @@ func ExampleConfigClient_ListExclusions() {
|
||||
}
|
||||
|
||||
req := &loggingpb.ListExclusionsRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
it := c.ListExclusions(ctx, req)
|
||||
for {
|
||||
@@ -159,7 +159,7 @@ func ExampleConfigClient_GetExclusion() {
|
||||
}
|
||||
|
||||
req := &loggingpb.GetExclusionRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.GetExclusion(ctx, req)
|
||||
if err != nil {
|
||||
@@ -177,7 +177,7 @@ func ExampleConfigClient_CreateExclusion() {
|
||||
}
|
||||
|
||||
req := &loggingpb.CreateExclusionRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.CreateExclusion(ctx, req)
|
||||
if err != nil {
|
||||
@@ -195,7 +195,7 @@ func ExampleConfigClient_UpdateExclusion() {
|
||||
}
|
||||
|
||||
req := &loggingpb.UpdateExclusionRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.UpdateExclusion(ctx, req)
|
||||
if err != nil {
|
||||
@@ -213,7 +213,7 @@ func ExampleConfigClient_DeleteExclusion() {
|
||||
}
|
||||
|
||||
req := &loggingpb.DeleteExclusionRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
err = c.DeleteExclusion(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
+4
-5
@@ -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,10 +17,9 @@
|
||||
// Package logging is an auto-generated package for the
|
||||
// Stackdriver Logging 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.
|
||||
//
|
||||
// The Stackdriver Logging API lets you write log entries and manage your
|
||||
// logs, log sinks and logs-based metrics.
|
||||
// Writes log entries and manages your Stackdriver Logging configuration.
|
||||
//
|
||||
// Use the client at cloud.google.com/go/logging in preference to this.
|
||||
package logging // import "cloud.google.com/go/logging/apiv2"
|
||||
|
||||
+10
-28
@@ -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,
|
||||
@@ -98,8 +98,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 logging service v2 client.
|
||||
@@ -137,25 +137,7 @@ func (c *Client) Close() error {
|
||||
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...))
|
||||
}
|
||||
|
||||
// ProjectPath returns the path for the project resource.
|
||||
func ProjectPath(project string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
""
|
||||
}
|
||||
|
||||
// LogPath returns the path for the log resource.
|
||||
func LogPath(project, log string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/logs/" +
|
||||
log +
|
||||
""
|
||||
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
|
||||
}
|
||||
|
||||
// DeleteLog deletes all the log entries in a log.
|
||||
@@ -163,7 +145,7 @@ func LogPath(project, log string) string {
|
||||
// Log entries written shortly before the delete operation might not be
|
||||
// deleted.
|
||||
func (c *Client) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.DeleteLog[0:len(c.CallOptions.DeleteLog):len(c.CallOptions.DeleteLog)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
@@ -181,7 +163,7 @@ func (c *Client) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest,
|
||||
// (fluentd) and all logging libraries configured to use Stackdriver
|
||||
// Logging.
|
||||
func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest, opts ...gax.CallOption) (*loggingpb.WriteLogEntriesResponse, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.WriteLogEntries[0:len(c.CallOptions.WriteLogEntries):len(c.CallOptions.WriteLogEntries)], opts...)
|
||||
var resp *loggingpb.WriteLogEntriesResponse
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -199,7 +181,7 @@ func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEnt
|
||||
// Stackdriver Logging. For ways to export log entries, see
|
||||
// Exporting Logs (at /logging/docs/export).
|
||||
func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest, opts ...gax.CallOption) *LogEntryIterator {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.ListLogEntries[0:len(c.CallOptions.ListLogEntries):len(c.CallOptions.ListLogEntries)], opts...)
|
||||
it := &LogEntryIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogEntry, string, error) {
|
||||
@@ -235,7 +217,7 @@ func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntri
|
||||
// ListMonitoredResourceDescriptors lists the descriptors for monitored resource types used by Stackdriver
|
||||
// Logging.
|
||||
func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest, opts ...gax.CallOption) *MonitoredResourceDescriptorIterator {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.ListMonitoredResourceDescriptors[0:len(c.CallOptions.ListMonitoredResourceDescriptors):len(c.CallOptions.ListMonitoredResourceDescriptors)], opts...)
|
||||
it := &MonitoredResourceDescriptorIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoredrespb.MonitoredResourceDescriptor, string, error) {
|
||||
@@ -271,7 +253,7 @@ func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *logg
|
||||
// ListLogs lists the logs in projects, organizations, folders, or billing accounts.
|
||||
// Only logs that have entries are listed.
|
||||
func (c *Client) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest, opts ...gax.CallOption) *StringIterator {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.ListLogs[0:len(c.CallOptions.ListLogs):len(c.CallOptions.ListLogs)], opts...)
|
||||
it := &StringIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
|
||||
|
||||
+7
-7
@@ -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,
|
||||
@@ -41,7 +41,7 @@ func ExampleClient_DeleteLog() {
|
||||
}
|
||||
|
||||
req := &loggingpb.DeleteLogRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
err = c.DeleteLog(ctx, req)
|
||||
if err != nil {
|
||||
@@ -57,7 +57,7 @@ func ExampleClient_WriteLogEntries() {
|
||||
}
|
||||
|
||||
req := &loggingpb.WriteLogEntriesRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.WriteLogEntries(ctx, req)
|
||||
if err != nil {
|
||||
@@ -75,7 +75,7 @@ func ExampleClient_ListLogEntries() {
|
||||
}
|
||||
|
||||
req := &loggingpb.ListLogEntriesRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
it := c.ListLogEntries(ctx, req)
|
||||
for {
|
||||
@@ -99,7 +99,7 @@ func ExampleClient_ListMonitoredResourceDescriptors() {
|
||||
}
|
||||
|
||||
req := &loggingpb.ListMonitoredResourceDescriptorsRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
it := c.ListMonitoredResourceDescriptors(ctx, req)
|
||||
for {
|
||||
@@ -123,7 +123,7 @@ func ExampleClient_ListLogs() {
|
||||
}
|
||||
|
||||
req := &loggingpb.ListLogsRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
it := c.ListLogs(ctx, req)
|
||||
for {
|
||||
|
||||
+10
-28
@@ -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,
|
||||
@@ -84,8 +84,8 @@ type MetricsClient struct {
|
||||
// The call options for this service.
|
||||
CallOptions *MetricsCallOptions
|
||||
|
||||
// The metadata to be sent with each request.
|
||||
Metadata metadata.MD
|
||||
// The x-goog-* metadata to be sent with each request.
|
||||
xGoogMetadata metadata.MD
|
||||
}
|
||||
|
||||
// NewMetricsClient creates a new metrics service v2 client.
|
||||
@@ -123,30 +123,12 @@ func (c *MetricsClient) Close() error {
|
||||
func (c *MetricsClient) 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...))
|
||||
}
|
||||
|
||||
// MetricsProjectPath returns the path for the project resource.
|
||||
func MetricsProjectPath(project string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
""
|
||||
}
|
||||
|
||||
// MetricsMetricPath returns the path for the metric resource.
|
||||
func MetricsMetricPath(project, metric string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/metrics/" +
|
||||
metric +
|
||||
""
|
||||
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
|
||||
}
|
||||
|
||||
// ListLogMetrics lists logs-based metrics.
|
||||
func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest, opts ...gax.CallOption) *LogMetricIterator {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.ListLogMetrics[0:len(c.CallOptions.ListLogMetrics):len(c.CallOptions.ListLogMetrics)], opts...)
|
||||
it := &LogMetricIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogMetric, string, error) {
|
||||
@@ -181,7 +163,7 @@ func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListL
|
||||
|
||||
// GetLogMetric gets a logs-based metric.
|
||||
func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.GetLogMetric[0:len(c.CallOptions.GetLogMetric):len(c.CallOptions.GetLogMetric)], opts...)
|
||||
var resp *loggingpb.LogMetric
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -197,7 +179,7 @@ func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogM
|
||||
|
||||
// CreateLogMetric creates a logs-based metric.
|
||||
func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.CreateLogMetric[0:len(c.CallOptions.CreateLogMetric):len(c.CallOptions.CreateLogMetric)], opts...)
|
||||
var resp *loggingpb.LogMetric
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -213,7 +195,7 @@ func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.Crea
|
||||
|
||||
// UpdateLogMetric creates or updates a logs-based metric.
|
||||
func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.UpdateLogMetric[0:len(c.CallOptions.UpdateLogMetric):len(c.CallOptions.UpdateLogMetric)], opts...)
|
||||
var resp *loggingpb.LogMetric
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
@@ -229,7 +211,7 @@ func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.Upda
|
||||
|
||||
// DeleteLogMetric deletes a logs-based metric.
|
||||
func (c *MetricsClient) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertMetadata(ctx, c.Metadata)
|
||||
ctx = insertMetadata(ctx, c.xGoogMetadata)
|
||||
opts = append(c.CallOptions.DeleteLogMetric[0:len(c.CallOptions.DeleteLogMetric):len(c.CallOptions.DeleteLogMetric)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
|
||||
+7
-7
@@ -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,
|
||||
@@ -41,7 +41,7 @@ func ExampleMetricsClient_ListLogMetrics() {
|
||||
}
|
||||
|
||||
req := &loggingpb.ListLogMetricsRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
it := c.ListLogMetrics(ctx, req)
|
||||
for {
|
||||
@@ -65,7 +65,7 @@ func ExampleMetricsClient_GetLogMetric() {
|
||||
}
|
||||
|
||||
req := &loggingpb.GetLogMetricRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.GetLogMetric(ctx, req)
|
||||
if err != nil {
|
||||
@@ -83,7 +83,7 @@ func ExampleMetricsClient_CreateLogMetric() {
|
||||
}
|
||||
|
||||
req := &loggingpb.CreateLogMetricRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.CreateLogMetric(ctx, req)
|
||||
if err != nil {
|
||||
@@ -101,7 +101,7 @@ func ExampleMetricsClient_UpdateLogMetric() {
|
||||
}
|
||||
|
||||
req := &loggingpb.UpdateLogMetricRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
resp, err := c.UpdateLogMetric(ctx, req)
|
||||
if err != nil {
|
||||
@@ -119,7 +119,7 @@ func ExampleMetricsClient_DeleteLogMetric() {
|
||||
}
|
||||
|
||||
req := &loggingpb.DeleteLogMetricRequest{
|
||||
// TODO: Fill request struct fields.
|
||||
// TODO: Fill request struct fields.
|
||||
}
|
||||
err = c.DeleteLogMetric(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
+36
-36
@@ -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,
|
||||
@@ -374,7 +374,7 @@ func TestLoggingServiceV2DeleteLog(t *testing.T) {
|
||||
|
||||
mockLogging.resps = append(mockLogging.resps[:0], expectedResponse)
|
||||
|
||||
var formattedLogName string = LogPath("[PROJECT]", "[LOG]")
|
||||
var formattedLogName string = fmt.Sprintf("projects/%s/logs/%s", "[PROJECT]", "[LOG]")
|
||||
var request = &loggingpb.DeleteLogRequest{
|
||||
LogName: formattedLogName,
|
||||
}
|
||||
@@ -400,7 +400,7 @@ func TestLoggingServiceV2DeleteLogError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedLogName string = LogPath("[PROJECT]", "[LOG]")
|
||||
var formattedLogName string = fmt.Sprintf("projects/%s/logs/%s", "[PROJECT]", "[LOG]")
|
||||
var request = &loggingpb.DeleteLogRequest{
|
||||
LogName: formattedLogName,
|
||||
}
|
||||
@@ -626,7 +626,7 @@ func TestLoggingServiceV2ListLogs(t *testing.T) {
|
||||
|
||||
mockLogging.resps = append(mockLogging.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = ProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListLogsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -665,7 +665,7 @@ func TestLoggingServiceV2ListLogsError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListLogsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -698,7 +698,7 @@ func TestConfigServiceV2ListSinks(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListSinksRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -737,7 +737,7 @@ func TestConfigServiceV2ListSinksError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListSinksRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -775,7 +775,7 @@ func TestConfigServiceV2GetSink(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var formattedSinkName string = fmt.Sprintf("projects/%s/sinks/%s", "[PROJECT]", "[SINK]")
|
||||
var request = &loggingpb.GetSinkRequest{
|
||||
SinkName: formattedSinkName,
|
||||
}
|
||||
@@ -804,7 +804,7 @@ func TestConfigServiceV2GetSinkError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var formattedSinkName string = fmt.Sprintf("projects/%s/sinks/%s", "[PROJECT]", "[SINK]")
|
||||
var request = &loggingpb.GetSinkRequest{
|
||||
SinkName: formattedSinkName,
|
||||
}
|
||||
@@ -842,7 +842,7 @@ func TestConfigServiceV2CreateSink(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var sink *loggingpb.LogSink = &loggingpb.LogSink{}
|
||||
var request = &loggingpb.CreateSinkRequest{
|
||||
Parent: formattedParent,
|
||||
@@ -873,7 +873,7 @@ func TestConfigServiceV2CreateSinkError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var sink *loggingpb.LogSink = &loggingpb.LogSink{}
|
||||
var request = &loggingpb.CreateSinkRequest{
|
||||
Parent: formattedParent,
|
||||
@@ -913,7 +913,7 @@ func TestConfigServiceV2UpdateSink(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var formattedSinkName string = fmt.Sprintf("projects/%s/sinks/%s", "[PROJECT]", "[SINK]")
|
||||
var sink *loggingpb.LogSink = &loggingpb.LogSink{}
|
||||
var request = &loggingpb.UpdateSinkRequest{
|
||||
SinkName: formattedSinkName,
|
||||
@@ -944,7 +944,7 @@ func TestConfigServiceV2UpdateSinkError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var formattedSinkName string = fmt.Sprintf("projects/%s/sinks/%s", "[PROJECT]", "[SINK]")
|
||||
var sink *loggingpb.LogSink = &loggingpb.LogSink{}
|
||||
var request = &loggingpb.UpdateSinkRequest{
|
||||
SinkName: formattedSinkName,
|
||||
@@ -973,7 +973,7 @@ func TestConfigServiceV2DeleteSink(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var formattedSinkName string = fmt.Sprintf("projects/%s/sinks/%s", "[PROJECT]", "[SINK]")
|
||||
var request = &loggingpb.DeleteSinkRequest{
|
||||
SinkName: formattedSinkName,
|
||||
}
|
||||
@@ -999,7 +999,7 @@ func TestConfigServiceV2DeleteSinkError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var formattedSinkName string = fmt.Sprintf("projects/%s/sinks/%s", "[PROJECT]", "[SINK]")
|
||||
var request = &loggingpb.DeleteSinkRequest{
|
||||
SinkName: formattedSinkName,
|
||||
}
|
||||
@@ -1031,7 +1031,7 @@ func TestConfigServiceV2ListExclusions(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListExclusionsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -1070,7 +1070,7 @@ func TestConfigServiceV2ListExclusionsError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListExclusionsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -1106,7 +1106,7 @@ func TestConfigServiceV2GetExclusion(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedName string = ConfigExclusionPath("[PROJECT]", "[EXCLUSION]")
|
||||
var formattedName string = fmt.Sprintf("projects/%s/exclusions/%s", "[PROJECT]", "[EXCLUSION]")
|
||||
var request = &loggingpb.GetExclusionRequest{
|
||||
Name: formattedName,
|
||||
}
|
||||
@@ -1135,7 +1135,7 @@ func TestConfigServiceV2GetExclusionError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedName string = ConfigExclusionPath("[PROJECT]", "[EXCLUSION]")
|
||||
var formattedName string = fmt.Sprintf("projects/%s/exclusions/%s", "[PROJECT]", "[EXCLUSION]")
|
||||
var request = &loggingpb.GetExclusionRequest{
|
||||
Name: formattedName,
|
||||
}
|
||||
@@ -1171,7 +1171,7 @@ func TestConfigServiceV2CreateExclusion(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var exclusion *loggingpb.LogExclusion = &loggingpb.LogExclusion{}
|
||||
var request = &loggingpb.CreateExclusionRequest{
|
||||
Parent: formattedParent,
|
||||
@@ -1202,7 +1202,7 @@ func TestConfigServiceV2CreateExclusionError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var exclusion *loggingpb.LogExclusion = &loggingpb.LogExclusion{}
|
||||
var request = &loggingpb.CreateExclusionRequest{
|
||||
Parent: formattedParent,
|
||||
@@ -1240,7 +1240,7 @@ func TestConfigServiceV2UpdateExclusion(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedName string = ConfigExclusionPath("[PROJECT]", "[EXCLUSION]")
|
||||
var formattedName string = fmt.Sprintf("projects/%s/exclusions/%s", "[PROJECT]", "[EXCLUSION]")
|
||||
var exclusion *loggingpb.LogExclusion = &loggingpb.LogExclusion{}
|
||||
var updateMask *field_maskpb.FieldMask = &field_maskpb.FieldMask{}
|
||||
var request = &loggingpb.UpdateExclusionRequest{
|
||||
@@ -1273,7 +1273,7 @@ func TestConfigServiceV2UpdateExclusionError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedName string = ConfigExclusionPath("[PROJECT]", "[EXCLUSION]")
|
||||
var formattedName string = fmt.Sprintf("projects/%s/exclusions/%s", "[PROJECT]", "[EXCLUSION]")
|
||||
var exclusion *loggingpb.LogExclusion = &loggingpb.LogExclusion{}
|
||||
var updateMask *field_maskpb.FieldMask = &field_maskpb.FieldMask{}
|
||||
var request = &loggingpb.UpdateExclusionRequest{
|
||||
@@ -1304,7 +1304,7 @@ func TestConfigServiceV2DeleteExclusion(t *testing.T) {
|
||||
|
||||
mockConfig.resps = append(mockConfig.resps[:0], expectedResponse)
|
||||
|
||||
var formattedName string = ConfigExclusionPath("[PROJECT]", "[EXCLUSION]")
|
||||
var formattedName string = fmt.Sprintf("projects/%s/exclusions/%s", "[PROJECT]", "[EXCLUSION]")
|
||||
var request = &loggingpb.DeleteExclusionRequest{
|
||||
Name: formattedName,
|
||||
}
|
||||
@@ -1330,7 +1330,7 @@ func TestConfigServiceV2DeleteExclusionError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedName string = ConfigExclusionPath("[PROJECT]", "[EXCLUSION]")
|
||||
var formattedName string = fmt.Sprintf("projects/%s/exclusions/%s", "[PROJECT]", "[EXCLUSION]")
|
||||
var request = &loggingpb.DeleteExclusionRequest{
|
||||
Name: formattedName,
|
||||
}
|
||||
@@ -1362,7 +1362,7 @@ func TestMetricsServiceV2ListLogMetrics(t *testing.T) {
|
||||
|
||||
mockMetrics.resps = append(mockMetrics.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = MetricsProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListLogMetricsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -1401,7 +1401,7 @@ func TestMetricsServiceV2ListLogMetricsError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = MetricsProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var request = &loggingpb.ListLogMetricsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -1437,7 +1437,7 @@ func TestMetricsServiceV2GetLogMetric(t *testing.T) {
|
||||
|
||||
mockMetrics.resps = append(mockMetrics.resps[:0], expectedResponse)
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var formattedMetricName string = fmt.Sprintf("projects/%s/metrics/%s", "[PROJECT]", "[METRIC]")
|
||||
var request = &loggingpb.GetLogMetricRequest{
|
||||
MetricName: formattedMetricName,
|
||||
}
|
||||
@@ -1466,7 +1466,7 @@ func TestMetricsServiceV2GetLogMetricError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var formattedMetricName string = fmt.Sprintf("projects/%s/metrics/%s", "[PROJECT]", "[METRIC]")
|
||||
var request = &loggingpb.GetLogMetricRequest{
|
||||
MetricName: formattedMetricName,
|
||||
}
|
||||
@@ -1502,7 +1502,7 @@ func TestMetricsServiceV2CreateLogMetric(t *testing.T) {
|
||||
|
||||
mockMetrics.resps = append(mockMetrics.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = MetricsProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var metric *loggingpb.LogMetric = &loggingpb.LogMetric{}
|
||||
var request = &loggingpb.CreateLogMetricRequest{
|
||||
Parent: formattedParent,
|
||||
@@ -1533,7 +1533,7 @@ func TestMetricsServiceV2CreateLogMetricError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = MetricsProjectPath("[PROJECT]")
|
||||
var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
|
||||
var metric *loggingpb.LogMetric = &loggingpb.LogMetric{}
|
||||
var request = &loggingpb.CreateLogMetricRequest{
|
||||
Parent: formattedParent,
|
||||
@@ -1571,7 +1571,7 @@ func TestMetricsServiceV2UpdateLogMetric(t *testing.T) {
|
||||
|
||||
mockMetrics.resps = append(mockMetrics.resps[:0], expectedResponse)
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var formattedMetricName string = fmt.Sprintf("projects/%s/metrics/%s", "[PROJECT]", "[METRIC]")
|
||||
var metric *loggingpb.LogMetric = &loggingpb.LogMetric{}
|
||||
var request = &loggingpb.UpdateLogMetricRequest{
|
||||
MetricName: formattedMetricName,
|
||||
@@ -1602,7 +1602,7 @@ func TestMetricsServiceV2UpdateLogMetricError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var formattedMetricName string = fmt.Sprintf("projects/%s/metrics/%s", "[PROJECT]", "[METRIC]")
|
||||
var metric *loggingpb.LogMetric = &loggingpb.LogMetric{}
|
||||
var request = &loggingpb.UpdateLogMetricRequest{
|
||||
MetricName: formattedMetricName,
|
||||
@@ -1631,7 +1631,7 @@ func TestMetricsServiceV2DeleteLogMetric(t *testing.T) {
|
||||
|
||||
mockMetrics.resps = append(mockMetrics.resps[:0], expectedResponse)
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var formattedMetricName string = fmt.Sprintf("projects/%s/metrics/%s", "[PROJECT]", "[METRIC]")
|
||||
var request = &loggingpb.DeleteLogMetricRequest{
|
||||
MetricName: formattedMetricName,
|
||||
}
|
||||
@@ -1657,7 +1657,7 @@ func TestMetricsServiceV2DeleteLogMetricError(t *testing.T) {
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var formattedMetricName string = fmt.Sprintf("projects/%s/metrics/%s", "[PROJECT]", "[METRIC]")
|
||||
var request = &loggingpb.DeleteLogMetricRequest{
|
||||
MetricName: formattedMetricName,
|
||||
}
|
||||
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
// 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 logging
|
||||
|
||||
// ConfigProjectPath returns the path for the project resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s", project)
|
||||
// instead.
|
||||
func ConfigProjectPath(project string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
""
|
||||
}
|
||||
|
||||
// ConfigSinkPath returns the path for the sink resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s/sinks/%s", project, sink)
|
||||
// instead.
|
||||
func ConfigSinkPath(project, sink string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/sinks/" +
|
||||
sink +
|
||||
""
|
||||
}
|
||||
|
||||
// ConfigExclusionPath returns the path for the exclusion resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s/exclusions/%s", project, exclusion)
|
||||
// instead.
|
||||
func ConfigExclusionPath(project, exclusion string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/exclusions/" +
|
||||
exclusion +
|
||||
""
|
||||
}
|
||||
|
||||
// ProjectPath returns the path for the project resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s", project)
|
||||
// instead.
|
||||
func ProjectPath(project string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
""
|
||||
}
|
||||
|
||||
// LogPath returns the path for the log resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s/logs/%s", project, log)
|
||||
// instead.
|
||||
func LogPath(project, log string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/logs/" +
|
||||
log +
|
||||
""
|
||||
}
|
||||
|
||||
// MetricsProjectPath returns the path for the project resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s", project)
|
||||
// instead.
|
||||
func MetricsProjectPath(project string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
""
|
||||
}
|
||||
|
||||
// MetricsMetricPath returns the path for the metric resource.
|
||||
//
|
||||
// Deprecated: Use
|
||||
// fmt.Sprintf("projects/%s/metrics/%s", project, metric)
|
||||
// instead.
|
||||
func MetricsMetricPath(project, metric string) string {
|
||||
return "" +
|
||||
"projects/" +
|
||||
project +
|
||||
"/metrics/" +
|
||||
metric +
|
||||
""
|
||||
}
|
||||
+16
-39
@@ -22,7 +22,6 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -88,15 +87,18 @@ func (h *loggingHandler) DeleteLog(_ context.Context, req *logpb.DeleteLogReques
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
// The only project ID that WriteLogEntries will accept.
|
||||
// The only IDs that WriteLogEntries will accept.
|
||||
// Important for testing Ping.
|
||||
const validProjectID = "PROJECT_ID"
|
||||
const (
|
||||
validProjectID = "PROJECT_ID"
|
||||
validOrgID = "433637338589"
|
||||
)
|
||||
|
||||
// WriteLogEntries writes log entries to Stackdriver Logging. All log entries in
|
||||
// Stackdriver Logging are written by this method.
|
||||
func (h *loggingHandler) WriteLogEntries(_ context.Context, req *logpb.WriteLogEntriesRequest) (*logpb.WriteLogEntriesResponse, error) {
|
||||
if !strings.HasPrefix(req.LogName, "projects/"+validProjectID+"/") {
|
||||
return nil, fmt.Errorf("bad project ID: %q", req.LogName)
|
||||
if !strings.HasPrefix(req.LogName, "projects/"+validProjectID+"/") && !strings.HasPrefix(req.LogName, "organizations/"+validOrgID+"/") {
|
||||
return nil, fmt.Errorf("bad LogName: %q", req.LogName)
|
||||
}
|
||||
// TODO(jba): support insertId?
|
||||
h.mu.Lock()
|
||||
@@ -142,7 +144,7 @@ func (h *loggingHandler) ListLogEntries(_ context.Context, req *logpb.ListLogEnt
|
||||
return nil, err
|
||||
}
|
||||
|
||||
from, to, nextPageToken, err := getPage(int(req.PageSize), req.PageToken, len(entries))
|
||||
from, to, nextPageToken, err := testutil.PageBounds(int(req.PageSize), req.PageToken, len(entries))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -152,35 +154,6 @@ func (h *loggingHandler) ListLogEntries(_ context.Context, req *logpb.ListLogEnt
|
||||
}, nil
|
||||
}
|
||||
|
||||
// getPage converts an incoming page size and token from an RPC request into
|
||||
// slice bounds and the outgoing next-page token.
|
||||
//
|
||||
// getPage assumes that the complete, unpaginated list of items exists as a
|
||||
// single slice. In addition to the page size and token, getPage needs the
|
||||
// length of that slice.
|
||||
//
|
||||
// getPage's first two return values should be used to construct a sub-slice of
|
||||
// the complete, unpaginated slice. E.g. if the complete slice is s, then
|
||||
// s[from:to] is the desired page. Its third return value should be set as the
|
||||
// NextPageToken field of the RPC response.
|
||||
func getPage(pageSize int, pageToken string, length int) (from, to int, nextPageToken string, err error) {
|
||||
from, to = 0, length
|
||||
if pageToken != "" {
|
||||
from, err = strconv.Atoi(pageToken)
|
||||
if err != nil {
|
||||
return 0, 0, "", invalidArgument("bad page token")
|
||||
}
|
||||
if from >= length {
|
||||
return length, length, "", nil
|
||||
}
|
||||
}
|
||||
if pageSize > 0 && from+pageSize < length {
|
||||
to = from + pageSize
|
||||
nextPageToken = strconv.Itoa(to)
|
||||
}
|
||||
return from, to, nextPageToken, nil
|
||||
}
|
||||
|
||||
func (h *loggingHandler) filterEntries(filter string) ([]*logpb.LogEntry, error) {
|
||||
logName, err := parseFilter(filter)
|
||||
if err != nil {
|
||||
@@ -268,12 +241,16 @@ func (h *loggingHandler) ListMonitoredResourceDescriptors(context.Context, *logp
|
||||
func (h *loggingHandler) ListLogs(_ context.Context, req *logpb.ListLogsRequest) (*logpb.ListLogsResponse, error) {
|
||||
// Return fixed, fake response.
|
||||
logNames := []string{"a", "b", "c"}
|
||||
from, to, npt, err := getPage(int(req.PageSize), req.PageToken, len(logNames))
|
||||
from, to, npt, err := testutil.PageBounds(int(req.PageSize), req.PageToken, len(logNames))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var lns []string
|
||||
for _, ln := range logNames[from:to] {
|
||||
lns = append(lns, req.Parent+"/logs/"+ln)
|
||||
}
|
||||
return &logpb.ListLogsResponse{
|
||||
LogNames: logNames[from:to],
|
||||
LogNames: lns,
|
||||
NextPageToken: npt,
|
||||
}, nil
|
||||
}
|
||||
@@ -329,7 +306,7 @@ func (h *configHandler) ListSinks(_ context.Context, req *logpb.ListSinksRequest
|
||||
h.mu.Unlock() // safe because no *logpb.LogSink is ever modified
|
||||
// Since map iteration varies, sort the sinks.
|
||||
sort.Sort(sinksByName(sinks))
|
||||
from, to, nextPageToken, err := getPage(int(req.PageSize), req.PageToken, len(sinks))
|
||||
from, to, nextPageToken, err := testutil.PageBounds(int(req.PageSize), req.PageToken, len(sinks))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -396,7 +373,7 @@ func (h *metricHandler) ListLogMetrics(_ context.Context, req *logpb.ListLogMetr
|
||||
h.mu.Unlock() // safe because no *logpb.LogMetric is ever modified
|
||||
// Since map iteration varies, sort the metrics.
|
||||
sort.Sort(metricsByName(metrics))
|
||||
from, to, nextPageToken, err := getPage(int(req.PageSize), req.PageToken, len(metrics))
|
||||
from, to, nextPageToken, err := testutil.PageBounds(int(req.PageSize), req.PageToken, len(metrics))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+28
-26
@@ -26,7 +26,6 @@
|
||||
package logadmin // import "cloud.google.com/go/logging/logadmin"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
@@ -54,22 +53,20 @@ import (
|
||||
|
||||
// Client is a Logging client. A Client is associated with a single Cloud project.
|
||||
type Client struct {
|
||||
lClient *vkit.Client // logging client
|
||||
sClient *vkit.ConfigClient // sink client
|
||||
mClient *vkit.MetricsClient // metric client
|
||||
projectID string
|
||||
closed bool
|
||||
lClient *vkit.Client // logging client
|
||||
sClient *vkit.ConfigClient // sink client
|
||||
mClient *vkit.MetricsClient // metric client
|
||||
parent string
|
||||
closed bool
|
||||
}
|
||||
|
||||
// NewClient returns a new logging client associated with the provided project ID.
|
||||
//
|
||||
// By default NewClient uses AdminScope. To use a different scope, call
|
||||
// NewClient using a WithScopes option (see https://godoc.org/google.golang.org/api/option#WithScopes).
|
||||
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
|
||||
// Check for '/' in project ID to reserve the ability to support various owning resources,
|
||||
// in the form "{Collection}/{Name}", for instance "organizations/my-org".
|
||||
if strings.ContainsRune(projectID, '/') {
|
||||
return nil, errors.New("logging: project ID contains '/'")
|
||||
func NewClient(ctx context.Context, parent string, opts ...option.ClientOption) (*Client, error) {
|
||||
if !strings.ContainsRune(parent, '/') {
|
||||
parent = "projects/" + parent
|
||||
}
|
||||
opts = append([]option.ClientOption{
|
||||
option.WithEndpoint(internal.ProdAddr),
|
||||
@@ -106,19 +103,14 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio
|
||||
sc.SetGoogleClientInfo("gccl", version.Repo)
|
||||
mc.SetGoogleClientInfo("gccl", version.Repo)
|
||||
client := &Client{
|
||||
lClient: lc,
|
||||
sClient: sc,
|
||||
mClient: mc,
|
||||
projectID: projectID,
|
||||
lClient: lc,
|
||||
sClient: sc,
|
||||
mClient: mc,
|
||||
parent: parent,
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// parent returns the string used in many RPCs to denote the parent resource of the log.
|
||||
func (c *Client) parent() string {
|
||||
return "projects/" + c.projectID
|
||||
}
|
||||
|
||||
// Close closes the client.
|
||||
func (c *Client) Close() error {
|
||||
if c.closed {
|
||||
@@ -137,7 +129,7 @@ func (c *Client) Close() error {
|
||||
// logID identifies the log within the project. An example log ID is "syslog". Requires AdminScope.
|
||||
func (c *Client) DeleteLog(ctx context.Context, logID string) error {
|
||||
return c.lClient.DeleteLog(ctx, &logpb.DeleteLogRequest{
|
||||
LogName: internal.LogPath(c.parent(), logID),
|
||||
LogName: internal.LogPath(c.parent, logID),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -197,6 +189,16 @@ func (p projectIDs) set(r *logpb.ListLogEntriesRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceNames sets the resource names from which to retrieve
|
||||
// log entries. Examples: "projects/my-project-1A", "organizations/my-org".
|
||||
func ResourceNames(rns []string) EntriesOption { return resourceNames(rns) }
|
||||
|
||||
type resourceNames []string
|
||||
|
||||
func (rn resourceNames) set(r *logpb.ListLogEntriesRequest) {
|
||||
r.ResourceNames = append([]string(nil), rn...)
|
||||
}
|
||||
|
||||
// Filter sets an advanced logs filter for listing log entries (see
|
||||
// https://cloud.google.com/logging/docs/view/advanced_filters). The filter is
|
||||
// compared against all log entries in the projects specified by ProjectIDs.
|
||||
@@ -228,7 +230,7 @@ func (newestFirst) set(r *logpb.ListLogEntriesRequest) { r.OrderBy = "timestamp
|
||||
// NewClient. This may be overridden by passing a ProjectIDs option. Requires ReadScope or AdminScope.
|
||||
func (c *Client) Entries(ctx context.Context, opts ...EntriesOption) *EntryIterator {
|
||||
it := &EntryIterator{
|
||||
it: c.lClient.ListLogEntries(ctx, listLogEntriesRequest(c.projectID, opts)),
|
||||
it: c.lClient.ListLogEntries(ctx, listLogEntriesRequest(c.parent, opts)),
|
||||
}
|
||||
it.pageInfo, it.nextFunc = iterator.NewPageInfo(
|
||||
it.fetch,
|
||||
@@ -237,9 +239,9 @@ func (c *Client) Entries(ctx context.Context, opts ...EntriesOption) *EntryItera
|
||||
return it
|
||||
}
|
||||
|
||||
func listLogEntriesRequest(projectID string, opts []EntriesOption) *logpb.ListLogEntriesRequest {
|
||||
func listLogEntriesRequest(parent string, opts []EntriesOption) *logpb.ListLogEntriesRequest {
|
||||
req := &logpb.ListLogEntriesRequest{
|
||||
ResourceNames: []string{"projects/" + projectID},
|
||||
ResourceNames: []string{parent},
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt.set(req)
|
||||
@@ -340,8 +342,8 @@ func fromLogEntry(le *logpb.LogEntry) (*logging.Entry, error) {
|
||||
// Logs lists the logs owned by the parent resource of the client.
|
||||
func (c *Client) Logs(ctx context.Context) *LogIterator {
|
||||
it := &LogIterator{
|
||||
parentResource: c.parent(),
|
||||
it: c.lClient.ListLogs(ctx, &logpb.ListLogsRequest{Parent: c.parent()}),
|
||||
parentResource: c.parent,
|
||||
it: c.lClient.ListLogs(ctx, &logpb.ListLogsRequest{Parent: c.parent}),
|
||||
}
|
||||
it.pageInfo, it.nextFunc = iterator.NewPageInfo(
|
||||
it.fetch,
|
||||
|
||||
+16
-14
@@ -32,6 +32,7 @@ import (
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
durpb "github.com/golang/protobuf/ptypes/duration"
|
||||
structpb "github.com/golang/protobuf/ptypes/struct"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/option"
|
||||
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
|
||||
@@ -183,7 +184,7 @@ func TestFromLogEntry(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := testutil.Diff(got, want, testutil.IgnoreUnexported(http.Request{})); diff != "" {
|
||||
if diff := testutil.Diff(got, want, cmpopts.IgnoreUnexported(http.Request{})); diff != "" {
|
||||
t.Errorf("FullEntry:\n%s", diff)
|
||||
}
|
||||
|
||||
@@ -232,29 +233,30 @@ func TestFromLogEntry(t *testing.T) {
|
||||
|
||||
func TestListLogEntriesRequest(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
opts []EntriesOption
|
||||
projectIDs []string
|
||||
filter string
|
||||
orderBy string
|
||||
opts []EntriesOption
|
||||
resourceNames []string
|
||||
filter string
|
||||
orderBy string
|
||||
}{
|
||||
// Default is client's project ID, empty filter and orderBy.
|
||||
{nil,
|
||||
[]string{"PROJECT_ID"}, "", ""},
|
||||
{nil, []string{"projects/PROJECT_ID"}, "", ""},
|
||||
{[]EntriesOption{NewestFirst(), Filter("f")},
|
||||
[]string{"PROJECT_ID"}, "f", "timestamp desc"},
|
||||
[]string{"projects/PROJECT_ID"}, "f", "timestamp desc"},
|
||||
{[]EntriesOption{ProjectIDs([]string{"foo"})},
|
||||
[]string{"foo"}, "", ""},
|
||||
[]string{"projects/foo"}, "", ""},
|
||||
{[]EntriesOption{ResourceNames([]string{"folders/F", "organizations/O"})},
|
||||
[]string{"folders/F", "organizations/O"}, "", ""},
|
||||
{[]EntriesOption{NewestFirst(), Filter("f"), ProjectIDs([]string{"foo"})},
|
||||
[]string{"foo"}, "f", "timestamp desc"},
|
||||
[]string{"projects/foo"}, "f", "timestamp desc"},
|
||||
{[]EntriesOption{NewestFirst(), Filter("f"), ProjectIDs([]string{"foo"})},
|
||||
[]string{"foo"}, "f", "timestamp desc"},
|
||||
[]string{"projects/foo"}, "f", "timestamp desc"},
|
||||
// If there are repeats, last one wins.
|
||||
{[]EntriesOption{NewestFirst(), Filter("no"), ProjectIDs([]string{"foo"}), Filter("f")},
|
||||
[]string{"foo"}, "f", "timestamp desc"},
|
||||
[]string{"projects/foo"}, "f", "timestamp desc"},
|
||||
} {
|
||||
got := listLogEntriesRequest("PROJECT_ID", test.opts)
|
||||
got := listLogEntriesRequest("projects/PROJECT_ID", test.opts)
|
||||
want := &logpb.ListLogEntriesRequest{
|
||||
ResourceNames: []string{"projects/" + test.projectIDs[0]},
|
||||
ResourceNames: test.resourceNames,
|
||||
Filter: test.filter,
|
||||
OrderBy: test.orderBy,
|
||||
}
|
||||
|
||||
+3
-3
@@ -49,7 +49,7 @@ type Metric struct {
|
||||
// CreateMetric creates a logs-based metric.
|
||||
func (c *Client) CreateMetric(ctx context.Context, m *Metric) error {
|
||||
_, err := c.mClient.CreateLogMetric(ctx, &logpb.CreateLogMetricRequest{
|
||||
Parent: c.parent(),
|
||||
Parent: c.parent,
|
||||
Metric: toLogMetric(m),
|
||||
})
|
||||
return err
|
||||
@@ -87,14 +87,14 @@ func (c *Client) UpdateMetric(ctx context.Context, m *Metric) error {
|
||||
}
|
||||
|
||||
func (c *Client) metricPath(metricID string) string {
|
||||
return fmt.Sprintf("%s/metrics/%s", c.parent(), metricID)
|
||||
return fmt.Sprintf("%s/metrics/%s", c.parent, metricID)
|
||||
}
|
||||
|
||||
// Metrics returns a MetricIterator for iterating over all Metrics in the Client's project.
|
||||
// Requires ReadScope or AdminScope.
|
||||
func (c *Client) Metrics(ctx context.Context) *MetricIterator {
|
||||
it := &MetricIterator{
|
||||
it: c.mClient.ListLogMetrics(ctx, &logpb.ListLogMetricsRequest{Parent: c.parent()}),
|
||||
it: c.mClient.ListLogMetrics(ctx, &logpb.ListLogMetricsRequest{Parent: c.parent}),
|
||||
}
|
||||
it.pageInfo, it.nextFunc = iterator.NewPageInfo(
|
||||
it.fetch,
|
||||
|
||||
+3
-3
@@ -55,7 +55,7 @@ type Sink struct {
|
||||
// Requires AdminScope.
|
||||
func (c *Client) CreateSink(ctx context.Context, sink *Sink) (*Sink, error) {
|
||||
ls, err := c.sClient.CreateSink(ctx, &logpb.CreateSinkRequest{
|
||||
Parent: c.parent(),
|
||||
Parent: c.parent,
|
||||
Sink: toLogSink(sink),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -100,14 +100,14 @@ func (c *Client) UpdateSink(ctx context.Context, sink *Sink) (*Sink, error) {
|
||||
}
|
||||
|
||||
func (c *Client) sinkPath(sinkID string) string {
|
||||
return fmt.Sprintf("%s/sinks/%s", c.parent(), sinkID)
|
||||
return fmt.Sprintf("%s/sinks/%s", c.parent, sinkID)
|
||||
}
|
||||
|
||||
// Sinks returns a SinkIterator for iterating over all Sinks in the Client's project.
|
||||
// Requires ReadScope or AdminScope.
|
||||
func (c *Client) Sinks(ctx context.Context) *SinkIterator {
|
||||
it := &SinkIterator{
|
||||
it: c.sClient.ListSinks(ctx, &logpb.ListSinksRequest{Parent: c.parent()}),
|
||||
it: c.sClient.ListSinks(ctx, &logpb.ListSinksRequest{Parent: c.parent}),
|
||||
}
|
||||
it.pageInfo, it.nextFunc = iterator.NewPageInfo(
|
||||
it.fetch,
|
||||
|
||||
+49
-27
@@ -94,12 +94,12 @@ var ErrOversizedEntry = bundler.ErrOversizedItem
|
||||
|
||||
// Client is a Logging client. A Client is associated with a single Cloud project.
|
||||
type Client struct {
|
||||
client *vkit.Client // client for the logging service
|
||||
projectID string
|
||||
errc chan error // should be buffered to minimize dropped errors
|
||||
donec chan struct{} // closed on Client.Close to close Logger bundlers
|
||||
loggers sync.WaitGroup // so we can wait for loggers to close
|
||||
closed bool
|
||||
client *vkit.Client // client for the logging service
|
||||
parent string // e.g. "projects/proj-id"
|
||||
errc chan error // should be buffered to minimize dropped errors
|
||||
donec chan struct{} // closed on Client.Close to close Logger bundlers
|
||||
loggers sync.WaitGroup // so we can wait for loggers to close
|
||||
closed bool
|
||||
|
||||
mu sync.Mutex
|
||||
nErrs int // number of errors we saw
|
||||
@@ -117,15 +117,20 @@ type Client struct {
|
||||
OnError func(err error)
|
||||
}
|
||||
|
||||
// NewClient returns a new logging client associated with the provided project ID.
|
||||
// NewClient returns a new logging client associated with the provided parent.
|
||||
// A parent can take any of the following forms:
|
||||
// projects/PROJECT_ID
|
||||
// folders/FOLDER_ID
|
||||
// billingAccounts/ACCOUNT_ID
|
||||
// organizations/ORG_ID
|
||||
// for backwards compatibility, a string with no '/' is also allowed and is interpreted
|
||||
// as a project ID.
|
||||
//
|
||||
// By default NewClient uses WriteScope. To use a different scope, call
|
||||
// NewClient using a WithScopes option (see https://godoc.org/google.golang.org/api/option#WithScopes).
|
||||
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
|
||||
// Check for '/' in project ID to reserve the ability to support various owning resources,
|
||||
// in the form "{Collection}/{Name}", for instance "organizations/my-org".
|
||||
if strings.ContainsRune(projectID, '/') {
|
||||
return nil, errors.New("logging: project ID contains '/'")
|
||||
func NewClient(ctx context.Context, parent string, opts ...option.ClientOption) (*Client, error) {
|
||||
if !strings.ContainsRune(parent, '/') {
|
||||
parent = "projects/" + parent
|
||||
}
|
||||
opts = append([]option.ClientOption{
|
||||
option.WithEndpoint(internal.ProdAddr),
|
||||
@@ -137,11 +142,11 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio
|
||||
}
|
||||
c.SetGoogleClientInfo("gccl", version.Repo)
|
||||
client := &Client{
|
||||
client: c,
|
||||
projectID: projectID,
|
||||
errc: make(chan error, defaultErrorCapacity), // create a small buffer for errors
|
||||
donec: make(chan struct{}),
|
||||
OnError: func(e error) { log.Printf("logging client: %v", e) },
|
||||
client: c,
|
||||
parent: parent,
|
||||
errc: make(chan error, defaultErrorCapacity), // create a small buffer for errors
|
||||
donec: make(chan struct{}),
|
||||
OnError: func(e error) { log.Printf("logging client: %v", e) },
|
||||
}
|
||||
// Call the user's function synchronously, to make life easier for them.
|
||||
go func() {
|
||||
@@ -153,18 +158,13 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio
|
||||
if fn := client.OnError; fn != nil {
|
||||
fn(err)
|
||||
} else {
|
||||
log.Printf("logging (project ID %q): %v", projectID, err)
|
||||
log.Printf("logging (parent %q): %v", parent, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// parent returns the string used in many RPCs to denote the parent resource of the log.
|
||||
func (c *Client) parent() string {
|
||||
return "projects/" + c.projectID
|
||||
}
|
||||
|
||||
var unixZeroTimestamp *tspb.Timestamp
|
||||
|
||||
func init() {
|
||||
@@ -185,8 +185,8 @@ func (c *Client) Ping(ctx context.Context) error {
|
||||
InsertId: "ping", // necessary for the service to dedup these entries.
|
||||
}
|
||||
_, err := c.client.WriteLogEntries(ctx, &logpb.WriteLogEntriesRequest{
|
||||
LogName: internal.LogPath(c.parent(), "ping"),
|
||||
Resource: globalResource(c.projectID),
|
||||
LogName: internal.LogPath(c.parent, "ping"),
|
||||
Resource: monitoredResource(c.parent),
|
||||
Entries: []*logpb.LogEntry{ent},
|
||||
})
|
||||
return err
|
||||
@@ -279,6 +279,28 @@ func detectResource() *mrpb.MonitoredResource {
|
||||
return detectedResource.pb
|
||||
}
|
||||
|
||||
var resourceInfo = map[string]struct{ rtype, label string }{
|
||||
"organizations": {"organization", "organization_id"},
|
||||
"folders": {"folder", "folder_id"},
|
||||
"projects": {"project", "project_id"},
|
||||
"billingAccounts": {"billing_account", "account_id"},
|
||||
}
|
||||
|
||||
func monitoredResource(parent string) *mrpb.MonitoredResource {
|
||||
parts := strings.SplitN(parent, "/", 2)
|
||||
if len(parts) != 2 {
|
||||
return globalResource(parent)
|
||||
}
|
||||
info, ok := resourceInfo[parts[0]]
|
||||
if !ok {
|
||||
return globalResource(parts[1])
|
||||
}
|
||||
return &mrpb.MonitoredResource{
|
||||
Type: info.rtype,
|
||||
Labels: map[string]string{info.label: parts[1]},
|
||||
}
|
||||
}
|
||||
|
||||
func globalResource(projectID string) *mrpb.MonitoredResource {
|
||||
return &mrpb.MonitoredResource{
|
||||
Type: "global",
|
||||
@@ -368,11 +390,11 @@ func (b bufferedByteLimit) set(l *Logger) { l.bundler.BufferedByteLimit = int(b)
|
||||
func (c *Client) Logger(logID string, opts ...LoggerOption) *Logger {
|
||||
r := detectResource()
|
||||
if r == nil {
|
||||
r = globalResource(c.projectID)
|
||||
r = monitoredResource(c.parent)
|
||||
}
|
||||
l := &Logger{
|
||||
client: c,
|
||||
logName: internal.LogPath(c.parent(), logID),
|
||||
logName: internal.LogPath(c.parent, logID),
|
||||
commonResource: r,
|
||||
}
|
||||
// TODO(jba): determine the right context for the bundle handler.
|
||||
|
||||
+59
-7
@@ -38,6 +38,8 @@ import (
|
||||
"google.golang.org/api/option"
|
||||
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const testLogIDPrefix = "GO-LOGGING-CLIENT/TEST-LOG"
|
||||
@@ -91,16 +93,16 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
logging.SetNow(testNow)
|
||||
|
||||
newClients = func(ctx context.Context, projectID string) (*logging.Client, *logadmin.Client) {
|
||||
newClients = func(ctx context.Context, parent string) (*logging.Client, *logadmin.Client) {
|
||||
conn, err := grpc.Dial(addr, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.Fatalf("dialing %q: %v", addr, err)
|
||||
}
|
||||
c, err := logging.NewClient(ctx, projectID, option.WithGRPCConn(conn))
|
||||
c, err := logging.NewClient(ctx, parent, option.WithGRPCConn(conn))
|
||||
if err != nil {
|
||||
log.Fatalf("creating client for fake at %q: %v", addr, err)
|
||||
}
|
||||
ac, err := logadmin.NewClient(ctx, projectID, option.WithGRPCConn(conn))
|
||||
ac, err := logadmin.NewClient(ctx, parent, option.WithGRPCConn(conn))
|
||||
if err != nil {
|
||||
log.Fatalf("creating client for fake at %q: %v", addr, err)
|
||||
}
|
||||
@@ -120,12 +122,12 @@ func TestMain(m *testing.M) {
|
||||
log.Fatal("The project key must be set. See CONTRIBUTING.md for details")
|
||||
}
|
||||
log.Printf("running integration tests with project %s", testProjectID)
|
||||
newClients = func(ctx context.Context, projectID string) (*logging.Client, *logadmin.Client) {
|
||||
c, err := logging.NewClient(ctx, projectID, option.WithTokenSource(ts))
|
||||
newClients = func(ctx context.Context, parent string) (*logging.Client, *logadmin.Client) {
|
||||
c, err := logging.NewClient(ctx, parent, option.WithTokenSource(ts))
|
||||
if err != nil {
|
||||
log.Fatalf("creating prod client: %v", err)
|
||||
}
|
||||
ac, err := logadmin.NewClient(ctx, projectID, option.WithTokenSource(ts))
|
||||
ac, err := logadmin.NewClient(ctx, parent, option.WithTokenSource(ts))
|
||||
if err != nil {
|
||||
log.Fatalf("creating prod client: %v", err)
|
||||
}
|
||||
@@ -289,8 +291,12 @@ func countLogEntries(ctx context.Context, filter string) int {
|
||||
}
|
||||
|
||||
func allTestLogEntries(ctx context.Context) ([]*logging.Entry, error) {
|
||||
return allEntries(ctx, aclient, testFilter)
|
||||
}
|
||||
|
||||
func allEntries(ctx context.Context, aclient *logadmin.Client, filter string) ([]*logging.Entry, error) {
|
||||
var es []*logging.Entry
|
||||
it := aclient.Entries(ctx, logadmin.Filter(testFilter))
|
||||
it := aclient.Entries(ctx, logadmin.Filter(filter))
|
||||
for {
|
||||
e, err := cleanNext(it)
|
||||
switch err {
|
||||
@@ -471,6 +477,52 @@ func TestLogsAndDelete(t *testing.T) {
|
||||
t.Logf("deleted %d logs", nDeleted)
|
||||
}
|
||||
|
||||
func TestNonProjectParent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
initLogs(ctx)
|
||||
const orgID = "433637338589" // org ID for google.com
|
||||
parent := "organizations/" + orgID
|
||||
c, a := newClients(ctx, parent)
|
||||
lg := c.Logger(testLogID)
|
||||
err := lg.LogSync(ctx, logging.Entry{Payload: "hello"})
|
||||
if integrationTest {
|
||||
// We don't have permission to log to the organization.
|
||||
if got, want := status.Code(err), codes.PermissionDenied; got != want {
|
||||
t.Errorf("got code %s, want %s", got, want)
|
||||
}
|
||||
return
|
||||
}
|
||||
// Continue test against fake.
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []*logging.Entry{{
|
||||
Timestamp: testNow().UTC(),
|
||||
Payload: "hello",
|
||||
LogName: parent + "/logs/" + testLogID,
|
||||
Resource: &mrpb.MonitoredResource{
|
||||
Type: "organization",
|
||||
Labels: map[string]string{"organization_id": orgID},
|
||||
},
|
||||
}}
|
||||
var got []*logging.Entry
|
||||
ok := waitFor(func() bool {
|
||||
got, err = allEntries(ctx, a, fmt.Sprintf(`logName = "%s/logs/%s"`, parent,
|
||||
strings.Replace(testLogID, "/", "%2F", -1)))
|
||||
if err != nil {
|
||||
t.Log("fetching log entries: ", err)
|
||||
return false
|
||||
}
|
||||
return len(got) == len(want)
|
||||
})
|
||||
if !ok {
|
||||
t.Fatalf("timed out; got: %d, want: %d\n", len(got), len(want))
|
||||
}
|
||||
if msg, ok := compareEntries(got, want); !ok {
|
||||
t.Error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// waitFor calls f repeatedly with exponential backoff, blocking until it returns true.
|
||||
// It returns false after a while (if it times out).
|
||||
func waitFor(f func() bool) bool {
|
||||
|
||||
+57
-1
@@ -34,7 +34,7 @@ import (
|
||||
|
||||
func TestLoggerCreation(t *testing.T) {
|
||||
const logID = "testing"
|
||||
c := &Client{projectID: "PROJECT_ID"}
|
||||
c := &Client{parent: "projects/PROJECT_ID"}
|
||||
customResource := &mrpb.MonitoredResource{
|
||||
Type: "global",
|
||||
Labels: map[string]string{
|
||||
@@ -223,6 +223,62 @@ func TestFromHTTPRequest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMonitoredResource(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
parent string
|
||||
want *mrpb.MonitoredResource
|
||||
}{
|
||||
{
|
||||
"projects/P",
|
||||
&mrpb.MonitoredResource{
|
||||
Type: "project",
|
||||
Labels: map[string]string{"project_id": "P"},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"folders/F",
|
||||
&mrpb.MonitoredResource{
|
||||
Type: "folder",
|
||||
Labels: map[string]string{"folder_id": "F"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"billingAccounts/B",
|
||||
&mrpb.MonitoredResource{
|
||||
Type: "billing_account",
|
||||
Labels: map[string]string{"account_id": "B"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"organizations/123",
|
||||
&mrpb.MonitoredResource{
|
||||
Type: "organization",
|
||||
Labels: map[string]string{"organization_id": "123"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"unknown/X",
|
||||
&mrpb.MonitoredResource{
|
||||
Type: "global",
|
||||
Labels: map[string]string{"project_id": "X"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"whatever",
|
||||
&mrpb.MonitoredResource{
|
||||
Type: "global",
|
||||
Labels: map[string]string{"project_id": "whatever"},
|
||||
},
|
||||
},
|
||||
} {
|
||||
got := monitoredResource(test.parent)
|
||||
if !testutil.Equal(got, test.want) {
|
||||
t.Errorf("%q: got %+v, want %+v", test.parent, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Used by the tests in logging_test.
|
||||
func SetNow(f func() time.Time) {
|
||||
now = f
|
||||
|
||||
Reference in New Issue
Block a user