...

Source file src/cloud.google.com/go/monitoring/apiv3/v2/metric_client_example_test.go

Documentation: cloud.google.com/go/monitoring/apiv3/v2

     1  // Copyright 2024 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package monitoring_test
    18  
    19  import (
    20  	"context"
    21  
    22  	monitoring "cloud.google.com/go/monitoring/apiv3/v2"
    23  	monitoringpb "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb"
    24  	"google.golang.org/api/iterator"
    25  )
    26  
    27  func ExampleNewMetricClient() {
    28  	ctx := context.Background()
    29  	// This snippet has been automatically generated and should be regarded as a code template only.
    30  	// It will require modifications to work:
    31  	// - It may require correct/in-range values for request initialization.
    32  	// - It may require specifying regional endpoints when creating the service client as shown in:
    33  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    34  	c, err := monitoring.NewMetricClient(ctx)
    35  	if err != nil {
    36  		// TODO: Handle error.
    37  	}
    38  	defer c.Close()
    39  
    40  	// TODO: Use client.
    41  	_ = c
    42  }
    43  
    44  func ExampleMetricClient_CreateMetricDescriptor() {
    45  	ctx := context.Background()
    46  	// This snippet has been automatically generated and should be regarded as a code template only.
    47  	// It will require modifications to work:
    48  	// - It may require correct/in-range values for request initialization.
    49  	// - It may require specifying regional endpoints when creating the service client as shown in:
    50  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    51  	c, err := monitoring.NewMetricClient(ctx)
    52  	if err != nil {
    53  		// TODO: Handle error.
    54  	}
    55  	defer c.Close()
    56  
    57  	req := &monitoringpb.CreateMetricDescriptorRequest{
    58  		// TODO: Fill request struct fields.
    59  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateMetricDescriptorRequest.
    60  	}
    61  	resp, err := c.CreateMetricDescriptor(ctx, req)
    62  	if err != nil {
    63  		// TODO: Handle error.
    64  	}
    65  	// TODO: Use resp.
    66  	_ = resp
    67  }
    68  
    69  func ExampleMetricClient_CreateServiceTimeSeries() {
    70  	ctx := context.Background()
    71  	// This snippet has been automatically generated and should be regarded as a code template only.
    72  	// It will require modifications to work:
    73  	// - It may require correct/in-range values for request initialization.
    74  	// - It may require specifying regional endpoints when creating the service client as shown in:
    75  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    76  	c, err := monitoring.NewMetricClient(ctx)
    77  	if err != nil {
    78  		// TODO: Handle error.
    79  	}
    80  	defer c.Close()
    81  
    82  	req := &monitoringpb.CreateTimeSeriesRequest{
    83  		// TODO: Fill request struct fields.
    84  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateTimeSeriesRequest.
    85  	}
    86  	err = c.CreateServiceTimeSeries(ctx, req)
    87  	if err != nil {
    88  		// TODO: Handle error.
    89  	}
    90  }
    91  
    92  func ExampleMetricClient_CreateTimeSeries() {
    93  	ctx := context.Background()
    94  	// This snippet has been automatically generated and should be regarded as a code template only.
    95  	// It will require modifications to work:
    96  	// - It may require correct/in-range values for request initialization.
    97  	// - It may require specifying regional endpoints when creating the service client as shown in:
    98  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    99  	c, err := monitoring.NewMetricClient(ctx)
   100  	if err != nil {
   101  		// TODO: Handle error.
   102  	}
   103  	defer c.Close()
   104  
   105  	req := &monitoringpb.CreateTimeSeriesRequest{
   106  		// TODO: Fill request struct fields.
   107  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#CreateTimeSeriesRequest.
   108  	}
   109  	err = c.CreateTimeSeries(ctx, req)
   110  	if err != nil {
   111  		// TODO: Handle error.
   112  	}
   113  }
   114  
   115  func ExampleMetricClient_DeleteMetricDescriptor() {
   116  	ctx := context.Background()
   117  	// This snippet has been automatically generated and should be regarded as a code template only.
   118  	// It will require modifications to work:
   119  	// - It may require correct/in-range values for request initialization.
   120  	// - It may require specifying regional endpoints when creating the service client as shown in:
   121  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   122  	c, err := monitoring.NewMetricClient(ctx)
   123  	if err != nil {
   124  		// TODO: Handle error.
   125  	}
   126  	defer c.Close()
   127  
   128  	req := &monitoringpb.DeleteMetricDescriptorRequest{
   129  		// TODO: Fill request struct fields.
   130  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#DeleteMetricDescriptorRequest.
   131  	}
   132  	err = c.DeleteMetricDescriptor(ctx, req)
   133  	if err != nil {
   134  		// TODO: Handle error.
   135  	}
   136  }
   137  
   138  func ExampleMetricClient_GetMetricDescriptor() {
   139  	ctx := context.Background()
   140  	// This snippet has been automatically generated and should be regarded as a code template only.
   141  	// It will require modifications to work:
   142  	// - It may require correct/in-range values for request initialization.
   143  	// - It may require specifying regional endpoints when creating the service client as shown in:
   144  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   145  	c, err := monitoring.NewMetricClient(ctx)
   146  	if err != nil {
   147  		// TODO: Handle error.
   148  	}
   149  	defer c.Close()
   150  
   151  	req := &monitoringpb.GetMetricDescriptorRequest{
   152  		// TODO: Fill request struct fields.
   153  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#GetMetricDescriptorRequest.
   154  	}
   155  	resp, err := c.GetMetricDescriptor(ctx, req)
   156  	if err != nil {
   157  		// TODO: Handle error.
   158  	}
   159  	// TODO: Use resp.
   160  	_ = resp
   161  }
   162  
   163  func ExampleMetricClient_GetMonitoredResourceDescriptor() {
   164  	ctx := context.Background()
   165  	// This snippet has been automatically generated and should be regarded as a code template only.
   166  	// It will require modifications to work:
   167  	// - It may require correct/in-range values for request initialization.
   168  	// - It may require specifying regional endpoints when creating the service client as shown in:
   169  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   170  	c, err := monitoring.NewMetricClient(ctx)
   171  	if err != nil {
   172  		// TODO: Handle error.
   173  	}
   174  	defer c.Close()
   175  
   176  	req := &monitoringpb.GetMonitoredResourceDescriptorRequest{
   177  		// TODO: Fill request struct fields.
   178  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#GetMonitoredResourceDescriptorRequest.
   179  	}
   180  	resp, err := c.GetMonitoredResourceDescriptor(ctx, req)
   181  	if err != nil {
   182  		// TODO: Handle error.
   183  	}
   184  	// TODO: Use resp.
   185  	_ = resp
   186  }
   187  
   188  func ExampleMetricClient_ListMetricDescriptors() {
   189  	ctx := context.Background()
   190  	// This snippet has been automatically generated and should be regarded as a code template only.
   191  	// It will require modifications to work:
   192  	// - It may require correct/in-range values for request initialization.
   193  	// - It may require specifying regional endpoints when creating the service client as shown in:
   194  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   195  	c, err := monitoring.NewMetricClient(ctx)
   196  	if err != nil {
   197  		// TODO: Handle error.
   198  	}
   199  	defer c.Close()
   200  
   201  	req := &monitoringpb.ListMetricDescriptorsRequest{
   202  		// TODO: Fill request struct fields.
   203  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListMetricDescriptorsRequest.
   204  	}
   205  	it := c.ListMetricDescriptors(ctx, req)
   206  	for {
   207  		resp, err := it.Next()
   208  		if err == iterator.Done {
   209  			break
   210  		}
   211  		if err != nil {
   212  			// TODO: Handle error.
   213  		}
   214  		// TODO: Use resp.
   215  		_ = resp
   216  
   217  		// If you need to access the underlying RPC response,
   218  		// you can do so by casting the `Response` as below.
   219  		// Otherwise, remove this line. Only populated after
   220  		// first call to Next(). Not safe for concurrent access.
   221  		_ = it.Response.(*monitoringpb.ListMetricDescriptorsResponse)
   222  	}
   223  }
   224  
   225  func ExampleMetricClient_ListMonitoredResourceDescriptors() {
   226  	ctx := context.Background()
   227  	// This snippet has been automatically generated and should be regarded as a code template only.
   228  	// It will require modifications to work:
   229  	// - It may require correct/in-range values for request initialization.
   230  	// - It may require specifying regional endpoints when creating the service client as shown in:
   231  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   232  	c, err := monitoring.NewMetricClient(ctx)
   233  	if err != nil {
   234  		// TODO: Handle error.
   235  	}
   236  	defer c.Close()
   237  
   238  	req := &monitoringpb.ListMonitoredResourceDescriptorsRequest{
   239  		// TODO: Fill request struct fields.
   240  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListMonitoredResourceDescriptorsRequest.
   241  	}
   242  	it := c.ListMonitoredResourceDescriptors(ctx, req)
   243  	for {
   244  		resp, err := it.Next()
   245  		if err == iterator.Done {
   246  			break
   247  		}
   248  		if err != nil {
   249  			// TODO: Handle error.
   250  		}
   251  		// TODO: Use resp.
   252  		_ = resp
   253  
   254  		// If you need to access the underlying RPC response,
   255  		// you can do so by casting the `Response` as below.
   256  		// Otherwise, remove this line. Only populated after
   257  		// first call to Next(). Not safe for concurrent access.
   258  		_ = it.Response.(*monitoringpb.ListMonitoredResourceDescriptorsResponse)
   259  	}
   260  }
   261  
   262  func ExampleMetricClient_ListTimeSeries() {
   263  	ctx := context.Background()
   264  	// This snippet has been automatically generated and should be regarded as a code template only.
   265  	// It will require modifications to work:
   266  	// - It may require correct/in-range values for request initialization.
   267  	// - It may require specifying regional endpoints when creating the service client as shown in:
   268  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   269  	c, err := monitoring.NewMetricClient(ctx)
   270  	if err != nil {
   271  		// TODO: Handle error.
   272  	}
   273  	defer c.Close()
   274  
   275  	req := &monitoringpb.ListTimeSeriesRequest{
   276  		// TODO: Fill request struct fields.
   277  		// See https://pkg.go.dev/cloud.google.com/go/monitoring/apiv3/v2/monitoringpb#ListTimeSeriesRequest.
   278  	}
   279  	it := c.ListTimeSeries(ctx, req)
   280  	for {
   281  		resp, err := it.Next()
   282  		if err == iterator.Done {
   283  			break
   284  		}
   285  		if err != nil {
   286  			// TODO: Handle error.
   287  		}
   288  		// TODO: Use resp.
   289  		_ = resp
   290  
   291  		// If you need to access the underlying RPC response,
   292  		// you can do so by casting the `Response` as below.
   293  		// Otherwise, remove this line. Only populated after
   294  		// first call to Next(). Not safe for concurrent access.
   295  		_ = it.Response.(*monitoringpb.ListTimeSeriesResponse)
   296  	}
   297  }
   298  

View as plain text