cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/model_monitoring_client.go (about)

     1  // Copyright 2025 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 aiplatform
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"log/slog"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  
    28  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb"
    29  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    30  	"cloud.google.com/go/longrunning"
    31  	lroauto "cloud.google.com/go/longrunning/autogen"
    32  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    33  	gax "github.com/googleapis/gax-go/v2"
    34  	"google.golang.org/api/iterator"
    35  	"google.golang.org/api/option"
    36  	"google.golang.org/api/option/internaloption"
    37  	gtransport "google.golang.org/api/transport/grpc"
    38  	httptransport "google.golang.org/api/transport/http"
    39  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    40  	"google.golang.org/grpc"
    41  	"google.golang.org/protobuf/encoding/protojson"
    42  	"google.golang.org/protobuf/proto"
    43  )
    44  
    45  var newModelMonitoringClientHook clientHook
    46  
    47  // ModelMonitoringCallOptions contains the retry settings for each method of ModelMonitoringClient.
    48  type ModelMonitoringCallOptions struct {
    49  	CreateModelMonitor          []gax.CallOption
    50  	UpdateModelMonitor          []gax.CallOption
    51  	GetModelMonitor             []gax.CallOption
    52  	ListModelMonitors           []gax.CallOption
    53  	DeleteModelMonitor          []gax.CallOption
    54  	CreateModelMonitoringJob    []gax.CallOption
    55  	GetModelMonitoringJob       []gax.CallOption
    56  	ListModelMonitoringJobs     []gax.CallOption
    57  	DeleteModelMonitoringJob    []gax.CallOption
    58  	SearchModelMonitoringStats  []gax.CallOption
    59  	SearchModelMonitoringAlerts []gax.CallOption
    60  	GetLocation                 []gax.CallOption
    61  	ListLocations               []gax.CallOption
    62  	GetIamPolicy                []gax.CallOption
    63  	SetIamPolicy                []gax.CallOption
    64  	TestIamPermissions          []gax.CallOption
    65  	CancelOperation             []gax.CallOption
    66  	DeleteOperation             []gax.CallOption
    67  	GetOperation                []gax.CallOption
    68  	ListOperations              []gax.CallOption
    69  	WaitOperation               []gax.CallOption
    70  }
    71  
    72  func defaultModelMonitoringGRPCClientOptions() []option.ClientOption {
    73  	return []option.ClientOption{
    74  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    75  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    76  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    77  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    78  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    79  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    80  		internaloption.EnableJwtWithScope(),
    81  		internaloption.EnableNewAuthLibrary(),
    82  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    83  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    84  	}
    85  }
    86  
    87  func defaultModelMonitoringCallOptions() *ModelMonitoringCallOptions {
    88  	return &ModelMonitoringCallOptions{
    89  		CreateModelMonitor:          []gax.CallOption{},
    90  		UpdateModelMonitor:          []gax.CallOption{},
    91  		GetModelMonitor:             []gax.CallOption{},
    92  		ListModelMonitors:           []gax.CallOption{},
    93  		DeleteModelMonitor:          []gax.CallOption{},
    94  		CreateModelMonitoringJob:    []gax.CallOption{},
    95  		GetModelMonitoringJob:       []gax.CallOption{},
    96  		ListModelMonitoringJobs:     []gax.CallOption{},
    97  		DeleteModelMonitoringJob:    []gax.CallOption{},
    98  		SearchModelMonitoringStats:  []gax.CallOption{},
    99  		SearchModelMonitoringAlerts: []gax.CallOption{},
   100  		GetLocation:                 []gax.CallOption{},
   101  		ListLocations:               []gax.CallOption{},
   102  		GetIamPolicy:                []gax.CallOption{},
   103  		SetIamPolicy:                []gax.CallOption{},
   104  		TestIamPermissions:          []gax.CallOption{},
   105  		CancelOperation:             []gax.CallOption{},
   106  		DeleteOperation:             []gax.CallOption{},
   107  		GetOperation:                []gax.CallOption{},
   108  		ListOperations:              []gax.CallOption{},
   109  		WaitOperation:               []gax.CallOption{},
   110  	}
   111  }
   112  
   113  func defaultModelMonitoringRESTCallOptions() *ModelMonitoringCallOptions {
   114  	return &ModelMonitoringCallOptions{
   115  		CreateModelMonitor:          []gax.CallOption{},
   116  		UpdateModelMonitor:          []gax.CallOption{},
   117  		GetModelMonitor:             []gax.CallOption{},
   118  		ListModelMonitors:           []gax.CallOption{},
   119  		DeleteModelMonitor:          []gax.CallOption{},
   120  		CreateModelMonitoringJob:    []gax.CallOption{},
   121  		GetModelMonitoringJob:       []gax.CallOption{},
   122  		ListModelMonitoringJobs:     []gax.CallOption{},
   123  		DeleteModelMonitoringJob:    []gax.CallOption{},
   124  		SearchModelMonitoringStats:  []gax.CallOption{},
   125  		SearchModelMonitoringAlerts: []gax.CallOption{},
   126  		GetLocation:                 []gax.CallOption{},
   127  		ListLocations:               []gax.CallOption{},
   128  		GetIamPolicy:                []gax.CallOption{},
   129  		SetIamPolicy:                []gax.CallOption{},
   130  		TestIamPermissions:          []gax.CallOption{},
   131  		CancelOperation:             []gax.CallOption{},
   132  		DeleteOperation:             []gax.CallOption{},
   133  		GetOperation:                []gax.CallOption{},
   134  		ListOperations:              []gax.CallOption{},
   135  		WaitOperation:               []gax.CallOption{},
   136  	}
   137  }
   138  
   139  // internalModelMonitoringClient is an interface that defines the methods available from Vertex AI API.
   140  type internalModelMonitoringClient interface {
   141  	Close() error
   142  	setGoogleClientInfo(...string)
   143  	Connection() *grpc.ClientConn
   144  	CreateModelMonitor(context.Context, *aiplatformpb.CreateModelMonitorRequest, ...gax.CallOption) (*CreateModelMonitorOperation, error)
   145  	CreateModelMonitorOperation(name string) *CreateModelMonitorOperation
   146  	UpdateModelMonitor(context.Context, *aiplatformpb.UpdateModelMonitorRequest, ...gax.CallOption) (*UpdateModelMonitorOperation, error)
   147  	UpdateModelMonitorOperation(name string) *UpdateModelMonitorOperation
   148  	GetModelMonitor(context.Context, *aiplatformpb.GetModelMonitorRequest, ...gax.CallOption) (*aiplatformpb.ModelMonitor, error)
   149  	ListModelMonitors(context.Context, *aiplatformpb.ListModelMonitorsRequest, ...gax.CallOption) *ModelMonitorIterator
   150  	DeleteModelMonitor(context.Context, *aiplatformpb.DeleteModelMonitorRequest, ...gax.CallOption) (*DeleteModelMonitorOperation, error)
   151  	DeleteModelMonitorOperation(name string) *DeleteModelMonitorOperation
   152  	CreateModelMonitoringJob(context.Context, *aiplatformpb.CreateModelMonitoringJobRequest, ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error)
   153  	GetModelMonitoringJob(context.Context, *aiplatformpb.GetModelMonitoringJobRequest, ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error)
   154  	ListModelMonitoringJobs(context.Context, *aiplatformpb.ListModelMonitoringJobsRequest, ...gax.CallOption) *ModelMonitoringJobIterator
   155  	DeleteModelMonitoringJob(context.Context, *aiplatformpb.DeleteModelMonitoringJobRequest, ...gax.CallOption) (*DeleteModelMonitoringJobOperation, error)
   156  	DeleteModelMonitoringJobOperation(name string) *DeleteModelMonitoringJobOperation
   157  	SearchModelMonitoringStats(context.Context, *aiplatformpb.SearchModelMonitoringStatsRequest, ...gax.CallOption) *ModelMonitoringStatsIterator
   158  	SearchModelMonitoringAlerts(context.Context, *aiplatformpb.SearchModelMonitoringAlertsRequest, ...gax.CallOption) *ModelMonitoringAlertIterator
   159  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   160  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   161  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   162  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   163  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   164  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   165  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   166  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   167  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   168  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   169  }
   170  
   171  // ModelMonitoringClient is a client for interacting with Vertex AI API.
   172  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   173  //
   174  // A service for creating and managing Vertex AI Model moitoring. This includes
   175  // ModelMonitor resources, ModelMonitoringJob resources.
   176  type ModelMonitoringClient struct {
   177  	// The internal transport-dependent client.
   178  	internalClient internalModelMonitoringClient
   179  
   180  	// The call options for this service.
   181  	CallOptions *ModelMonitoringCallOptions
   182  
   183  	// LROClient is used internally to handle long-running operations.
   184  	// It is exposed so that its CallOptions can be modified if required.
   185  	// Users should not Close this client.
   186  	LROClient *lroauto.OperationsClient
   187  }
   188  
   189  // Wrapper methods routed to the internal client.
   190  
   191  // Close closes the connection to the API service. The user should invoke this when
   192  // the client is no longer required.
   193  func (c *ModelMonitoringClient) Close() error {
   194  	return c.internalClient.Close()
   195  }
   196  
   197  // setGoogleClientInfo sets the name and version of the application in
   198  // the `x-goog-api-client` header passed on each request. Intended for
   199  // use by Google-written clients.
   200  func (c *ModelMonitoringClient) setGoogleClientInfo(keyval ...string) {
   201  	c.internalClient.setGoogleClientInfo(keyval...)
   202  }
   203  
   204  // Connection returns a connection to the API service.
   205  //
   206  // Deprecated: Connections are now pooled so this method does not always
   207  // return the same resource.
   208  func (c *ModelMonitoringClient) Connection() *grpc.ClientConn {
   209  	return c.internalClient.Connection()
   210  }
   211  
   212  // CreateModelMonitor creates a ModelMonitor.
   213  func (c *ModelMonitoringClient) CreateModelMonitor(ctx context.Context, req *aiplatformpb.CreateModelMonitorRequest, opts ...gax.CallOption) (*CreateModelMonitorOperation, error) {
   214  	return c.internalClient.CreateModelMonitor(ctx, req, opts...)
   215  }
   216  
   217  // CreateModelMonitorOperation returns a new CreateModelMonitorOperation from a given name.
   218  // The name must be that of a previously created CreateModelMonitorOperation, possibly from a different process.
   219  func (c *ModelMonitoringClient) CreateModelMonitorOperation(name string) *CreateModelMonitorOperation {
   220  	return c.internalClient.CreateModelMonitorOperation(name)
   221  }
   222  
   223  // UpdateModelMonitor updates a ModelMonitor.
   224  func (c *ModelMonitoringClient) UpdateModelMonitor(ctx context.Context, req *aiplatformpb.UpdateModelMonitorRequest, opts ...gax.CallOption) (*UpdateModelMonitorOperation, error) {
   225  	return c.internalClient.UpdateModelMonitor(ctx, req, opts...)
   226  }
   227  
   228  // UpdateModelMonitorOperation returns a new UpdateModelMonitorOperation from a given name.
   229  // The name must be that of a previously created UpdateModelMonitorOperation, possibly from a different process.
   230  func (c *ModelMonitoringClient) UpdateModelMonitorOperation(name string) *UpdateModelMonitorOperation {
   231  	return c.internalClient.UpdateModelMonitorOperation(name)
   232  }
   233  
   234  // GetModelMonitor gets a ModelMonitor.
   235  func (c *ModelMonitoringClient) GetModelMonitor(ctx context.Context, req *aiplatformpb.GetModelMonitorRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitor, error) {
   236  	return c.internalClient.GetModelMonitor(ctx, req, opts...)
   237  }
   238  
   239  // ListModelMonitors lists ModelMonitors in a Location.
   240  func (c *ModelMonitoringClient) ListModelMonitors(ctx context.Context, req *aiplatformpb.ListModelMonitorsRequest, opts ...gax.CallOption) *ModelMonitorIterator {
   241  	return c.internalClient.ListModelMonitors(ctx, req, opts...)
   242  }
   243  
   244  // DeleteModelMonitor deletes a ModelMonitor.
   245  func (c *ModelMonitoringClient) DeleteModelMonitor(ctx context.Context, req *aiplatformpb.DeleteModelMonitorRequest, opts ...gax.CallOption) (*DeleteModelMonitorOperation, error) {
   246  	return c.internalClient.DeleteModelMonitor(ctx, req, opts...)
   247  }
   248  
   249  // DeleteModelMonitorOperation returns a new DeleteModelMonitorOperation from a given name.
   250  // The name must be that of a previously created DeleteModelMonitorOperation, possibly from a different process.
   251  func (c *ModelMonitoringClient) DeleteModelMonitorOperation(name string) *DeleteModelMonitorOperation {
   252  	return c.internalClient.DeleteModelMonitorOperation(name)
   253  }
   254  
   255  // CreateModelMonitoringJob creates a ModelMonitoringJob.
   256  func (c *ModelMonitoringClient) CreateModelMonitoringJob(ctx context.Context, req *aiplatformpb.CreateModelMonitoringJobRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error) {
   257  	return c.internalClient.CreateModelMonitoringJob(ctx, req, opts...)
   258  }
   259  
   260  // GetModelMonitoringJob gets a ModelMonitoringJob.
   261  func (c *ModelMonitoringClient) GetModelMonitoringJob(ctx context.Context, req *aiplatformpb.GetModelMonitoringJobRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error) {
   262  	return c.internalClient.GetModelMonitoringJob(ctx, req, opts...)
   263  }
   264  
   265  // ListModelMonitoringJobs lists ModelMonitoringJobs.
   266  // Callers may choose to read across multiple Monitors as per
   267  // AIP-159 (at https://google.aip.dev/159) by using ‘-’ (the hyphen or dash
   268  // character) as a wildcard character instead of modelMonitor id in the
   269  // parent. Format
   270  // projects/{project_id}/locations/{location}/moodelMonitors/-/modelMonitoringJobs
   271  func (c *ModelMonitoringClient) ListModelMonitoringJobs(ctx context.Context, req *aiplatformpb.ListModelMonitoringJobsRequest, opts ...gax.CallOption) *ModelMonitoringJobIterator {
   272  	return c.internalClient.ListModelMonitoringJobs(ctx, req, opts...)
   273  }
   274  
   275  // DeleteModelMonitoringJob deletes a ModelMonitoringJob.
   276  func (c *ModelMonitoringClient) DeleteModelMonitoringJob(ctx context.Context, req *aiplatformpb.DeleteModelMonitoringJobRequest, opts ...gax.CallOption) (*DeleteModelMonitoringJobOperation, error) {
   277  	return c.internalClient.DeleteModelMonitoringJob(ctx, req, opts...)
   278  }
   279  
   280  // DeleteModelMonitoringJobOperation returns a new DeleteModelMonitoringJobOperation from a given name.
   281  // The name must be that of a previously created DeleteModelMonitoringJobOperation, possibly from a different process.
   282  func (c *ModelMonitoringClient) DeleteModelMonitoringJobOperation(name string) *DeleteModelMonitoringJobOperation {
   283  	return c.internalClient.DeleteModelMonitoringJobOperation(name)
   284  }
   285  
   286  // SearchModelMonitoringStats searches Model Monitoring Stats generated within a given time window.
   287  func (c *ModelMonitoringClient) SearchModelMonitoringStats(ctx context.Context, req *aiplatformpb.SearchModelMonitoringStatsRequest, opts ...gax.CallOption) *ModelMonitoringStatsIterator {
   288  	return c.internalClient.SearchModelMonitoringStats(ctx, req, opts...)
   289  }
   290  
   291  // SearchModelMonitoringAlerts returns the Model Monitoring alerts.
   292  func (c *ModelMonitoringClient) SearchModelMonitoringAlerts(ctx context.Context, req *aiplatformpb.SearchModelMonitoringAlertsRequest, opts ...gax.CallOption) *ModelMonitoringAlertIterator {
   293  	return c.internalClient.SearchModelMonitoringAlerts(ctx, req, opts...)
   294  }
   295  
   296  // GetLocation gets information about a location.
   297  func (c *ModelMonitoringClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   298  	return c.internalClient.GetLocation(ctx, req, opts...)
   299  }
   300  
   301  // ListLocations lists information about the supported locations for this service.
   302  func (c *ModelMonitoringClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   303  	return c.internalClient.ListLocations(ctx, req, opts...)
   304  }
   305  
   306  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   307  // if the resource exists and does not have a policy set.
   308  func (c *ModelMonitoringClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   309  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   310  }
   311  
   312  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   313  // any existing policy.
   314  //
   315  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   316  // errors.
   317  func (c *ModelMonitoringClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   318  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   319  }
   320  
   321  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   322  // resource does not exist, this will return an empty set of
   323  // permissions, not a NOT_FOUND error.
   324  //
   325  // Note: This operation is designed to be used for building
   326  // permission-aware UIs and command-line tools, not for authorization
   327  // checking. This operation may “fail open” without warning.
   328  func (c *ModelMonitoringClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   329  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   330  }
   331  
   332  // CancelOperation is a utility method from google.longrunning.Operations.
   333  func (c *ModelMonitoringClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   334  	return c.internalClient.CancelOperation(ctx, req, opts...)
   335  }
   336  
   337  // DeleteOperation is a utility method from google.longrunning.Operations.
   338  func (c *ModelMonitoringClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   339  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   340  }
   341  
   342  // GetOperation is a utility method from google.longrunning.Operations.
   343  func (c *ModelMonitoringClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   344  	return c.internalClient.GetOperation(ctx, req, opts...)
   345  }
   346  
   347  // ListOperations is a utility method from google.longrunning.Operations.
   348  func (c *ModelMonitoringClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   349  	return c.internalClient.ListOperations(ctx, req, opts...)
   350  }
   351  
   352  // WaitOperation is a utility method from google.longrunning.Operations.
   353  func (c *ModelMonitoringClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   354  	return c.internalClient.WaitOperation(ctx, req, opts...)
   355  }
   356  
   357  // modelMonitoringGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   358  //
   359  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   360  type modelMonitoringGRPCClient struct {
   361  	// Connection pool of gRPC connections to the service.
   362  	connPool gtransport.ConnPool
   363  
   364  	// Points back to the CallOptions field of the containing ModelMonitoringClient
   365  	CallOptions **ModelMonitoringCallOptions
   366  
   367  	// The gRPC API client.
   368  	modelMonitoringClient aiplatformpb.ModelMonitoringServiceClient
   369  
   370  	// LROClient is used internally to handle long-running operations.
   371  	// It is exposed so that its CallOptions can be modified if required.
   372  	// Users should not Close this client.
   373  	LROClient **lroauto.OperationsClient
   374  
   375  	operationsClient longrunningpb.OperationsClient
   376  
   377  	iamPolicyClient iampb.IAMPolicyClient
   378  
   379  	locationsClient locationpb.LocationsClient
   380  
   381  	// The x-goog-* metadata to be sent with each request.
   382  	xGoogHeaders []string
   383  
   384  	logger *slog.Logger
   385  }
   386  
   387  // NewModelMonitoringClient creates a new model monitoring service client based on gRPC.
   388  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   389  //
   390  // A service for creating and managing Vertex AI Model moitoring. This includes
   391  // ModelMonitor resources, ModelMonitoringJob resources.
   392  func NewModelMonitoringClient(ctx context.Context, opts ...option.ClientOption) (*ModelMonitoringClient, error) {
   393  	clientOpts := defaultModelMonitoringGRPCClientOptions()
   394  	if newModelMonitoringClientHook != nil {
   395  		hookOpts, err := newModelMonitoringClientHook(ctx, clientHookParams{})
   396  		if err != nil {
   397  			return nil, err
   398  		}
   399  		clientOpts = append(clientOpts, hookOpts...)
   400  	}
   401  
   402  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   403  	if err != nil {
   404  		return nil, err
   405  	}
   406  	client := ModelMonitoringClient{CallOptions: defaultModelMonitoringCallOptions()}
   407  
   408  	c := &modelMonitoringGRPCClient{
   409  		connPool:              connPool,
   410  		modelMonitoringClient: aiplatformpb.NewModelMonitoringServiceClient(connPool),
   411  		CallOptions:           &client.CallOptions,
   412  		logger:                internaloption.GetLogger(opts),
   413  		operationsClient:      longrunningpb.NewOperationsClient(connPool),
   414  		iamPolicyClient:       iampb.NewIAMPolicyClient(connPool),
   415  		locationsClient:       locationpb.NewLocationsClient(connPool),
   416  	}
   417  	c.setGoogleClientInfo()
   418  
   419  	client.internalClient = c
   420  
   421  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   422  	if err != nil {
   423  		// This error "should not happen", since we are just reusing old connection pool
   424  		// and never actually need to dial.
   425  		// If this does happen, we could leak connp. However, we cannot close conn:
   426  		// If the user invoked the constructor with option.WithGRPCConn,
   427  		// we would close a connection that's still in use.
   428  		// TODO: investigate error conditions.
   429  		return nil, err
   430  	}
   431  	c.LROClient = &client.LROClient
   432  	return &client, nil
   433  }
   434  
   435  // Connection returns a connection to the API service.
   436  //
   437  // Deprecated: Connections are now pooled so this method does not always
   438  // return the same resource.
   439  func (c *modelMonitoringGRPCClient) Connection() *grpc.ClientConn {
   440  	return c.connPool.Conn()
   441  }
   442  
   443  // setGoogleClientInfo sets the name and version of the application in
   444  // the `x-goog-api-client` header passed on each request. Intended for
   445  // use by Google-written clients.
   446  func (c *modelMonitoringGRPCClient) setGoogleClientInfo(keyval ...string) {
   447  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   448  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   449  	c.xGoogHeaders = []string{
   450  		"x-goog-api-client", gax.XGoogHeader(kv...),
   451  	}
   452  }
   453  
   454  // Close closes the connection to the API service. The user should invoke this when
   455  // the client is no longer required.
   456  func (c *modelMonitoringGRPCClient) Close() error {
   457  	return c.connPool.Close()
   458  }
   459  
   460  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   461  type modelMonitoringRESTClient struct {
   462  	// The http endpoint to connect to.
   463  	endpoint string
   464  
   465  	// The http client.
   466  	httpClient *http.Client
   467  
   468  	// LROClient is used internally to handle long-running operations.
   469  	// It is exposed so that its CallOptions can be modified if required.
   470  	// Users should not Close this client.
   471  	LROClient **lroauto.OperationsClient
   472  
   473  	// The x-goog-* headers to be sent with each request.
   474  	xGoogHeaders []string
   475  
   476  	// Points back to the CallOptions field of the containing ModelMonitoringClient
   477  	CallOptions **ModelMonitoringCallOptions
   478  
   479  	logger *slog.Logger
   480  }
   481  
   482  // NewModelMonitoringRESTClient creates a new model monitoring service rest client.
   483  //
   484  // A service for creating and managing Vertex AI Model moitoring. This includes
   485  // ModelMonitor resources, ModelMonitoringJob resources.
   486  func NewModelMonitoringRESTClient(ctx context.Context, opts ...option.ClientOption) (*ModelMonitoringClient, error) {
   487  	clientOpts := append(defaultModelMonitoringRESTClientOptions(), opts...)
   488  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   489  	if err != nil {
   490  		return nil, err
   491  	}
   492  
   493  	callOpts := defaultModelMonitoringRESTCallOptions()
   494  	c := &modelMonitoringRESTClient{
   495  		endpoint:    endpoint,
   496  		httpClient:  httpClient,
   497  		CallOptions: &callOpts,
   498  		logger:      internaloption.GetLogger(opts),
   499  	}
   500  	c.setGoogleClientInfo()
   501  
   502  	lroOpts := []option.ClientOption{
   503  		option.WithHTTPClient(httpClient),
   504  		option.WithEndpoint(endpoint),
   505  	}
   506  	opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
   507  	if err != nil {
   508  		return nil, err
   509  	}
   510  	c.LROClient = &opClient
   511  
   512  	return &ModelMonitoringClient{internalClient: c, CallOptions: callOpts}, nil
   513  }
   514  
   515  func defaultModelMonitoringRESTClientOptions() []option.ClientOption {
   516  	return []option.ClientOption{
   517  		internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"),
   518  		internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"),
   519  		internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"),
   520  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   521  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
   522  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   523  		internaloption.EnableNewAuthLibrary(),
   524  	}
   525  }
   526  
   527  // setGoogleClientInfo sets the name and version of the application in
   528  // the `x-goog-api-client` header passed on each request. Intended for
   529  // use by Google-written clients.
   530  func (c *modelMonitoringRESTClient) setGoogleClientInfo(keyval ...string) {
   531  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   532  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
   533  	c.xGoogHeaders = []string{
   534  		"x-goog-api-client", gax.XGoogHeader(kv...),
   535  	}
   536  }
   537  
   538  // Close closes the connection to the API service. The user should invoke this when
   539  // the client is no longer required.
   540  func (c *modelMonitoringRESTClient) Close() error {
   541  	// Replace httpClient with nil to force cleanup.
   542  	c.httpClient = nil
   543  	return nil
   544  }
   545  
   546  // Connection returns a connection to the API service.
   547  //
   548  // Deprecated: This method always returns nil.
   549  func (c *modelMonitoringRESTClient) Connection() *grpc.ClientConn {
   550  	return nil
   551  }
   552  func (c *modelMonitoringGRPCClient) CreateModelMonitor(ctx context.Context, req *aiplatformpb.CreateModelMonitorRequest, opts ...gax.CallOption) (*CreateModelMonitorOperation, error) {
   553  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   554  
   555  	hds = append(c.xGoogHeaders, hds...)
   556  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   557  	opts = append((*c.CallOptions).CreateModelMonitor[0:len((*c.CallOptions).CreateModelMonitor):len((*c.CallOptions).CreateModelMonitor)], opts...)
   558  	var resp *longrunningpb.Operation
   559  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   560  		var err error
   561  		resp, err = executeRPC(ctx, c.modelMonitoringClient.CreateModelMonitor, req, settings.GRPC, c.logger, "CreateModelMonitor")
   562  		return err
   563  	}, opts...)
   564  	if err != nil {
   565  		return nil, err
   566  	}
   567  	return &CreateModelMonitorOperation{
   568  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   569  	}, nil
   570  }
   571  
   572  func (c *modelMonitoringGRPCClient) UpdateModelMonitor(ctx context.Context, req *aiplatformpb.UpdateModelMonitorRequest, opts ...gax.CallOption) (*UpdateModelMonitorOperation, error) {
   573  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "model_monitor.name", url.QueryEscape(req.GetModelMonitor().GetName()))}
   574  
   575  	hds = append(c.xGoogHeaders, hds...)
   576  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   577  	opts = append((*c.CallOptions).UpdateModelMonitor[0:len((*c.CallOptions).UpdateModelMonitor):len((*c.CallOptions).UpdateModelMonitor)], opts...)
   578  	var resp *longrunningpb.Operation
   579  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   580  		var err error
   581  		resp, err = executeRPC(ctx, c.modelMonitoringClient.UpdateModelMonitor, req, settings.GRPC, c.logger, "UpdateModelMonitor")
   582  		return err
   583  	}, opts...)
   584  	if err != nil {
   585  		return nil, err
   586  	}
   587  	return &UpdateModelMonitorOperation{
   588  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   589  	}, nil
   590  }
   591  
   592  func (c *modelMonitoringGRPCClient) GetModelMonitor(ctx context.Context, req *aiplatformpb.GetModelMonitorRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitor, error) {
   593  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   594  
   595  	hds = append(c.xGoogHeaders, hds...)
   596  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   597  	opts = append((*c.CallOptions).GetModelMonitor[0:len((*c.CallOptions).GetModelMonitor):len((*c.CallOptions).GetModelMonitor)], opts...)
   598  	var resp *aiplatformpb.ModelMonitor
   599  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   600  		var err error
   601  		resp, err = executeRPC(ctx, c.modelMonitoringClient.GetModelMonitor, req, settings.GRPC, c.logger, "GetModelMonitor")
   602  		return err
   603  	}, opts...)
   604  	if err != nil {
   605  		return nil, err
   606  	}
   607  	return resp, nil
   608  }
   609  
   610  func (c *modelMonitoringGRPCClient) ListModelMonitors(ctx context.Context, req *aiplatformpb.ListModelMonitorsRequest, opts ...gax.CallOption) *ModelMonitorIterator {
   611  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   612  
   613  	hds = append(c.xGoogHeaders, hds...)
   614  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   615  	opts = append((*c.CallOptions).ListModelMonitors[0:len((*c.CallOptions).ListModelMonitors):len((*c.CallOptions).ListModelMonitors)], opts...)
   616  	it := &ModelMonitorIterator{}
   617  	req = proto.Clone(req).(*aiplatformpb.ListModelMonitorsRequest)
   618  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitor, string, error) {
   619  		resp := &aiplatformpb.ListModelMonitorsResponse{}
   620  		if pageToken != "" {
   621  			req.PageToken = pageToken
   622  		}
   623  		if pageSize > math.MaxInt32 {
   624  			req.PageSize = math.MaxInt32
   625  		} else if pageSize != 0 {
   626  			req.PageSize = int32(pageSize)
   627  		}
   628  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   629  			var err error
   630  			resp, err = executeRPC(ctx, c.modelMonitoringClient.ListModelMonitors, req, settings.GRPC, c.logger, "ListModelMonitors")
   631  			return err
   632  		}, opts...)
   633  		if err != nil {
   634  			return nil, "", err
   635  		}
   636  
   637  		it.Response = resp
   638  		return resp.GetModelMonitors(), resp.GetNextPageToken(), nil
   639  	}
   640  	fetch := func(pageSize int, pageToken string) (string, error) {
   641  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   642  		if err != nil {
   643  			return "", err
   644  		}
   645  		it.items = append(it.items, items...)
   646  		return nextPageToken, nil
   647  	}
   648  
   649  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   650  	it.pageInfo.MaxSize = int(req.GetPageSize())
   651  	it.pageInfo.Token = req.GetPageToken()
   652  
   653  	return it
   654  }
   655  
   656  func (c *modelMonitoringGRPCClient) DeleteModelMonitor(ctx context.Context, req *aiplatformpb.DeleteModelMonitorRequest, opts ...gax.CallOption) (*DeleteModelMonitorOperation, error) {
   657  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   658  
   659  	hds = append(c.xGoogHeaders, hds...)
   660  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   661  	opts = append((*c.CallOptions).DeleteModelMonitor[0:len((*c.CallOptions).DeleteModelMonitor):len((*c.CallOptions).DeleteModelMonitor)], opts...)
   662  	var resp *longrunningpb.Operation
   663  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   664  		var err error
   665  		resp, err = executeRPC(ctx, c.modelMonitoringClient.DeleteModelMonitor, req, settings.GRPC, c.logger, "DeleteModelMonitor")
   666  		return err
   667  	}, opts...)
   668  	if err != nil {
   669  		return nil, err
   670  	}
   671  	return &DeleteModelMonitorOperation{
   672  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   673  	}, nil
   674  }
   675  
   676  func (c *modelMonitoringGRPCClient) CreateModelMonitoringJob(ctx context.Context, req *aiplatformpb.CreateModelMonitoringJobRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error) {
   677  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   678  
   679  	hds = append(c.xGoogHeaders, hds...)
   680  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   681  	opts = append((*c.CallOptions).CreateModelMonitoringJob[0:len((*c.CallOptions).CreateModelMonitoringJob):len((*c.CallOptions).CreateModelMonitoringJob)], opts...)
   682  	var resp *aiplatformpb.ModelMonitoringJob
   683  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   684  		var err error
   685  		resp, err = executeRPC(ctx, c.modelMonitoringClient.CreateModelMonitoringJob, req, settings.GRPC, c.logger, "CreateModelMonitoringJob")
   686  		return err
   687  	}, opts...)
   688  	if err != nil {
   689  		return nil, err
   690  	}
   691  	return resp, nil
   692  }
   693  
   694  func (c *modelMonitoringGRPCClient) GetModelMonitoringJob(ctx context.Context, req *aiplatformpb.GetModelMonitoringJobRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error) {
   695  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   696  
   697  	hds = append(c.xGoogHeaders, hds...)
   698  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   699  	opts = append((*c.CallOptions).GetModelMonitoringJob[0:len((*c.CallOptions).GetModelMonitoringJob):len((*c.CallOptions).GetModelMonitoringJob)], opts...)
   700  	var resp *aiplatformpb.ModelMonitoringJob
   701  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   702  		var err error
   703  		resp, err = executeRPC(ctx, c.modelMonitoringClient.GetModelMonitoringJob, req, settings.GRPC, c.logger, "GetModelMonitoringJob")
   704  		return err
   705  	}, opts...)
   706  	if err != nil {
   707  		return nil, err
   708  	}
   709  	return resp, nil
   710  }
   711  
   712  func (c *modelMonitoringGRPCClient) ListModelMonitoringJobs(ctx context.Context, req *aiplatformpb.ListModelMonitoringJobsRequest, opts ...gax.CallOption) *ModelMonitoringJobIterator {
   713  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   714  
   715  	hds = append(c.xGoogHeaders, hds...)
   716  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   717  	opts = append((*c.CallOptions).ListModelMonitoringJobs[0:len((*c.CallOptions).ListModelMonitoringJobs):len((*c.CallOptions).ListModelMonitoringJobs)], opts...)
   718  	it := &ModelMonitoringJobIterator{}
   719  	req = proto.Clone(req).(*aiplatformpb.ListModelMonitoringJobsRequest)
   720  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitoringJob, string, error) {
   721  		resp := &aiplatformpb.ListModelMonitoringJobsResponse{}
   722  		if pageToken != "" {
   723  			req.PageToken = pageToken
   724  		}
   725  		if pageSize > math.MaxInt32 {
   726  			req.PageSize = math.MaxInt32
   727  		} else if pageSize != 0 {
   728  			req.PageSize = int32(pageSize)
   729  		}
   730  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   731  			var err error
   732  			resp, err = executeRPC(ctx, c.modelMonitoringClient.ListModelMonitoringJobs, req, settings.GRPC, c.logger, "ListModelMonitoringJobs")
   733  			return err
   734  		}, opts...)
   735  		if err != nil {
   736  			return nil, "", err
   737  		}
   738  
   739  		it.Response = resp
   740  		return resp.GetModelMonitoringJobs(), resp.GetNextPageToken(), nil
   741  	}
   742  	fetch := func(pageSize int, pageToken string) (string, error) {
   743  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   744  		if err != nil {
   745  			return "", err
   746  		}
   747  		it.items = append(it.items, items...)
   748  		return nextPageToken, nil
   749  	}
   750  
   751  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   752  	it.pageInfo.MaxSize = int(req.GetPageSize())
   753  	it.pageInfo.Token = req.GetPageToken()
   754  
   755  	return it
   756  }
   757  
   758  func (c *modelMonitoringGRPCClient) DeleteModelMonitoringJob(ctx context.Context, req *aiplatformpb.DeleteModelMonitoringJobRequest, opts ...gax.CallOption) (*DeleteModelMonitoringJobOperation, error) {
   759  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   760  
   761  	hds = append(c.xGoogHeaders, hds...)
   762  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   763  	opts = append((*c.CallOptions).DeleteModelMonitoringJob[0:len((*c.CallOptions).DeleteModelMonitoringJob):len((*c.CallOptions).DeleteModelMonitoringJob)], opts...)
   764  	var resp *longrunningpb.Operation
   765  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   766  		var err error
   767  		resp, err = executeRPC(ctx, c.modelMonitoringClient.DeleteModelMonitoringJob, req, settings.GRPC, c.logger, "DeleteModelMonitoringJob")
   768  		return err
   769  	}, opts...)
   770  	if err != nil {
   771  		return nil, err
   772  	}
   773  	return &DeleteModelMonitoringJobOperation{
   774  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   775  	}, nil
   776  }
   777  
   778  func (c *modelMonitoringGRPCClient) SearchModelMonitoringStats(ctx context.Context, req *aiplatformpb.SearchModelMonitoringStatsRequest, opts ...gax.CallOption) *ModelMonitoringStatsIterator {
   779  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "model_monitor", url.QueryEscape(req.GetModelMonitor()))}
   780  
   781  	hds = append(c.xGoogHeaders, hds...)
   782  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   783  	opts = append((*c.CallOptions).SearchModelMonitoringStats[0:len((*c.CallOptions).SearchModelMonitoringStats):len((*c.CallOptions).SearchModelMonitoringStats)], opts...)
   784  	it := &ModelMonitoringStatsIterator{}
   785  	req = proto.Clone(req).(*aiplatformpb.SearchModelMonitoringStatsRequest)
   786  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitoringStats, string, error) {
   787  		resp := &aiplatformpb.SearchModelMonitoringStatsResponse{}
   788  		if pageToken != "" {
   789  			req.PageToken = pageToken
   790  		}
   791  		if pageSize > math.MaxInt32 {
   792  			req.PageSize = math.MaxInt32
   793  		} else if pageSize != 0 {
   794  			req.PageSize = int32(pageSize)
   795  		}
   796  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   797  			var err error
   798  			resp, err = executeRPC(ctx, c.modelMonitoringClient.SearchModelMonitoringStats, req, settings.GRPC, c.logger, "SearchModelMonitoringStats")
   799  			return err
   800  		}, opts...)
   801  		if err != nil {
   802  			return nil, "", err
   803  		}
   804  
   805  		it.Response = resp
   806  		return resp.GetMonitoringStats(), resp.GetNextPageToken(), nil
   807  	}
   808  	fetch := func(pageSize int, pageToken string) (string, error) {
   809  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   810  		if err != nil {
   811  			return "", err
   812  		}
   813  		it.items = append(it.items, items...)
   814  		return nextPageToken, nil
   815  	}
   816  
   817  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   818  	it.pageInfo.MaxSize = int(req.GetPageSize())
   819  	it.pageInfo.Token = req.GetPageToken()
   820  
   821  	return it
   822  }
   823  
   824  func (c *modelMonitoringGRPCClient) SearchModelMonitoringAlerts(ctx context.Context, req *aiplatformpb.SearchModelMonitoringAlertsRequest, opts ...gax.CallOption) *ModelMonitoringAlertIterator {
   825  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "model_monitor", url.QueryEscape(req.GetModelMonitor()))}
   826  
   827  	hds = append(c.xGoogHeaders, hds...)
   828  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   829  	opts = append((*c.CallOptions).SearchModelMonitoringAlerts[0:len((*c.CallOptions).SearchModelMonitoringAlerts):len((*c.CallOptions).SearchModelMonitoringAlerts)], opts...)
   830  	it := &ModelMonitoringAlertIterator{}
   831  	req = proto.Clone(req).(*aiplatformpb.SearchModelMonitoringAlertsRequest)
   832  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitoringAlert, string, error) {
   833  		resp := &aiplatformpb.SearchModelMonitoringAlertsResponse{}
   834  		if pageToken != "" {
   835  			req.PageToken = pageToken
   836  		}
   837  		if pageSize > math.MaxInt32 {
   838  			req.PageSize = math.MaxInt32
   839  		} else if pageSize != 0 {
   840  			req.PageSize = int32(pageSize)
   841  		}
   842  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   843  			var err error
   844  			resp, err = executeRPC(ctx, c.modelMonitoringClient.SearchModelMonitoringAlerts, req, settings.GRPC, c.logger, "SearchModelMonitoringAlerts")
   845  			return err
   846  		}, opts...)
   847  		if err != nil {
   848  			return nil, "", err
   849  		}
   850  
   851  		it.Response = resp
   852  		return resp.GetModelMonitoringAlerts(), resp.GetNextPageToken(), nil
   853  	}
   854  	fetch := func(pageSize int, pageToken string) (string, error) {
   855  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   856  		if err != nil {
   857  			return "", err
   858  		}
   859  		it.items = append(it.items, items...)
   860  		return nextPageToken, nil
   861  	}
   862  
   863  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   864  	it.pageInfo.MaxSize = int(req.GetPageSize())
   865  	it.pageInfo.Token = req.GetPageToken()
   866  
   867  	return it
   868  }
   869  
   870  func (c *modelMonitoringGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   871  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   872  
   873  	hds = append(c.xGoogHeaders, hds...)
   874  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   875  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   876  	var resp *locationpb.Location
   877  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   878  		var err error
   879  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   880  		return err
   881  	}, opts...)
   882  	if err != nil {
   883  		return nil, err
   884  	}
   885  	return resp, nil
   886  }
   887  
   888  func (c *modelMonitoringGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   889  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   890  
   891  	hds = append(c.xGoogHeaders, hds...)
   892  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   893  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   894  	it := &LocationIterator{}
   895  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   896  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   897  		resp := &locationpb.ListLocationsResponse{}
   898  		if pageToken != "" {
   899  			req.PageToken = pageToken
   900  		}
   901  		if pageSize > math.MaxInt32 {
   902  			req.PageSize = math.MaxInt32
   903  		} else if pageSize != 0 {
   904  			req.PageSize = int32(pageSize)
   905  		}
   906  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   907  			var err error
   908  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   909  			return err
   910  		}, opts...)
   911  		if err != nil {
   912  			return nil, "", err
   913  		}
   914  
   915  		it.Response = resp
   916  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   917  	}
   918  	fetch := func(pageSize int, pageToken string) (string, error) {
   919  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   920  		if err != nil {
   921  			return "", err
   922  		}
   923  		it.items = append(it.items, items...)
   924  		return nextPageToken, nil
   925  	}
   926  
   927  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   928  	it.pageInfo.MaxSize = int(req.GetPageSize())
   929  	it.pageInfo.Token = req.GetPageToken()
   930  
   931  	return it
   932  }
   933  
   934  func (c *modelMonitoringGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   935  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   936  
   937  	hds = append(c.xGoogHeaders, hds...)
   938  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   939  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   940  	var resp *iampb.Policy
   941  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   942  		var err error
   943  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   944  		return err
   945  	}, opts...)
   946  	if err != nil {
   947  		return nil, err
   948  	}
   949  	return resp, nil
   950  }
   951  
   952  func (c *modelMonitoringGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   953  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   954  
   955  	hds = append(c.xGoogHeaders, hds...)
   956  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   957  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   958  	var resp *iampb.Policy
   959  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   960  		var err error
   961  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   962  		return err
   963  	}, opts...)
   964  	if err != nil {
   965  		return nil, err
   966  	}
   967  	return resp, nil
   968  }
   969  
   970  func (c *modelMonitoringGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   971  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   972  
   973  	hds = append(c.xGoogHeaders, hds...)
   974  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   975  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   976  	var resp *iampb.TestIamPermissionsResponse
   977  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   978  		var err error
   979  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   980  		return err
   981  	}, opts...)
   982  	if err != nil {
   983  		return nil, err
   984  	}
   985  	return resp, nil
   986  }
   987  
   988  func (c *modelMonitoringGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   989  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   990  
   991  	hds = append(c.xGoogHeaders, hds...)
   992  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   993  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   994  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   995  		var err error
   996  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   997  		return err
   998  	}, opts...)
   999  	return err
  1000  }
  1001  
  1002  func (c *modelMonitoringGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
  1003  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1004  
  1005  	hds = append(c.xGoogHeaders, hds...)
  1006  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1007  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
  1008  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1009  		var err error
  1010  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
  1011  		return err
  1012  	}, opts...)
  1013  	return err
  1014  }
  1015  
  1016  func (c *modelMonitoringGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1017  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1018  
  1019  	hds = append(c.xGoogHeaders, hds...)
  1020  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1021  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1022  	var resp *longrunningpb.Operation
  1023  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1024  		var err error
  1025  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
  1026  		return err
  1027  	}, opts...)
  1028  	if err != nil {
  1029  		return nil, err
  1030  	}
  1031  	return resp, nil
  1032  }
  1033  
  1034  func (c *modelMonitoringGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  1035  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1036  
  1037  	hds = append(c.xGoogHeaders, hds...)
  1038  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1039  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
  1040  	it := &OperationIterator{}
  1041  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  1042  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  1043  		resp := &longrunningpb.ListOperationsResponse{}
  1044  		if pageToken != "" {
  1045  			req.PageToken = pageToken
  1046  		}
  1047  		if pageSize > math.MaxInt32 {
  1048  			req.PageSize = math.MaxInt32
  1049  		} else if pageSize != 0 {
  1050  			req.PageSize = int32(pageSize)
  1051  		}
  1052  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1053  			var err error
  1054  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
  1055  			return err
  1056  		}, opts...)
  1057  		if err != nil {
  1058  			return nil, "", err
  1059  		}
  1060  
  1061  		it.Response = resp
  1062  		return resp.GetOperations(), resp.GetNextPageToken(), nil
  1063  	}
  1064  	fetch := func(pageSize int, pageToken string) (string, error) {
  1065  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1066  		if err != nil {
  1067  			return "", err
  1068  		}
  1069  		it.items = append(it.items, items...)
  1070  		return nextPageToken, nil
  1071  	}
  1072  
  1073  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1074  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1075  	it.pageInfo.Token = req.GetPageToken()
  1076  
  1077  	return it
  1078  }
  1079  
  1080  func (c *modelMonitoringGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1081  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1082  
  1083  	hds = append(c.xGoogHeaders, hds...)
  1084  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1085  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  1086  	var resp *longrunningpb.Operation
  1087  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1088  		var err error
  1089  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
  1090  		return err
  1091  	}, opts...)
  1092  	if err != nil {
  1093  		return nil, err
  1094  	}
  1095  	return resp, nil
  1096  }
  1097  
  1098  // CreateModelMonitor creates a ModelMonitor.
  1099  func (c *modelMonitoringRESTClient) CreateModelMonitor(ctx context.Context, req *aiplatformpb.CreateModelMonitorRequest, opts ...gax.CallOption) (*CreateModelMonitorOperation, error) {
  1100  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1101  	body := req.GetModelMonitor()
  1102  	jsonReq, err := m.Marshal(body)
  1103  	if err != nil {
  1104  		return nil, err
  1105  	}
  1106  
  1107  	baseUrl, err := url.Parse(c.endpoint)
  1108  	if err != nil {
  1109  		return nil, err
  1110  	}
  1111  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v/modelMonitors", req.GetParent())
  1112  
  1113  	params := url.Values{}
  1114  	params.Add("$alt", "json;enum-encoding=int")
  1115  	if req.GetModelMonitorId() != "" {
  1116  		params.Add("modelMonitorId", fmt.Sprintf("%v", req.GetModelMonitorId()))
  1117  	}
  1118  
  1119  	baseUrl.RawQuery = params.Encode()
  1120  
  1121  	// Build HTTP headers from client and context metadata.
  1122  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  1123  
  1124  	hds = append(c.xGoogHeaders, hds...)
  1125  	hds = append(hds, "Content-Type", "application/json")
  1126  	headers := gax.BuildHeaders(ctx, hds...)
  1127  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1128  	resp := &longrunningpb.Operation{}
  1129  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1130  		if settings.Path != "" {
  1131  			baseUrl.Path = settings.Path
  1132  		}
  1133  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1134  		if err != nil {
  1135  			return err
  1136  		}
  1137  		httpReq = httpReq.WithContext(ctx)
  1138  		httpReq.Header = headers
  1139  
  1140  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateModelMonitor")
  1141  		if err != nil {
  1142  			return err
  1143  		}
  1144  		if err := unm.Unmarshal(buf, resp); err != nil {
  1145  			return err
  1146  		}
  1147  
  1148  		return nil
  1149  	}, opts...)
  1150  	if e != nil {
  1151  		return nil, e
  1152  	}
  1153  
  1154  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1155  	return &CreateModelMonitorOperation{
  1156  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1157  		pollPath: override,
  1158  	}, nil
  1159  }
  1160  
  1161  // UpdateModelMonitor updates a ModelMonitor.
  1162  func (c *modelMonitoringRESTClient) UpdateModelMonitor(ctx context.Context, req *aiplatformpb.UpdateModelMonitorRequest, opts ...gax.CallOption) (*UpdateModelMonitorOperation, error) {
  1163  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1164  	body := req.GetModelMonitor()
  1165  	jsonReq, err := m.Marshal(body)
  1166  	if err != nil {
  1167  		return nil, err
  1168  	}
  1169  
  1170  	baseUrl, err := url.Parse(c.endpoint)
  1171  	if err != nil {
  1172  		return nil, err
  1173  	}
  1174  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetModelMonitor().GetName())
  1175  
  1176  	params := url.Values{}
  1177  	params.Add("$alt", "json;enum-encoding=int")
  1178  	if req.GetUpdateMask() != nil {
  1179  		field, err := protojson.Marshal(req.GetUpdateMask())
  1180  		if err != nil {
  1181  			return nil, err
  1182  		}
  1183  		params.Add("updateMask", string(field[1:len(field)-1]))
  1184  	}
  1185  
  1186  	baseUrl.RawQuery = params.Encode()
  1187  
  1188  	// Build HTTP headers from client and context metadata.
  1189  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "model_monitor.name", url.QueryEscape(req.GetModelMonitor().GetName()))}
  1190  
  1191  	hds = append(c.xGoogHeaders, hds...)
  1192  	hds = append(hds, "Content-Type", "application/json")
  1193  	headers := gax.BuildHeaders(ctx, hds...)
  1194  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1195  	resp := &longrunningpb.Operation{}
  1196  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1197  		if settings.Path != "" {
  1198  			baseUrl.Path = settings.Path
  1199  		}
  1200  		httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
  1201  		if err != nil {
  1202  			return err
  1203  		}
  1204  		httpReq = httpReq.WithContext(ctx)
  1205  		httpReq.Header = headers
  1206  
  1207  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateModelMonitor")
  1208  		if err != nil {
  1209  			return err
  1210  		}
  1211  		if err := unm.Unmarshal(buf, resp); err != nil {
  1212  			return err
  1213  		}
  1214  
  1215  		return nil
  1216  	}, opts...)
  1217  	if e != nil {
  1218  		return nil, e
  1219  	}
  1220  
  1221  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1222  	return &UpdateModelMonitorOperation{
  1223  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1224  		pollPath: override,
  1225  	}, nil
  1226  }
  1227  
  1228  // GetModelMonitor gets a ModelMonitor.
  1229  func (c *modelMonitoringRESTClient) GetModelMonitor(ctx context.Context, req *aiplatformpb.GetModelMonitorRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitor, error) {
  1230  	baseUrl, err := url.Parse(c.endpoint)
  1231  	if err != nil {
  1232  		return nil, err
  1233  	}
  1234  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
  1235  
  1236  	params := url.Values{}
  1237  	params.Add("$alt", "json;enum-encoding=int")
  1238  
  1239  	baseUrl.RawQuery = params.Encode()
  1240  
  1241  	// Build HTTP headers from client and context metadata.
  1242  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1243  
  1244  	hds = append(c.xGoogHeaders, hds...)
  1245  	hds = append(hds, "Content-Type", "application/json")
  1246  	headers := gax.BuildHeaders(ctx, hds...)
  1247  	opts = append((*c.CallOptions).GetModelMonitor[0:len((*c.CallOptions).GetModelMonitor):len((*c.CallOptions).GetModelMonitor)], opts...)
  1248  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1249  	resp := &aiplatformpb.ModelMonitor{}
  1250  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1251  		if settings.Path != "" {
  1252  			baseUrl.Path = settings.Path
  1253  		}
  1254  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1255  		if err != nil {
  1256  			return err
  1257  		}
  1258  		httpReq = httpReq.WithContext(ctx)
  1259  		httpReq.Header = headers
  1260  
  1261  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetModelMonitor")
  1262  		if err != nil {
  1263  			return err
  1264  		}
  1265  
  1266  		if err := unm.Unmarshal(buf, resp); err != nil {
  1267  			return err
  1268  		}
  1269  
  1270  		return nil
  1271  	}, opts...)
  1272  	if e != nil {
  1273  		return nil, e
  1274  	}
  1275  	return resp, nil
  1276  }
  1277  
  1278  // ListModelMonitors lists ModelMonitors in a Location.
  1279  func (c *modelMonitoringRESTClient) ListModelMonitors(ctx context.Context, req *aiplatformpb.ListModelMonitorsRequest, opts ...gax.CallOption) *ModelMonitorIterator {
  1280  	it := &ModelMonitorIterator{}
  1281  	req = proto.Clone(req).(*aiplatformpb.ListModelMonitorsRequest)
  1282  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1283  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitor, string, error) {
  1284  		resp := &aiplatformpb.ListModelMonitorsResponse{}
  1285  		if pageToken != "" {
  1286  			req.PageToken = pageToken
  1287  		}
  1288  		if pageSize > math.MaxInt32 {
  1289  			req.PageSize = math.MaxInt32
  1290  		} else if pageSize != 0 {
  1291  			req.PageSize = int32(pageSize)
  1292  		}
  1293  		baseUrl, err := url.Parse(c.endpoint)
  1294  		if err != nil {
  1295  			return nil, "", err
  1296  		}
  1297  		baseUrl.Path += fmt.Sprintf("/v1beta1/%v/modelMonitors", req.GetParent())
  1298  
  1299  		params := url.Values{}
  1300  		params.Add("$alt", "json;enum-encoding=int")
  1301  		if req.GetFilter() != "" {
  1302  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1303  		}
  1304  		if req.GetPageSize() != 0 {
  1305  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1306  		}
  1307  		if req.GetPageToken() != "" {
  1308  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1309  		}
  1310  		if req.GetReadMask() != nil {
  1311  			field, err := protojson.Marshal(req.GetReadMask())
  1312  			if err != nil {
  1313  				return nil, "", err
  1314  			}
  1315  			params.Add("readMask", string(field[1:len(field)-1]))
  1316  		}
  1317  
  1318  		baseUrl.RawQuery = params.Encode()
  1319  
  1320  		// Build HTTP headers from client and context metadata.
  1321  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1322  		headers := gax.BuildHeaders(ctx, hds...)
  1323  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1324  			if settings.Path != "" {
  1325  				baseUrl.Path = settings.Path
  1326  			}
  1327  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1328  			if err != nil {
  1329  				return err
  1330  			}
  1331  			httpReq.Header = headers
  1332  
  1333  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListModelMonitors")
  1334  			if err != nil {
  1335  				return err
  1336  			}
  1337  			if err := unm.Unmarshal(buf, resp); err != nil {
  1338  				return err
  1339  			}
  1340  
  1341  			return nil
  1342  		}, opts...)
  1343  		if e != nil {
  1344  			return nil, "", e
  1345  		}
  1346  		it.Response = resp
  1347  		return resp.GetModelMonitors(), resp.GetNextPageToken(), nil
  1348  	}
  1349  
  1350  	fetch := func(pageSize int, pageToken string) (string, error) {
  1351  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1352  		if err != nil {
  1353  			return "", err
  1354  		}
  1355  		it.items = append(it.items, items...)
  1356  		return nextPageToken, nil
  1357  	}
  1358  
  1359  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1360  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1361  	it.pageInfo.Token = req.GetPageToken()
  1362  
  1363  	return it
  1364  }
  1365  
  1366  // DeleteModelMonitor deletes a ModelMonitor.
  1367  func (c *modelMonitoringRESTClient) DeleteModelMonitor(ctx context.Context, req *aiplatformpb.DeleteModelMonitorRequest, opts ...gax.CallOption) (*DeleteModelMonitorOperation, error) {
  1368  	baseUrl, err := url.Parse(c.endpoint)
  1369  	if err != nil {
  1370  		return nil, err
  1371  	}
  1372  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
  1373  
  1374  	params := url.Values{}
  1375  	params.Add("$alt", "json;enum-encoding=int")
  1376  	if req.GetForce() {
  1377  		params.Add("force", fmt.Sprintf("%v", req.GetForce()))
  1378  	}
  1379  
  1380  	baseUrl.RawQuery = params.Encode()
  1381  
  1382  	// Build HTTP headers from client and context metadata.
  1383  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1384  
  1385  	hds = append(c.xGoogHeaders, hds...)
  1386  	hds = append(hds, "Content-Type", "application/json")
  1387  	headers := gax.BuildHeaders(ctx, hds...)
  1388  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1389  	resp := &longrunningpb.Operation{}
  1390  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1391  		if settings.Path != "" {
  1392  			baseUrl.Path = settings.Path
  1393  		}
  1394  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1395  		if err != nil {
  1396  			return err
  1397  		}
  1398  		httpReq = httpReq.WithContext(ctx)
  1399  		httpReq.Header = headers
  1400  
  1401  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteModelMonitor")
  1402  		if err != nil {
  1403  			return err
  1404  		}
  1405  		if err := unm.Unmarshal(buf, resp); err != nil {
  1406  			return err
  1407  		}
  1408  
  1409  		return nil
  1410  	}, opts...)
  1411  	if e != nil {
  1412  		return nil, e
  1413  	}
  1414  
  1415  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1416  	return &DeleteModelMonitorOperation{
  1417  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1418  		pollPath: override,
  1419  	}, nil
  1420  }
  1421  
  1422  // CreateModelMonitoringJob creates a ModelMonitoringJob.
  1423  func (c *modelMonitoringRESTClient) CreateModelMonitoringJob(ctx context.Context, req *aiplatformpb.CreateModelMonitoringJobRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error) {
  1424  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1425  	body := req.GetModelMonitoringJob()
  1426  	jsonReq, err := m.Marshal(body)
  1427  	if err != nil {
  1428  		return nil, err
  1429  	}
  1430  
  1431  	baseUrl, err := url.Parse(c.endpoint)
  1432  	if err != nil {
  1433  		return nil, err
  1434  	}
  1435  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v/modelMonitoringJobs", req.GetParent())
  1436  
  1437  	params := url.Values{}
  1438  	params.Add("$alt", "json;enum-encoding=int")
  1439  	if req.GetModelMonitoringJobId() != "" {
  1440  		params.Add("modelMonitoringJobId", fmt.Sprintf("%v", req.GetModelMonitoringJobId()))
  1441  	}
  1442  
  1443  	baseUrl.RawQuery = params.Encode()
  1444  
  1445  	// Build HTTP headers from client and context metadata.
  1446  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  1447  
  1448  	hds = append(c.xGoogHeaders, hds...)
  1449  	hds = append(hds, "Content-Type", "application/json")
  1450  	headers := gax.BuildHeaders(ctx, hds...)
  1451  	opts = append((*c.CallOptions).CreateModelMonitoringJob[0:len((*c.CallOptions).CreateModelMonitoringJob):len((*c.CallOptions).CreateModelMonitoringJob)], opts...)
  1452  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1453  	resp := &aiplatformpb.ModelMonitoringJob{}
  1454  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1455  		if settings.Path != "" {
  1456  			baseUrl.Path = settings.Path
  1457  		}
  1458  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1459  		if err != nil {
  1460  			return err
  1461  		}
  1462  		httpReq = httpReq.WithContext(ctx)
  1463  		httpReq.Header = headers
  1464  
  1465  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateModelMonitoringJob")
  1466  		if err != nil {
  1467  			return err
  1468  		}
  1469  
  1470  		if err := unm.Unmarshal(buf, resp); err != nil {
  1471  			return err
  1472  		}
  1473  
  1474  		return nil
  1475  	}, opts...)
  1476  	if e != nil {
  1477  		return nil, e
  1478  	}
  1479  	return resp, nil
  1480  }
  1481  
  1482  // GetModelMonitoringJob gets a ModelMonitoringJob.
  1483  func (c *modelMonitoringRESTClient) GetModelMonitoringJob(ctx context.Context, req *aiplatformpb.GetModelMonitoringJobRequest, opts ...gax.CallOption) (*aiplatformpb.ModelMonitoringJob, error) {
  1484  	baseUrl, err := url.Parse(c.endpoint)
  1485  	if err != nil {
  1486  		return nil, err
  1487  	}
  1488  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
  1489  
  1490  	params := url.Values{}
  1491  	params.Add("$alt", "json;enum-encoding=int")
  1492  
  1493  	baseUrl.RawQuery = params.Encode()
  1494  
  1495  	// Build HTTP headers from client and context metadata.
  1496  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1497  
  1498  	hds = append(c.xGoogHeaders, hds...)
  1499  	hds = append(hds, "Content-Type", "application/json")
  1500  	headers := gax.BuildHeaders(ctx, hds...)
  1501  	opts = append((*c.CallOptions).GetModelMonitoringJob[0:len((*c.CallOptions).GetModelMonitoringJob):len((*c.CallOptions).GetModelMonitoringJob)], opts...)
  1502  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1503  	resp := &aiplatformpb.ModelMonitoringJob{}
  1504  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1505  		if settings.Path != "" {
  1506  			baseUrl.Path = settings.Path
  1507  		}
  1508  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1509  		if err != nil {
  1510  			return err
  1511  		}
  1512  		httpReq = httpReq.WithContext(ctx)
  1513  		httpReq.Header = headers
  1514  
  1515  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetModelMonitoringJob")
  1516  		if err != nil {
  1517  			return err
  1518  		}
  1519  
  1520  		if err := unm.Unmarshal(buf, resp); err != nil {
  1521  			return err
  1522  		}
  1523  
  1524  		return nil
  1525  	}, opts...)
  1526  	if e != nil {
  1527  		return nil, e
  1528  	}
  1529  	return resp, nil
  1530  }
  1531  
  1532  // ListModelMonitoringJobs lists ModelMonitoringJobs.
  1533  // Callers may choose to read across multiple Monitors as per
  1534  // AIP-159 (at https://google.aip.dev/159) by using ‘-’ (the hyphen or dash
  1535  // character) as a wildcard character instead of modelMonitor id in the
  1536  // parent. Format
  1537  // projects/{project_id}/locations/{location}/moodelMonitors/-/modelMonitoringJobs
  1538  func (c *modelMonitoringRESTClient) ListModelMonitoringJobs(ctx context.Context, req *aiplatformpb.ListModelMonitoringJobsRequest, opts ...gax.CallOption) *ModelMonitoringJobIterator {
  1539  	it := &ModelMonitoringJobIterator{}
  1540  	req = proto.Clone(req).(*aiplatformpb.ListModelMonitoringJobsRequest)
  1541  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1542  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitoringJob, string, error) {
  1543  		resp := &aiplatformpb.ListModelMonitoringJobsResponse{}
  1544  		if pageToken != "" {
  1545  			req.PageToken = pageToken
  1546  		}
  1547  		if pageSize > math.MaxInt32 {
  1548  			req.PageSize = math.MaxInt32
  1549  		} else if pageSize != 0 {
  1550  			req.PageSize = int32(pageSize)
  1551  		}
  1552  		baseUrl, err := url.Parse(c.endpoint)
  1553  		if err != nil {
  1554  			return nil, "", err
  1555  		}
  1556  		baseUrl.Path += fmt.Sprintf("/v1beta1/%v/modelMonitoringJobs", req.GetParent())
  1557  
  1558  		params := url.Values{}
  1559  		params.Add("$alt", "json;enum-encoding=int")
  1560  		if req.GetFilter() != "" {
  1561  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1562  		}
  1563  		if req.GetPageSize() != 0 {
  1564  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1565  		}
  1566  		if req.GetPageToken() != "" {
  1567  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1568  		}
  1569  		if req.GetReadMask() != nil {
  1570  			field, err := protojson.Marshal(req.GetReadMask())
  1571  			if err != nil {
  1572  				return nil, "", err
  1573  			}
  1574  			params.Add("readMask", string(field[1:len(field)-1]))
  1575  		}
  1576  
  1577  		baseUrl.RawQuery = params.Encode()
  1578  
  1579  		// Build HTTP headers from client and context metadata.
  1580  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1581  		headers := gax.BuildHeaders(ctx, hds...)
  1582  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1583  			if settings.Path != "" {
  1584  				baseUrl.Path = settings.Path
  1585  			}
  1586  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1587  			if err != nil {
  1588  				return err
  1589  			}
  1590  			httpReq.Header = headers
  1591  
  1592  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListModelMonitoringJobs")
  1593  			if err != nil {
  1594  				return err
  1595  			}
  1596  			if err := unm.Unmarshal(buf, resp); err != nil {
  1597  				return err
  1598  			}
  1599  
  1600  			return nil
  1601  		}, opts...)
  1602  		if e != nil {
  1603  			return nil, "", e
  1604  		}
  1605  		it.Response = resp
  1606  		return resp.GetModelMonitoringJobs(), resp.GetNextPageToken(), nil
  1607  	}
  1608  
  1609  	fetch := func(pageSize int, pageToken string) (string, error) {
  1610  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1611  		if err != nil {
  1612  			return "", err
  1613  		}
  1614  		it.items = append(it.items, items...)
  1615  		return nextPageToken, nil
  1616  	}
  1617  
  1618  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1619  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1620  	it.pageInfo.Token = req.GetPageToken()
  1621  
  1622  	return it
  1623  }
  1624  
  1625  // DeleteModelMonitoringJob deletes a ModelMonitoringJob.
  1626  func (c *modelMonitoringRESTClient) DeleteModelMonitoringJob(ctx context.Context, req *aiplatformpb.DeleteModelMonitoringJobRequest, opts ...gax.CallOption) (*DeleteModelMonitoringJobOperation, error) {
  1627  	baseUrl, err := url.Parse(c.endpoint)
  1628  	if err != nil {
  1629  		return nil, err
  1630  	}
  1631  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName())
  1632  
  1633  	params := url.Values{}
  1634  	params.Add("$alt", "json;enum-encoding=int")
  1635  
  1636  	baseUrl.RawQuery = params.Encode()
  1637  
  1638  	// Build HTTP headers from client and context metadata.
  1639  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1640  
  1641  	hds = append(c.xGoogHeaders, hds...)
  1642  	hds = append(hds, "Content-Type", "application/json")
  1643  	headers := gax.BuildHeaders(ctx, hds...)
  1644  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1645  	resp := &longrunningpb.Operation{}
  1646  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1647  		if settings.Path != "" {
  1648  			baseUrl.Path = settings.Path
  1649  		}
  1650  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1651  		if err != nil {
  1652  			return err
  1653  		}
  1654  		httpReq = httpReq.WithContext(ctx)
  1655  		httpReq.Header = headers
  1656  
  1657  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteModelMonitoringJob")
  1658  		if err != nil {
  1659  			return err
  1660  		}
  1661  		if err := unm.Unmarshal(buf, resp); err != nil {
  1662  			return err
  1663  		}
  1664  
  1665  		return nil
  1666  	}, opts...)
  1667  	if e != nil {
  1668  		return nil, e
  1669  	}
  1670  
  1671  	override := fmt.Sprintf("/ui/%s", resp.GetName())
  1672  	return &DeleteModelMonitoringJobOperation{
  1673  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1674  		pollPath: override,
  1675  	}, nil
  1676  }
  1677  
  1678  // SearchModelMonitoringStats searches Model Monitoring Stats generated within a given time window.
  1679  func (c *modelMonitoringRESTClient) SearchModelMonitoringStats(ctx context.Context, req *aiplatformpb.SearchModelMonitoringStatsRequest, opts ...gax.CallOption) *ModelMonitoringStatsIterator {
  1680  	it := &ModelMonitoringStatsIterator{}
  1681  	req = proto.Clone(req).(*aiplatformpb.SearchModelMonitoringStatsRequest)
  1682  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1683  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1684  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitoringStats, string, error) {
  1685  		resp := &aiplatformpb.SearchModelMonitoringStatsResponse{}
  1686  		if pageToken != "" {
  1687  			req.PageToken = pageToken
  1688  		}
  1689  		if pageSize > math.MaxInt32 {
  1690  			req.PageSize = math.MaxInt32
  1691  		} else if pageSize != 0 {
  1692  			req.PageSize = int32(pageSize)
  1693  		}
  1694  		jsonReq, err := m.Marshal(req)
  1695  		if err != nil {
  1696  			return nil, "", err
  1697  		}
  1698  
  1699  		baseUrl, err := url.Parse(c.endpoint)
  1700  		if err != nil {
  1701  			return nil, "", err
  1702  		}
  1703  		baseUrl.Path += fmt.Sprintf("/v1beta1/%v:searchModelMonitoringStats", req.GetModelMonitor())
  1704  
  1705  		params := url.Values{}
  1706  		params.Add("$alt", "json;enum-encoding=int")
  1707  
  1708  		baseUrl.RawQuery = params.Encode()
  1709  
  1710  		// Build HTTP headers from client and context metadata.
  1711  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1712  		headers := gax.BuildHeaders(ctx, hds...)
  1713  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1714  			if settings.Path != "" {
  1715  				baseUrl.Path = settings.Path
  1716  			}
  1717  			httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1718  			if err != nil {
  1719  				return err
  1720  			}
  1721  			httpReq.Header = headers
  1722  
  1723  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SearchModelMonitoringStats")
  1724  			if err != nil {
  1725  				return err
  1726  			}
  1727  			if err := unm.Unmarshal(buf, resp); err != nil {
  1728  				return err
  1729  			}
  1730  
  1731  			return nil
  1732  		}, opts...)
  1733  		if e != nil {
  1734  			return nil, "", e
  1735  		}
  1736  		it.Response = resp
  1737  		return resp.GetMonitoringStats(), resp.GetNextPageToken(), nil
  1738  	}
  1739  
  1740  	fetch := func(pageSize int, pageToken string) (string, error) {
  1741  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1742  		if err != nil {
  1743  			return "", err
  1744  		}
  1745  		it.items = append(it.items, items...)
  1746  		return nextPageToken, nil
  1747  	}
  1748  
  1749  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1750  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1751  	it.pageInfo.Token = req.GetPageToken()
  1752  
  1753  	return it
  1754  }
  1755  
  1756  // SearchModelMonitoringAlerts returns the Model Monitoring alerts.
  1757  func (c *modelMonitoringRESTClient) SearchModelMonitoringAlerts(ctx context.Context, req *aiplatformpb.SearchModelMonitoringAlertsRequest, opts ...gax.CallOption) *ModelMonitoringAlertIterator {
  1758  	it := &ModelMonitoringAlertIterator{}
  1759  	req = proto.Clone(req).(*aiplatformpb.SearchModelMonitoringAlertsRequest)
  1760  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1761  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1762  	it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.ModelMonitoringAlert, string, error) {
  1763  		resp := &aiplatformpb.SearchModelMonitoringAlertsResponse{}
  1764  		if pageToken != "" {
  1765  			req.PageToken = pageToken
  1766  		}
  1767  		if pageSize > math.MaxInt32 {
  1768  			req.PageSize = math.MaxInt32
  1769  		} else if pageSize != 0 {
  1770  			req.PageSize = int32(pageSize)
  1771  		}
  1772  		jsonReq, err := m.Marshal(req)
  1773  		if err != nil {
  1774  			return nil, "", err
  1775  		}
  1776  
  1777  		baseUrl, err := url.Parse(c.endpoint)
  1778  		if err != nil {
  1779  			return nil, "", err
  1780  		}
  1781  		baseUrl.Path += fmt.Sprintf("/v1beta1/%v:searchModelMonitoringAlerts", req.GetModelMonitor())
  1782  
  1783  		params := url.Values{}
  1784  		params.Add("$alt", "json;enum-encoding=int")
  1785  
  1786  		baseUrl.RawQuery = params.Encode()
  1787  
  1788  		// Build HTTP headers from client and context metadata.
  1789  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1790  		headers := gax.BuildHeaders(ctx, hds...)
  1791  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1792  			if settings.Path != "" {
  1793  				baseUrl.Path = settings.Path
  1794  			}
  1795  			httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1796  			if err != nil {
  1797  				return err
  1798  			}
  1799  			httpReq.Header = headers
  1800  
  1801  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SearchModelMonitoringAlerts")
  1802  			if err != nil {
  1803  				return err
  1804  			}
  1805  			if err := unm.Unmarshal(buf, resp); err != nil {
  1806  				return err
  1807  			}
  1808  
  1809  			return nil
  1810  		}, opts...)
  1811  		if e != nil {
  1812  			return nil, "", e
  1813  		}
  1814  		it.Response = resp
  1815  		return resp.GetModelMonitoringAlerts(), resp.GetNextPageToken(), nil
  1816  	}
  1817  
  1818  	fetch := func(pageSize int, pageToken string) (string, error) {
  1819  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1820  		if err != nil {
  1821  			return "", err
  1822  		}
  1823  		it.items = append(it.items, items...)
  1824  		return nextPageToken, nil
  1825  	}
  1826  
  1827  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1828  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1829  	it.pageInfo.Token = req.GetPageToken()
  1830  
  1831  	return it
  1832  }
  1833  
  1834  // GetLocation gets information about a location.
  1835  func (c *modelMonitoringRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
  1836  	baseUrl, err := url.Parse(c.endpoint)
  1837  	if err != nil {
  1838  		return nil, err
  1839  	}
  1840  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1841  
  1842  	params := url.Values{}
  1843  	params.Add("$alt", "json;enum-encoding=int")
  1844  
  1845  	baseUrl.RawQuery = params.Encode()
  1846  
  1847  	// Build HTTP headers from client and context metadata.
  1848  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1849  
  1850  	hds = append(c.xGoogHeaders, hds...)
  1851  	hds = append(hds, "Content-Type", "application/json")
  1852  	headers := gax.BuildHeaders(ctx, hds...)
  1853  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
  1854  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1855  	resp := &locationpb.Location{}
  1856  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1857  		if settings.Path != "" {
  1858  			baseUrl.Path = settings.Path
  1859  		}
  1860  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1861  		if err != nil {
  1862  			return err
  1863  		}
  1864  		httpReq = httpReq.WithContext(ctx)
  1865  		httpReq.Header = headers
  1866  
  1867  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
  1868  		if err != nil {
  1869  			return err
  1870  		}
  1871  
  1872  		if err := unm.Unmarshal(buf, resp); err != nil {
  1873  			return err
  1874  		}
  1875  
  1876  		return nil
  1877  	}, opts...)
  1878  	if e != nil {
  1879  		return nil, e
  1880  	}
  1881  	return resp, nil
  1882  }
  1883  
  1884  // ListLocations lists information about the supported locations for this service.
  1885  func (c *modelMonitoringRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
  1886  	it := &LocationIterator{}
  1887  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
  1888  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1889  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
  1890  		resp := &locationpb.ListLocationsResponse{}
  1891  		if pageToken != "" {
  1892  			req.PageToken = pageToken
  1893  		}
  1894  		if pageSize > math.MaxInt32 {
  1895  			req.PageSize = math.MaxInt32
  1896  		} else if pageSize != 0 {
  1897  			req.PageSize = int32(pageSize)
  1898  		}
  1899  		baseUrl, err := url.Parse(c.endpoint)
  1900  		if err != nil {
  1901  			return nil, "", err
  1902  		}
  1903  		baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName())
  1904  
  1905  		params := url.Values{}
  1906  		params.Add("$alt", "json;enum-encoding=int")
  1907  		if req.GetFilter() != "" {
  1908  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1909  		}
  1910  		if req.GetPageSize() != 0 {
  1911  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1912  		}
  1913  		if req.GetPageToken() != "" {
  1914  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1915  		}
  1916  
  1917  		baseUrl.RawQuery = params.Encode()
  1918  
  1919  		// Build HTTP headers from client and context metadata.
  1920  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1921  		headers := gax.BuildHeaders(ctx, hds...)
  1922  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1923  			if settings.Path != "" {
  1924  				baseUrl.Path = settings.Path
  1925  			}
  1926  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1927  			if err != nil {
  1928  				return err
  1929  			}
  1930  			httpReq.Header = headers
  1931  
  1932  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
  1933  			if err != nil {
  1934  				return err
  1935  			}
  1936  			if err := unm.Unmarshal(buf, resp); err != nil {
  1937  				return err
  1938  			}
  1939  
  1940  			return nil
  1941  		}, opts...)
  1942  		if e != nil {
  1943  			return nil, "", e
  1944  		}
  1945  		it.Response = resp
  1946  		return resp.GetLocations(), resp.GetNextPageToken(), nil
  1947  	}
  1948  
  1949  	fetch := func(pageSize int, pageToken string) (string, error) {
  1950  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1951  		if err != nil {
  1952  			return "", err
  1953  		}
  1954  		it.items = append(it.items, items...)
  1955  		return nextPageToken, nil
  1956  	}
  1957  
  1958  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1959  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1960  	it.pageInfo.Token = req.GetPageToken()
  1961  
  1962  	return it
  1963  }
  1964  
  1965  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
  1966  // if the resource exists and does not have a policy set.
  1967  func (c *modelMonitoringRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1968  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1969  	jsonReq, err := m.Marshal(req)
  1970  	if err != nil {
  1971  		return nil, err
  1972  	}
  1973  
  1974  	baseUrl, err := url.Parse(c.endpoint)
  1975  	if err != nil {
  1976  		return nil, err
  1977  	}
  1978  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource())
  1979  
  1980  	params := url.Values{}
  1981  	params.Add("$alt", "json;enum-encoding=int")
  1982  
  1983  	baseUrl.RawQuery = params.Encode()
  1984  
  1985  	// Build HTTP headers from client and context metadata.
  1986  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1987  
  1988  	hds = append(c.xGoogHeaders, hds...)
  1989  	hds = append(hds, "Content-Type", "application/json")
  1990  	headers := gax.BuildHeaders(ctx, hds...)
  1991  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1992  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1993  	resp := &iampb.Policy{}
  1994  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1995  		if settings.Path != "" {
  1996  			baseUrl.Path = settings.Path
  1997  		}
  1998  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1999  		if err != nil {
  2000  			return err
  2001  		}
  2002  		httpReq = httpReq.WithContext(ctx)
  2003  		httpReq.Header = headers
  2004  
  2005  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
  2006  		if err != nil {
  2007  			return err
  2008  		}
  2009  
  2010  		if err := unm.Unmarshal(buf, resp); err != nil {
  2011  			return err
  2012  		}
  2013  
  2014  		return nil
  2015  	}, opts...)
  2016  	if e != nil {
  2017  		return nil, e
  2018  	}
  2019  	return resp, nil
  2020  }
  2021  
  2022  // SetIamPolicy sets the access control policy on the specified resource. Replaces
  2023  // any existing policy.
  2024  //
  2025  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
  2026  // errors.
  2027  func (c *modelMonitoringRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  2028  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  2029  	jsonReq, err := m.Marshal(req)
  2030  	if err != nil {
  2031  		return nil, err
  2032  	}
  2033  
  2034  	baseUrl, err := url.Parse(c.endpoint)
  2035  	if err != nil {
  2036  		return nil, err
  2037  	}
  2038  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource())
  2039  
  2040  	params := url.Values{}
  2041  	params.Add("$alt", "json;enum-encoding=int")
  2042  
  2043  	baseUrl.RawQuery = params.Encode()
  2044  
  2045  	// Build HTTP headers from client and context metadata.
  2046  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  2047  
  2048  	hds = append(c.xGoogHeaders, hds...)
  2049  	hds = append(hds, "Content-Type", "application/json")
  2050  	headers := gax.BuildHeaders(ctx, hds...)
  2051  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  2052  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  2053  	resp := &iampb.Policy{}
  2054  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2055  		if settings.Path != "" {
  2056  			baseUrl.Path = settings.Path
  2057  		}
  2058  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  2059  		if err != nil {
  2060  			return err
  2061  		}
  2062  		httpReq = httpReq.WithContext(ctx)
  2063  		httpReq.Header = headers
  2064  
  2065  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
  2066  		if err != nil {
  2067  			return err
  2068  		}
  2069  
  2070  		if err := unm.Unmarshal(buf, resp); err != nil {
  2071  			return err
  2072  		}
  2073  
  2074  		return nil
  2075  	}, opts...)
  2076  	if e != nil {
  2077  		return nil, e
  2078  	}
  2079  	return resp, nil
  2080  }
  2081  
  2082  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
  2083  // resource does not exist, this will return an empty set of
  2084  // permissions, not a NOT_FOUND error.
  2085  //
  2086  // Note: This operation is designed to be used for building
  2087  // permission-aware UIs and command-line tools, not for authorization
  2088  // checking. This operation may “fail open” without warning.
  2089  func (c *modelMonitoringRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  2090  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  2091  	jsonReq, err := m.Marshal(req)
  2092  	if err != nil {
  2093  		return nil, err
  2094  	}
  2095  
  2096  	baseUrl, err := url.Parse(c.endpoint)
  2097  	if err != nil {
  2098  		return nil, err
  2099  	}
  2100  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource())
  2101  
  2102  	params := url.Values{}
  2103  	params.Add("$alt", "json;enum-encoding=int")
  2104  
  2105  	baseUrl.RawQuery = params.Encode()
  2106  
  2107  	// Build HTTP headers from client and context metadata.
  2108  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  2109  
  2110  	hds = append(c.xGoogHeaders, hds...)
  2111  	hds = append(hds, "Content-Type", "application/json")
  2112  	headers := gax.BuildHeaders(ctx, hds...)
  2113  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  2114  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  2115  	resp := &iampb.TestIamPermissionsResponse{}
  2116  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2117  		if settings.Path != "" {
  2118  			baseUrl.Path = settings.Path
  2119  		}
  2120  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  2121  		if err != nil {
  2122  			return err
  2123  		}
  2124  		httpReq = httpReq.WithContext(ctx)
  2125  		httpReq.Header = headers
  2126  
  2127  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
  2128  		if err != nil {
  2129  			return err
  2130  		}
  2131  
  2132  		if err := unm.Unmarshal(buf, resp); err != nil {
  2133  			return err
  2134  		}
  2135  
  2136  		return nil
  2137  	}, opts...)
  2138  	if e != nil {
  2139  		return nil, e
  2140  	}
  2141  	return resp, nil
  2142  }
  2143  
  2144  // CancelOperation is a utility method from google.longrunning.Operations.
  2145  func (c *modelMonitoringRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  2146  	baseUrl, err := url.Parse(c.endpoint)
  2147  	if err != nil {
  2148  		return err
  2149  	}
  2150  	baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName())
  2151  
  2152  	params := url.Values{}
  2153  	params.Add("$alt", "json;enum-encoding=int")
  2154  
  2155  	baseUrl.RawQuery = params.Encode()
  2156  
  2157  	// Build HTTP headers from client and context metadata.
  2158  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  2159  
  2160  	hds = append(c.xGoogHeaders, hds...)
  2161  	hds = append(hds, "Content-Type", "application/json")
  2162  	headers := gax.BuildHeaders(ctx, hds...)
  2163  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2164  		if settings.Path != "" {
  2165  			baseUrl.Path = settings.Path
  2166  		}
  2167  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  2168  		if err != nil {
  2169  			return err
  2170  		}
  2171  		httpReq = httpReq.WithContext(ctx)
  2172  		httpReq.Header = headers
  2173  
  2174  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation")
  2175  		return err
  2176  	}, opts...)
  2177  }
  2178  
  2179  // DeleteOperation is a utility method from google.longrunning.Operations.
  2180  func (c *modelMonitoringRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
  2181  	baseUrl, err := url.Parse(c.endpoint)
  2182  	if err != nil {
  2183  		return err
  2184  	}
  2185  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  2186  
  2187  	params := url.Values{}
  2188  	params.Add("$alt", "json;enum-encoding=int")
  2189  
  2190  	baseUrl.RawQuery = params.Encode()
  2191  
  2192  	// Build HTTP headers from client and context metadata.
  2193  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  2194  
  2195  	hds = append(c.xGoogHeaders, hds...)
  2196  	hds = append(hds, "Content-Type", "application/json")
  2197  	headers := gax.BuildHeaders(ctx, hds...)
  2198  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2199  		if settings.Path != "" {
  2200  			baseUrl.Path = settings.Path
  2201  		}
  2202  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  2203  		if err != nil {
  2204  			return err
  2205  		}
  2206  		httpReq = httpReq.WithContext(ctx)
  2207  		httpReq.Header = headers
  2208  
  2209  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
  2210  		return err
  2211  	}, opts...)
  2212  }
  2213  
  2214  // GetOperation is a utility method from google.longrunning.Operations.
  2215  func (c *modelMonitoringRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  2216  	baseUrl, err := url.Parse(c.endpoint)
  2217  	if err != nil {
  2218  		return nil, err
  2219  	}
  2220  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  2221  
  2222  	params := url.Values{}
  2223  	params.Add("$alt", "json;enum-encoding=int")
  2224  
  2225  	baseUrl.RawQuery = params.Encode()
  2226  
  2227  	// Build HTTP headers from client and context metadata.
  2228  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  2229  
  2230  	hds = append(c.xGoogHeaders, hds...)
  2231  	hds = append(hds, "Content-Type", "application/json")
  2232  	headers := gax.BuildHeaders(ctx, hds...)
  2233  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  2234  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  2235  	resp := &longrunningpb.Operation{}
  2236  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2237  		if settings.Path != "" {
  2238  			baseUrl.Path = settings.Path
  2239  		}
  2240  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  2241  		if err != nil {
  2242  			return err
  2243  		}
  2244  		httpReq = httpReq.WithContext(ctx)
  2245  		httpReq.Header = headers
  2246  
  2247  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
  2248  		if err != nil {
  2249  			return err
  2250  		}
  2251  
  2252  		if err := unm.Unmarshal(buf, resp); err != nil {
  2253  			return err
  2254  		}
  2255  
  2256  		return nil
  2257  	}, opts...)
  2258  	if e != nil {
  2259  		return nil, e
  2260  	}
  2261  	return resp, nil
  2262  }
  2263  
  2264  // ListOperations is a utility method from google.longrunning.Operations.
  2265  func (c *modelMonitoringRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  2266  	it := &OperationIterator{}
  2267  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  2268  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  2269  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  2270  		resp := &longrunningpb.ListOperationsResponse{}
  2271  		if pageToken != "" {
  2272  			req.PageToken = pageToken
  2273  		}
  2274  		if pageSize > math.MaxInt32 {
  2275  			req.PageSize = math.MaxInt32
  2276  		} else if pageSize != 0 {
  2277  			req.PageSize = int32(pageSize)
  2278  		}
  2279  		baseUrl, err := url.Parse(c.endpoint)
  2280  		if err != nil {
  2281  			return nil, "", err
  2282  		}
  2283  		baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName())
  2284  
  2285  		params := url.Values{}
  2286  		params.Add("$alt", "json;enum-encoding=int")
  2287  		if req.GetFilter() != "" {
  2288  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  2289  		}
  2290  		if req.GetPageSize() != 0 {
  2291  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  2292  		}
  2293  		if req.GetPageToken() != "" {
  2294  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  2295  		}
  2296  
  2297  		baseUrl.RawQuery = params.Encode()
  2298  
  2299  		// Build HTTP headers from client and context metadata.
  2300  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  2301  		headers := gax.BuildHeaders(ctx, hds...)
  2302  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2303  			if settings.Path != "" {
  2304  				baseUrl.Path = settings.Path
  2305  			}
  2306  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  2307  			if err != nil {
  2308  				return err
  2309  			}
  2310  			httpReq.Header = headers
  2311  
  2312  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
  2313  			if err != nil {
  2314  				return err
  2315  			}
  2316  			if err := unm.Unmarshal(buf, resp); err != nil {
  2317  				return err
  2318  			}
  2319  
  2320  			return nil
  2321  		}, opts...)
  2322  		if e != nil {
  2323  			return nil, "", e
  2324  		}
  2325  		it.Response = resp
  2326  		return resp.GetOperations(), resp.GetNextPageToken(), nil
  2327  	}
  2328  
  2329  	fetch := func(pageSize int, pageToken string) (string, error) {
  2330  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  2331  		if err != nil {
  2332  			return "", err
  2333  		}
  2334  		it.items = append(it.items, items...)
  2335  		return nextPageToken, nil
  2336  	}
  2337  
  2338  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  2339  	it.pageInfo.MaxSize = int(req.GetPageSize())
  2340  	it.pageInfo.Token = req.GetPageToken()
  2341  
  2342  	return it
  2343  }
  2344  
  2345  // WaitOperation is a utility method from google.longrunning.Operations.
  2346  func (c *modelMonitoringRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  2347  	baseUrl, err := url.Parse(c.endpoint)
  2348  	if err != nil {
  2349  		return nil, err
  2350  	}
  2351  	baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName())
  2352  
  2353  	params := url.Values{}
  2354  	params.Add("$alt", "json;enum-encoding=int")
  2355  	if req.GetTimeout() != nil {
  2356  		field, err := protojson.Marshal(req.GetTimeout())
  2357  		if err != nil {
  2358  			return nil, err
  2359  		}
  2360  		params.Add("timeout", string(field[1:len(field)-1]))
  2361  	}
  2362  
  2363  	baseUrl.RawQuery = params.Encode()
  2364  
  2365  	// Build HTTP headers from client and context metadata.
  2366  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  2367  
  2368  	hds = append(c.xGoogHeaders, hds...)
  2369  	hds = append(hds, "Content-Type", "application/json")
  2370  	headers := gax.BuildHeaders(ctx, hds...)
  2371  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  2372  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  2373  	resp := &longrunningpb.Operation{}
  2374  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  2375  		if settings.Path != "" {
  2376  			baseUrl.Path = settings.Path
  2377  		}
  2378  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  2379  		if err != nil {
  2380  			return err
  2381  		}
  2382  		httpReq = httpReq.WithContext(ctx)
  2383  		httpReq.Header = headers
  2384  
  2385  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation")
  2386  		if err != nil {
  2387  			return err
  2388  		}
  2389  
  2390  		if err := unm.Unmarshal(buf, resp); err != nil {
  2391  			return err
  2392  		}
  2393  
  2394  		return nil
  2395  	}, opts...)
  2396  	if e != nil {
  2397  		return nil, e
  2398  	}
  2399  	return resp, nil
  2400  }
  2401  
  2402  // CreateModelMonitorOperation returns a new CreateModelMonitorOperation from a given name.
  2403  // The name must be that of a previously created CreateModelMonitorOperation, possibly from a different process.
  2404  func (c *modelMonitoringGRPCClient) CreateModelMonitorOperation(name string) *CreateModelMonitorOperation {
  2405  	return &CreateModelMonitorOperation{
  2406  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2407  	}
  2408  }
  2409  
  2410  // CreateModelMonitorOperation returns a new CreateModelMonitorOperation from a given name.
  2411  // The name must be that of a previously created CreateModelMonitorOperation, possibly from a different process.
  2412  func (c *modelMonitoringRESTClient) CreateModelMonitorOperation(name string) *CreateModelMonitorOperation {
  2413  	override := fmt.Sprintf("/ui/%s", name)
  2414  	return &CreateModelMonitorOperation{
  2415  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2416  		pollPath: override,
  2417  	}
  2418  }
  2419  
  2420  // DeleteModelMonitorOperation returns a new DeleteModelMonitorOperation from a given name.
  2421  // The name must be that of a previously created DeleteModelMonitorOperation, possibly from a different process.
  2422  func (c *modelMonitoringGRPCClient) DeleteModelMonitorOperation(name string) *DeleteModelMonitorOperation {
  2423  	return &DeleteModelMonitorOperation{
  2424  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2425  	}
  2426  }
  2427  
  2428  // DeleteModelMonitorOperation returns a new DeleteModelMonitorOperation from a given name.
  2429  // The name must be that of a previously created DeleteModelMonitorOperation, possibly from a different process.
  2430  func (c *modelMonitoringRESTClient) DeleteModelMonitorOperation(name string) *DeleteModelMonitorOperation {
  2431  	override := fmt.Sprintf("/ui/%s", name)
  2432  	return &DeleteModelMonitorOperation{
  2433  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2434  		pollPath: override,
  2435  	}
  2436  }
  2437  
  2438  // DeleteModelMonitoringJobOperation returns a new DeleteModelMonitoringJobOperation from a given name.
  2439  // The name must be that of a previously created DeleteModelMonitoringJobOperation, possibly from a different process.
  2440  func (c *modelMonitoringGRPCClient) DeleteModelMonitoringJobOperation(name string) *DeleteModelMonitoringJobOperation {
  2441  	return &DeleteModelMonitoringJobOperation{
  2442  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2443  	}
  2444  }
  2445  
  2446  // DeleteModelMonitoringJobOperation returns a new DeleteModelMonitoringJobOperation from a given name.
  2447  // The name must be that of a previously created DeleteModelMonitoringJobOperation, possibly from a different process.
  2448  func (c *modelMonitoringRESTClient) DeleteModelMonitoringJobOperation(name string) *DeleteModelMonitoringJobOperation {
  2449  	override := fmt.Sprintf("/ui/%s", name)
  2450  	return &DeleteModelMonitoringJobOperation{
  2451  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2452  		pollPath: override,
  2453  	}
  2454  }
  2455  
  2456  // UpdateModelMonitorOperation returns a new UpdateModelMonitorOperation from a given name.
  2457  // The name must be that of a previously created UpdateModelMonitorOperation, possibly from a different process.
  2458  func (c *modelMonitoringGRPCClient) UpdateModelMonitorOperation(name string) *UpdateModelMonitorOperation {
  2459  	return &UpdateModelMonitorOperation{
  2460  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2461  	}
  2462  }
  2463  
  2464  // UpdateModelMonitorOperation returns a new UpdateModelMonitorOperation from a given name.
  2465  // The name must be that of a previously created UpdateModelMonitorOperation, possibly from a different process.
  2466  func (c *modelMonitoringRESTClient) UpdateModelMonitorOperation(name string) *UpdateModelMonitorOperation {
  2467  	override := fmt.Sprintf("/ui/%s", name)
  2468  	return &UpdateModelMonitorOperation{
  2469  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  2470  		pollPath: override,
  2471  	}
  2472  }