...

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

View as plain text