...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-01-preview/insights/predictivemetric.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-01-preview/insights

     1  package insights
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // PredictiveMetricClient is the monitor Management Client
    19  type PredictiveMetricClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPredictiveMetricClient creates an instance of the PredictiveMetricClient client.
    24  func NewPredictiveMetricClient(subscriptionID string) PredictiveMetricClient {
    25  	return NewPredictiveMetricClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPredictiveMetricClientWithBaseURI creates an instance of the PredictiveMetricClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewPredictiveMetricClientWithBaseURI(baseURI string, subscriptionID string) PredictiveMetricClient {
    32  	return PredictiveMetricClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get get predictive autoscale metric future data
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // autoscaleSettingName - the autoscale setting name.
    39  // aggregation - the list of aggregation types (comma separated) to retrieve.
    40  // timespan - the timespan of the query. It is a string with the following format
    41  // 'startDateTime_ISO/endDateTime_ISO'.
    42  // interval - the interval (i.e. timegrain) of the query.
    43  // metricnamespace - metric namespace to query metric definitions for.
    44  // metricnames - the names of the metrics (comma separated) to retrieve. Special case: If a metricname itself
    45  // has a comma in it then use %2 to indicate it. Eg: 'Metric,Name1' should be **'Metric%2Name1'**
    46  func (client PredictiveMetricClient) Get(ctx context.Context, resourceGroupName string, autoscaleSettingName string, aggregation string, timespan string, interval *string, metricnamespace string, metricnames string) (result PredictiveResponse, err error) {
    47  	if tracing.IsEnabled() {
    48  		ctx = tracing.StartSpan(ctx, fqdn+"/PredictiveMetricClient.Get")
    49  		defer func() {
    50  			sc := -1
    51  			if result.Response.Response != nil {
    52  				sc = result.Response.Response.StatusCode
    53  			}
    54  			tracing.EndSpan(ctx, sc, err)
    55  		}()
    56  	}
    57  	if err := validation.Validate([]validation.Validation{
    58  		{TargetValue: client.SubscriptionID,
    59  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    60  		{TargetValue: resourceGroupName,
    61  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    62  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    63  		return result, validation.NewError("insights.PredictiveMetricClient", "Get", err.Error())
    64  	}
    65  
    66  	req, err := client.GetPreparer(ctx, resourceGroupName, autoscaleSettingName, aggregation, timespan, interval, metricnamespace, metricnames)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "insights.PredictiveMetricClient", "Get", nil, "Failure preparing request")
    69  		return
    70  	}
    71  
    72  	resp, err := client.GetSender(req)
    73  	if err != nil {
    74  		result.Response = autorest.Response{Response: resp}
    75  		err = autorest.NewErrorWithError(err, "insights.PredictiveMetricClient", "Get", resp, "Failure sending request")
    76  		return
    77  	}
    78  
    79  	result, err = client.GetResponder(resp)
    80  	if err != nil {
    81  		err = autorest.NewErrorWithError(err, "insights.PredictiveMetricClient", "Get", resp, "Failure responding to request")
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // GetPreparer prepares the Get request.
    89  func (client PredictiveMetricClient) GetPreparer(ctx context.Context, resourceGroupName string, autoscaleSettingName string, aggregation string, timespan string, interval *string, metricnamespace string, metricnames string) (*http.Request, error) {
    90  	pathParameters := map[string]interface{}{
    91  		"autoscaleSettingName": autorest.Encode("path", autoscaleSettingName),
    92  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
    93  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
    94  	}
    95  
    96  	const APIVersion = "2022-10-01"
    97  	queryParameters := map[string]interface{}{
    98  		"aggregation": autorest.Encode("query", aggregation),
    99  		"api-version": APIVersion,
   100  	}
   101  	if len(timespan) > 0 {
   102  		queryParameters["timespan"] = autorest.Encode("query", timespan)
   103  	}
   104  	if interval != nil {
   105  		queryParameters["interval"] = autorest.Encode("query", *interval)
   106  	}
   107  	if len(metricnamespace) > 0 {
   108  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
   109  	}
   110  	if len(metricnames) > 0 {
   111  		queryParameters["metricnames"] = autorest.Encode("query", metricnames)
   112  	}
   113  
   114  	preparer := autorest.CreatePreparer(
   115  		autorest.AsGet(),
   116  		autorest.WithBaseURL(client.BaseURI),
   117  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/autoscalesettings/{autoscaleSettingName}/predictiveMetrics", pathParameters),
   118  		autorest.WithQueryParameters(queryParameters))
   119  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   120  }
   121  
   122  // GetSender sends the Get request. The method will close the
   123  // http.Response Body if it receives an error.
   124  func (client PredictiveMetricClient) GetSender(req *http.Request) (*http.Response, error) {
   125  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   126  }
   127  
   128  // GetResponder handles the response to the Get request. The method always
   129  // closes the http.Response Body.
   130  func (client PredictiveMetricClient) GetResponder(resp *http.Response) (result PredictiveResponse, err error) {
   131  	err = autorest.Respond(
   132  		resp,
   133  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   134  		autorest.ByUnmarshallingJSON(&result),
   135  		autorest.ByClosing())
   136  	result.Response = autorest.Response{Response: resp}
   137  	return
   138  }
   139  

View as plain text