...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics/predictivemetric.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics

     1  package diagnostics
     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  // timespan - the timespan of the query. It is a string with the following format
    40  // 'startDateTime_ISO/endDateTime_ISO'.
    41  // interval - the interval (i.e. timegrain) of the query.
    42  // metricNamespace - metric namespace to query metric definitions for.
    43  // metricName - the names of the metrics (comma separated) to retrieve. Special case: If a metricname itself
    44  // has a comma in it then use %2 to indicate it. Eg: 'Metric,Name1' should be **'Metric%2Name1'**
    45  // aggregation - the list of aggregation types (comma separated) to retrieve.
    46  func (client PredictiveMetricClient) Get(ctx context.Context, resourceGroupName string, autoscaleSettingName string, timespan string, interval string, metricNamespace string, metricName string, aggregation 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("diagnostics.PredictiveMetricClient", "Get", err.Error())
    64  	}
    65  
    66  	req, err := client.GetPreparer(ctx, resourceGroupName, autoscaleSettingName, timespan, interval, metricNamespace, metricName, aggregation)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "diagnostics.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, "diagnostics.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, "diagnostics.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, timespan string, interval string, metricNamespace string, metricName string, aggregation 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 = "2021-05-01-preview"
    97  	queryParameters := map[string]interface{}{
    98  		"aggregation":     autorest.Encode("query", aggregation),
    99  		"api-version":     APIVersion,
   100  		"interval":        autorest.Encode("query", interval),
   101  		"metricName":      autorest.Encode("query", metricName),
   102  		"metricNamespace": autorest.Encode("query", metricNamespace),
   103  		"timespan":        autorest.Encode("query", timespan),
   104  	}
   105  
   106  	preparer := autorest.CreatePreparer(
   107  		autorest.AsGet(),
   108  		autorest.WithBaseURL(client.BaseURI),
   109  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/autoscalesettings/{autoscaleSettingName}/predictiveMetrics", pathParameters),
   110  		autorest.WithQueryParameters(queryParameters))
   111  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   112  }
   113  
   114  // GetSender sends the Get request. The method will close the
   115  // http.Response Body if it receives an error.
   116  func (client PredictiveMetricClient) GetSender(req *http.Request) (*http.Response, error) {
   117  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   118  }
   119  
   120  // GetResponder handles the response to the Get request. The method always
   121  // closes the http.Response Body.
   122  func (client PredictiveMetricClient) GetResponder(resp *http.Response) (result PredictiveResponse, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  

View as plain text