...

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

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

     1  package metrics
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // BaselinesClient is the monitor Management Client
    18  type BaselinesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewBaselinesClient creates an instance of the BaselinesClient client.
    23  func NewBaselinesClient(subscriptionID string) BaselinesClient {
    24  	return NewBaselinesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewBaselinesClientWithBaseURI creates an instance of the BaselinesClient client using a custom endpoint.  Use this
    28  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewBaselinesClientWithBaseURI(baseURI string, subscriptionID string) BaselinesClient {
    30  	return BaselinesClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // List **Lists the metric baseline values for a resource**.
    34  // Parameters:
    35  // resourceURI - the identifier of the resource.
    36  // metricnames - the names of the metrics (comma separated) to retrieve.
    37  // metricnamespace - metric namespace where the metrics you want reside.
    38  // timespan - the timespan of the query. It is a string with the following format
    39  // 'startDateTime_ISO/endDateTime_ISO'.
    40  // interval - the interval (i.e. timegrain) of the query.
    41  // aggregation - the list of aggregation types (comma separated) to retrieve.
    42  // sensitivities - the list of sensitivities (comma separated) to retrieve.
    43  // filter - the **$filter** is used to reduce the set of metric data returned. Example: Metric contains
    44  // metadata A, B and C. - Return all time series of C where A = a1 and B = b1 or b2 **$filter=A eq 'a1' and B
    45  // eq 'b1' or B eq 'b2' and C eq '*'** - Invalid variant: **$filter=A eq 'a1' and B eq 'b1' and C eq '*' or B =
    46  // 'b2'** This is invalid because the logical or operator cannot separate two different metadata names. -
    47  // Return all time series where A = a1, B = b1 and C = c1: **$filter=A eq 'a1' and B eq 'b1' and C eq 'c1'** -
    48  // Return all time series where A = a1 **$filter=A eq 'a1' and B eq '*' and C eq '*'**. Special case: When
    49  // dimension name or dimension value uses round brackets. Eg: When dimension name is **dim (test) 1** Instead
    50  // of using $filter= "dim (test) 1 eq '*' " use **$filter= "dim %2528test%2529 1 eq '*' "** When dimension name
    51  // is **dim (test) 3** and dimension value is **dim3 (test) val** Instead of using $filter= "dim (test) 3 eq
    52  // 'dim3 (test) val' " use **$filter= "dim %2528test%2529 3 eq 'dim3 %2528test%2529 val' "**
    53  // resultType - allows retrieving only metadata of the baseline. On data request all information is retrieved.
    54  func (client BaselinesClient) List(ctx context.Context, resourceURI string, metricnames string, metricnamespace string, timespan string, interval *string, aggregation string, sensitivities string, filter string, resultType ResultType) (result BaselinesResponse, err error) {
    55  	if tracing.IsEnabled() {
    56  		ctx = tracing.StartSpan(ctx, fqdn+"/BaselinesClient.List")
    57  		defer func() {
    58  			sc := -1
    59  			if result.Response.Response != nil {
    60  				sc = result.Response.Response.StatusCode
    61  			}
    62  			tracing.EndSpan(ctx, sc, err)
    63  		}()
    64  	}
    65  	req, err := client.ListPreparer(ctx, resourceURI, metricnames, metricnamespace, timespan, interval, aggregation, sensitivities, filter, resultType)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "metrics.BaselinesClient", "List", nil, "Failure preparing request")
    68  		return
    69  	}
    70  
    71  	resp, err := client.ListSender(req)
    72  	if err != nil {
    73  		result.Response = autorest.Response{Response: resp}
    74  		err = autorest.NewErrorWithError(err, "metrics.BaselinesClient", "List", resp, "Failure sending request")
    75  		return
    76  	}
    77  
    78  	result, err = client.ListResponder(resp)
    79  	if err != nil {
    80  		err = autorest.NewErrorWithError(err, "metrics.BaselinesClient", "List", resp, "Failure responding to request")
    81  		return
    82  	}
    83  
    84  	return
    85  }
    86  
    87  // ListPreparer prepares the List request.
    88  func (client BaselinesClient) ListPreparer(ctx context.Context, resourceURI string, metricnames string, metricnamespace string, timespan string, interval *string, aggregation string, sensitivities string, filter string, resultType ResultType) (*http.Request, error) {
    89  	pathParameters := map[string]interface{}{
    90  		"resourceUri": resourceURI,
    91  	}
    92  
    93  	const APIVersion = "2019-03-01"
    94  	queryParameters := map[string]interface{}{
    95  		"api-version": APIVersion,
    96  	}
    97  	if len(metricnames) > 0 {
    98  		queryParameters["metricnames"] = autorest.Encode("query", metricnames)
    99  	}
   100  	if len(metricnamespace) > 0 {
   101  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
   102  	}
   103  	if len(timespan) > 0 {
   104  		queryParameters["timespan"] = autorest.Encode("query", timespan)
   105  	}
   106  	if interval != nil {
   107  		queryParameters["interval"] = autorest.Encode("query", *interval)
   108  	}
   109  	if len(aggregation) > 0 {
   110  		queryParameters["aggregation"] = autorest.Encode("query", aggregation)
   111  	}
   112  	if len(sensitivities) > 0 {
   113  		queryParameters["sensitivities"] = autorest.Encode("query", sensitivities)
   114  	}
   115  	if len(filter) > 0 {
   116  		queryParameters["$filter"] = autorest.Encode("query", filter)
   117  	}
   118  	if len(string(resultType)) > 0 {
   119  		queryParameters["resultType"] = autorest.Encode("query", resultType)
   120  	}
   121  
   122  	preparer := autorest.CreatePreparer(
   123  		autorest.AsGet(),
   124  		autorest.WithBaseURL(client.BaseURI),
   125  		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metricBaselines", pathParameters),
   126  		autorest.WithQueryParameters(queryParameters))
   127  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   128  }
   129  
   130  // ListSender sends the List request. The method will close the
   131  // http.Response Body if it receives an error.
   132  func (client BaselinesClient) ListSender(req *http.Request) (*http.Response, error) {
   133  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   134  }
   135  
   136  // ListResponder handles the response to the List request. The method always
   137  // closes the http.Response Body.
   138  func (client BaselinesClient) ListResponder(resp *http.Response) (result BaselinesResponse, err error) {
   139  	err = autorest.Respond(
   140  		resp,
   141  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   142  		autorest.ByUnmarshallingJSON(&result),
   143  		autorest.ByClosing())
   144  	result.Response = autorest.Response{Response: resp}
   145  	return
   146  }
   147  

View as plain text