From fad263d8d0fa95e619140febe28d670948e66c7f Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Wed, 1 Jun 2022 19:34:35 +0000 Subject: [PATCH] Regenerate client from commit 35942efc of spec repo --- .apigentools-info | 8 +- .generator/schemas/v1/openapi.yaml | 158 +++++++++++ api/v1/datadog/api_metrics.go | 199 +++++++++++++ .../datadog/model_distribution_point_item.go | 155 ++++++++++ ...el_distribution_points_content_encoding.go | 107 +++++++ .../model_distribution_points_payload.go | 103 +++++++ .../model_distribution_points_series.go | 265 ++++++++++++++++++ .../datadog/model_distribution_points_type.go | 107 +++++++ .../v1/metrics/SubmitDistributionPoints.go | 47 ++++ .../SubmitDistributionPoints_3109558960.go | 47 ++++ tests/scenarios/features/v1/metrics.feature | 36 +++ tests/scenarios/features/v1/undo.json | 6 + 12 files changed, 1234 insertions(+), 4 deletions(-) create mode 100644 api/v1/datadog/model_distribution_point_item.go create mode 100644 api/v1/datadog/model_distribution_points_content_encoding.go create mode 100644 api/v1/datadog/model_distribution_points_payload.go create mode 100644 api/v1/datadog/model_distribution_points_series.go create mode 100644 api/v1/datadog/model_distribution_points_type.go create mode 100644 examples/v1/metrics/SubmitDistributionPoints.go create mode 100644 examples/v1/metrics/SubmitDistributionPoints_3109558960.go diff --git a/.apigentools-info b/.apigentools-info index 1e6255ad4d0..be54f2445ad 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.2", - "regenerated": "2022-06-01 08:09:47.329559", - "spec_repo_commit": "921d5a27" + "regenerated": "2022-06-01 19:33:40.360385", + "spec_repo_commit": "35942efc" }, "v2": { "apigentools_version": "1.6.2", - "regenerated": "2022-06-01 08:09:47.341885", - "spec_repo_commit": "921d5a27" + "regenerated": "2022-06-01 19:33:40.373169", + "spec_repo_commit": "35942efc" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 77973a8a69d..cfd382a0a16 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -1299,6 +1299,96 @@ components: type: integer readOnly: true type: object + DistributionPoint: + description: Array of distribution points. + example: + - 1575317847.0 + - - 0.5 + - 1.0 + items: + description: List of distribution point. + oneOf: + - $ref: '#/components/schemas/DistributionPointTimestamp' + - $ref: '#/components/schemas/DistributionPointData' + maxItems: 2 + minItems: 2 + type: array + DistributionPointData: + description: Distribution point data. + items: + description: List of distribution point data. + format: double + type: number + type: array + DistributionPointTimestamp: + description: Distribution point timestamp. It should be in seconds and current. + format: double + type: number + DistributionPointsContentEncoding: + description: HTTP header used to compress the media-type. + enum: + - deflate + type: string + x-enum-varnames: + - DEFLATE + DistributionPointsPayload: + description: The distribution points payload. + properties: + series: + description: A list of distribution points series to submit to Datadog. + example: + - metric: system.load.1 + points: + - - 1475317847.0 + - - 1.0 + - 2.0 + items: + $ref: '#/components/schemas/DistributionPointsSeries' + type: array + required: + - series + type: object + DistributionPointsSeries: + description: A distribution points metric to submit to Datadog. + properties: + host: + description: The name of the host that produced the distribution point metric. + example: test.example.com + type: string + metric: + description: The name of the distribution points metric. + example: system.load.1 + type: string + points: + description: Points relating to the distribution point metric. All points + must be tuples with timestamp and a list of values (cannot be a string). + Timestamps should be in POSIX time in seconds. + items: + $ref: '#/components/schemas/DistributionPoint' + type: array + tags: + description: A list of tags associated with the distribution point metric. + example: + - environment:test + items: + description: Individual tags. + type: string + type: array + type: + $ref: '#/components/schemas/DistributionPointsType' + required: + - metric + - points + type: object + DistributionPointsType: + default: distribution + description: The type of the distribution point. + enum: + - distribution + example: distribution + type: string + x-enum-varnames: + - DISTRIBUTION DistributionWidgetDefinition: description: "The Distribution visualization is another way of showing metrics\naggregated across one or several tags, such as hosts.\nUnlike the heat map, a distribution @@ -18017,6 +18107,74 @@ paths: x-menu-order: 6 x-undo: type: idempotent + /api/v1/distribution_points: + post: + description: "The distribution points end-point allows you to post distribution + data that can be graphed on Datadog\u2019s dashboards." + operationId: SubmitDistributionPoints + parameters: + - description: HTTP header used to compress the media-type. + in: header + name: Content-Encoding + required: false + schema: + $ref: '#/components/schemas/DistributionPointsContentEncoding' + requestBody: + content: + text/json: + examples: + dynamic-points: + description: "Post time-series data that can be graphed on Datadog\u2019s + dashboards." + externalValue: examples/metrics/distribution-points.json.sh + summary: Dynamic Points + x-variables: + NOW: $(date +%s) + schema: + $ref: '#/components/schemas/DistributionPointsPayload' + required: true + responses: + '202': + content: + text/json: + schema: + $ref: '#/components/schemas/IntakePayloadAccepted' + description: Payload accepted + '400': + content: + text/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Bad Request + '403': + content: + text/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Authentication error + '408': + content: + text/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Request timeout + '413': + content: + text/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Payload too large + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + summary: Submit distribution points + tags: + - Metrics + x-codegen-request-body-name: body + x-menu-order: 1 + x-undo: + type: safe /api/v1/downtime: get: description: Get all scheduled downtimes. diff --git a/api/v1/datadog/api_metrics.go b/api/v1/datadog/api_metrics.go index d595bd7f97f..24c3dfd5e23 100644 --- a/api/v1/datadog/api_metrics.go +++ b/api/v1/datadog/api_metrics.go @@ -674,6 +674,205 @@ func (a *MetricsApiService) queryMetricsExecute(r apiQueryMetricsRequest) (Metri return localVarReturnValue, localVarHTTPResponse, nil } +type apiSubmitDistributionPointsRequest struct { + ctx _context.Context + ApiService *MetricsApiService + body *DistributionPointsPayload + contentEncoding *DistributionPointsContentEncoding +} + +// SubmitDistributionPointsOptionalParameters holds optional parameters for SubmitDistributionPoints. +type SubmitDistributionPointsOptionalParameters struct { + ContentEncoding *DistributionPointsContentEncoding +} + +// NewSubmitDistributionPointsOptionalParameters creates an empty struct for parameters. +func NewSubmitDistributionPointsOptionalParameters() *SubmitDistributionPointsOptionalParameters { + this := SubmitDistributionPointsOptionalParameters{} + return &this +} + +// WithContentEncoding sets the corresponding parameter name and returns the struct. +func (r *SubmitDistributionPointsOptionalParameters) WithContentEncoding(contentEncoding DistributionPointsContentEncoding) *SubmitDistributionPointsOptionalParameters { + r.ContentEncoding = &contentEncoding + return r +} + +func (a *MetricsApiService) buildSubmitDistributionPointsRequest(ctx _context.Context, body DistributionPointsPayload, o ...SubmitDistributionPointsOptionalParameters) (apiSubmitDistributionPointsRequest, error) { + req := apiSubmitDistributionPointsRequest{ + ApiService: a, + ctx: ctx, + body: &body, + } + + if len(o) > 1 { + return req, reportError("only one argument of type SubmitDistributionPointsOptionalParameters is allowed") + } + + if o != nil { + req.contentEncoding = o[0].ContentEncoding + } + return req, nil +} + +// SubmitDistributionPoints Submit distribution points. +// The distribution points end-point allows you to post distribution data that can be graphed on Datadog’s dashboards. +func (a *MetricsApiService) SubmitDistributionPoints(ctx _context.Context, body DistributionPointsPayload, o ...SubmitDistributionPointsOptionalParameters) (IntakePayloadAccepted, *_nethttp.Response, error) { + req, err := a.buildSubmitDistributionPointsRequest(ctx, body, o...) + if err != nil { + var localVarReturnValue IntakePayloadAccepted + return localVarReturnValue, nil, err + } + + return req.ApiService.submitDistributionPointsExecute(req) +} + +// submitDistributionPointsExecute executes the request. +func (a *MetricsApiService) submitDistributionPointsExecute(r apiSubmitDistributionPointsRequest) (IntakePayloadAccepted, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue IntakePayloadAccepted + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MetricsApiService.SubmitDistributionPoints") + if err != nil { + return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/api/v1/distribution_points" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if r.body == nil { + return localVarReturnValue, nil, reportError("body is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"text/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"text/json", "application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + + if r.contentEncoding != nil { + localVarHeaderParams["Content-Encoding"] = parameterToString(*r.contentEncoding, "") + } + + // body params + localVarPostBody = r.body + if r.ctx != nil { + // API Key Authentication + if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { + if apiKey, ok := auth["apiKeyAuth"]; ok { + var key string + if apiKey.Prefix != "" { + key = apiKey.Prefix + " " + apiKey.Key + } else { + key = apiKey.Key + } + localVarHeaderParams["DD-API-KEY"] = key + } + } + } + req, err := a.client.PrepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v APIErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v APIErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 408 { + var v APIErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 413 { + var v APIErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + type apiSubmitMetricsRequest struct { ctx _context.Context ApiService *MetricsApiService diff --git a/api/v1/datadog/model_distribution_point_item.go b/api/v1/datadog/model_distribution_point_item.go new file mode 100644 index 00000000000..c33484d5f3a --- /dev/null +++ b/api/v1/datadog/model_distribution_point_item.go @@ -0,0 +1,155 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadog + +import ( + "encoding/json" +) + +// DistributionPointItem - List of distribution point. +type DistributionPointItem struct { + DistributionPointTimestamp *float64 + DistributionPointData *[]float64 + + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject interface{} +} + +// DistributionPointTimestampAsDistributionPointItem is a convenience function that returns float64 wrapped in DistributionPointItem. +func DistributionPointTimestampAsDistributionPointItem(v *float64) DistributionPointItem { + return DistributionPointItem{DistributionPointTimestamp: v} +} + +// DistributionPointDataAsDistributionPointItem is a convenience function that returns []float64 wrapped in DistributionPointItem. +func DistributionPointDataAsDistributionPointItem(v *[]float64) DistributionPointItem { + return DistributionPointItem{DistributionPointData: v} +} + +// UnmarshalJSON turns data into one of the pointers in the struct. +func (obj *DistributionPointItem) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into DistributionPointTimestamp + err = json.Unmarshal(data, &obj.DistributionPointTimestamp) + if err == nil { + if obj.DistributionPointTimestamp != nil { + jsonDistributionPointTimestamp, _ := json.Marshal(obj.DistributionPointTimestamp) + if string(jsonDistributionPointTimestamp) == "{}" { // empty struct + obj.DistributionPointTimestamp = nil + } else { + match++ + } + } else { + obj.DistributionPointTimestamp = nil + } + } else { + obj.DistributionPointTimestamp = nil + } + + // try to unmarshal data into DistributionPointData + err = json.Unmarshal(data, &obj.DistributionPointData) + if err == nil { + if obj.DistributionPointData != nil { + jsonDistributionPointData, _ := json.Marshal(obj.DistributionPointData) + if string(jsonDistributionPointData) == "{}" { // empty struct + obj.DistributionPointData = nil + } else { + match++ + } + } else { + obj.DistributionPointData = nil + } + } else { + obj.DistributionPointData = nil + } + + if match != 1 { // more than 1 match + // reset to nil + obj.DistributionPointTimestamp = nil + obj.DistributionPointData = nil + return json.Unmarshal(data, &obj.UnparsedObject) + } + return nil // exactly one match +} + +// MarshalJSON turns data from the first non-nil pointers in the struct to JSON. +func (obj DistributionPointItem) MarshalJSON() ([]byte, error) { + if obj.DistributionPointTimestamp != nil { + return json.Marshal(&obj.DistributionPointTimestamp) + } + + if obj.DistributionPointData != nil { + return json.Marshal(&obj.DistributionPointData) + } + + if obj.UnparsedObject != nil { + return json.Marshal(obj.UnparsedObject) + } + return nil, nil // no data in oneOf schemas +} + +// GetActualInstance returns the actual instance. +func (obj *DistributionPointItem) GetActualInstance() interface{} { + if obj.DistributionPointTimestamp != nil { + return obj.DistributionPointTimestamp + } + + if obj.DistributionPointData != nil { + return obj.DistributionPointData + } + + // all schemas are nil + return nil +} + +// NullableDistributionPointItem handles when a null is used for DistributionPointItem. +type NullableDistributionPointItem struct { + value *DistributionPointItem + isSet bool +} + +// Get returns the associated value. +func (v NullableDistributionPointItem) Get() *DistributionPointItem { + return v.value +} + +// Set changes the value and indicates it's been called. +func (v *NullableDistributionPointItem) Set(val *DistributionPointItem) { + v.value = val + v.isSet = true +} + +// IsSet returns whether Set has been called. +func (v NullableDistributionPointItem) IsSet() bool { + return v.isSet +} + +// Unset sets the value to nil and resets the set flag/ +func (v *NullableDistributionPointItem) Unset() { + v.value = nil + v.isSet = false +} + +// NewNullableDistributionPointItem initializes the struct as if Set has been called. +func NewNullableDistributionPointItem(val *DistributionPointItem) *NullableDistributionPointItem { + return &NullableDistributionPointItem{value: val, isSet: true} +} + +// MarshalJSON serializes the associated value. +func (v NullableDistributionPointItem) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called. +func (v *NullableDistributionPointItem) UnmarshalJSON(src []byte) error { + v.isSet = true + + // this object is nullable so check if the payload is null or empty string + if string(src) == "" || string(src) == "{}" { + return nil + } + + return json.Unmarshal(src, &v.value) +} diff --git a/api/v1/datadog/model_distribution_points_content_encoding.go b/api/v1/datadog/model_distribution_points_content_encoding.go new file mode 100644 index 00000000000..8b770b886ca --- /dev/null +++ b/api/v1/datadog/model_distribution_points_content_encoding.go @@ -0,0 +1,107 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadog + +import ( + "encoding/json" + "fmt" +) + +// DistributionPointsContentEncoding HTTP header used to compress the media-type. +type DistributionPointsContentEncoding string + +// List of DistributionPointsContentEncoding. +const ( + DISTRIBUTIONPOINTSCONTENTENCODING_DEFLATE DistributionPointsContentEncoding = "deflate" +) + +var allowedDistributionPointsContentEncodingEnumValues = []DistributionPointsContentEncoding{ + DISTRIBUTIONPOINTSCONTENTENCODING_DEFLATE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *DistributionPointsContentEncoding) GetAllowedValues() []DistributionPointsContentEncoding { + return allowedDistributionPointsContentEncodingEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *DistributionPointsContentEncoding) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + *v = DistributionPointsContentEncoding(value) + return nil +} + +// NewDistributionPointsContentEncodingFromValue returns a pointer to a valid DistributionPointsContentEncoding +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewDistributionPointsContentEncodingFromValue(v string) (*DistributionPointsContentEncoding, error) { + ev := DistributionPointsContentEncoding(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for DistributionPointsContentEncoding: valid values are %v", v, allowedDistributionPointsContentEncodingEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v DistributionPointsContentEncoding) IsValid() bool { + for _, existing := range allowedDistributionPointsContentEncodingEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to DistributionPointsContentEncoding value. +func (v DistributionPointsContentEncoding) Ptr() *DistributionPointsContentEncoding { + return &v +} + +// NullableDistributionPointsContentEncoding handles when a null is used for DistributionPointsContentEncoding. +type NullableDistributionPointsContentEncoding struct { + value *DistributionPointsContentEncoding + isSet bool +} + +// Get returns the associated value. +func (v NullableDistributionPointsContentEncoding) Get() *DistributionPointsContentEncoding { + return v.value +} + +// Set changes the value and indicates it's been called. +func (v *NullableDistributionPointsContentEncoding) Set(val *DistributionPointsContentEncoding) { + v.value = val + v.isSet = true +} + +// IsSet returns whether Set has been called. +func (v NullableDistributionPointsContentEncoding) IsSet() bool { + return v.isSet +} + +// Unset sets the value to nil and resets the set flag. +func (v *NullableDistributionPointsContentEncoding) Unset() { + v.value = nil + v.isSet = false +} + +// NewNullableDistributionPointsContentEncoding initializes the struct as if Set has been called. +func NewNullableDistributionPointsContentEncoding(val *DistributionPointsContentEncoding) *NullableDistributionPointsContentEncoding { + return &NullableDistributionPointsContentEncoding{value: val, isSet: true} +} + +// MarshalJSON serializes the associated value. +func (v NullableDistributionPointsContentEncoding) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called. +func (v *NullableDistributionPointsContentEncoding) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/v1/datadog/model_distribution_points_payload.go b/api/v1/datadog/model_distribution_points_payload.go new file mode 100644 index 00000000000..5264e294702 --- /dev/null +++ b/api/v1/datadog/model_distribution_points_payload.go @@ -0,0 +1,103 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadog + +import ( + "encoding/json" + "fmt" +) + +// DistributionPointsPayload The distribution points payload. +type DistributionPointsPayload struct { + // A list of distribution points series to submit to Datadog. + Series []DistributionPointsSeries `json:"series"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:-` + AdditionalProperties map[string]interface{} +} + +// NewDistributionPointsPayload instantiates a new DistributionPointsPayload object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewDistributionPointsPayload(series []DistributionPointsSeries) *DistributionPointsPayload { + this := DistributionPointsPayload{} + this.Series = series + return &this +} + +// NewDistributionPointsPayloadWithDefaults instantiates a new DistributionPointsPayload object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewDistributionPointsPayloadWithDefaults() *DistributionPointsPayload { + this := DistributionPointsPayload{} + return &this +} + +// GetSeries returns the Series field value. +func (o *DistributionPointsPayload) GetSeries() []DistributionPointsSeries { + if o == nil { + var ret []DistributionPointsSeries + return ret + } + return o.Series +} + +// GetSeriesOk returns a tuple with the Series field value +// and a boolean to check if the value has been set. +func (o *DistributionPointsPayload) GetSeriesOk() (*[]DistributionPointsSeries, bool) { + if o == nil { + return nil, false + } + return &o.Series, true +} + +// SetSeries sets field value. +func (o *DistributionPointsPayload) SetSeries(v []DistributionPointsSeries) { + o.Series = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DistributionPointsPayload) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return json.Marshal(o.UnparsedObject) + } + toSerialize["series"] = o.Series + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DistributionPointsPayload) UnmarshalJSON(bytes []byte) (err error) { + raw := map[string]interface{}{} + required := struct { + Series *[]DistributionPointsSeries `json:"series"` + }{} + all := struct { + Series []DistributionPointsSeries `json:"series"` + }{} + err = json.Unmarshal(bytes, &required) + if err != nil { + return err + } + if required.Series == nil { + return fmt.Errorf("Required field series missing") + } + err = json.Unmarshal(bytes, &all) + if err != nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + o.Series = all.Series + return nil +} diff --git a/api/v1/datadog/model_distribution_points_series.go b/api/v1/datadog/model_distribution_points_series.go new file mode 100644 index 00000000000..4874ff8e599 --- /dev/null +++ b/api/v1/datadog/model_distribution_points_series.go @@ -0,0 +1,265 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadog + +import ( + "encoding/json" + "fmt" +) + +// DistributionPointsSeries A distribution points metric to submit to Datadog. +type DistributionPointsSeries struct { + // The name of the host that produced the distribution point metric. + Host *string `json:"host,omitempty"` + // The name of the distribution points metric. + Metric string `json:"metric"` + // Points relating to the distribution point metric. All points must be tuples with timestamp and a list of values (cannot be a string). Timestamps should be in POSIX time in seconds. + Points [][]DistributionPointItem `json:"points"` + // A list of tags associated with the distribution point metric. + Tags []string `json:"tags,omitempty"` + // The type of the distribution point. + Type *DistributionPointsType `json:"type,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:-` + AdditionalProperties map[string]interface{} +} + +// NewDistributionPointsSeries instantiates a new DistributionPointsSeries object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewDistributionPointsSeries(metric string, points [][]DistributionPointItem) *DistributionPointsSeries { + this := DistributionPointsSeries{} + this.Metric = metric + this.Points = points + var typeVar DistributionPointsType = DISTRIBUTIONPOINTSTYPE_DISTRIBUTION + this.Type = &typeVar + return &this +} + +// NewDistributionPointsSeriesWithDefaults instantiates a new DistributionPointsSeries object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewDistributionPointsSeriesWithDefaults() *DistributionPointsSeries { + this := DistributionPointsSeries{} + var typeVar DistributionPointsType = DISTRIBUTIONPOINTSTYPE_DISTRIBUTION + this.Type = &typeVar + return &this +} + +// GetHost returns the Host field value if set, zero value otherwise. +func (o *DistributionPointsSeries) GetHost() string { + if o == nil || o.Host == nil { + var ret string + return ret + } + return *o.Host +} + +// GetHostOk returns a tuple with the Host field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DistributionPointsSeries) GetHostOk() (*string, bool) { + if o == nil || o.Host == nil { + return nil, false + } + return o.Host, true +} + +// HasHost returns a boolean if a field has been set. +func (o *DistributionPointsSeries) HasHost() bool { + if o != nil && o.Host != nil { + return true + } + + return false +} + +// SetHost gets a reference to the given string and assigns it to the Host field. +func (o *DistributionPointsSeries) SetHost(v string) { + o.Host = &v +} + +// GetMetric returns the Metric field value. +func (o *DistributionPointsSeries) GetMetric() string { + if o == nil { + var ret string + return ret + } + return o.Metric +} + +// GetMetricOk returns a tuple with the Metric field value +// and a boolean to check if the value has been set. +func (o *DistributionPointsSeries) GetMetricOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Metric, true +} + +// SetMetric sets field value. +func (o *DistributionPointsSeries) SetMetric(v string) { + o.Metric = v +} + +// GetPoints returns the Points field value. +func (o *DistributionPointsSeries) GetPoints() [][]DistributionPointItem { + if o == nil { + var ret [][]DistributionPointItem + return ret + } + return o.Points +} + +// GetPointsOk returns a tuple with the Points field value +// and a boolean to check if the value has been set. +func (o *DistributionPointsSeries) GetPointsOk() (*[][]DistributionPointItem, bool) { + if o == nil { + return nil, false + } + return &o.Points, true +} + +// SetPoints sets field value. +func (o *DistributionPointsSeries) SetPoints(v [][]DistributionPointItem) { + o.Points = v +} + +// GetTags returns the Tags field value if set, zero value otherwise. +func (o *DistributionPointsSeries) GetTags() []string { + if o == nil || o.Tags == nil { + var ret []string + return ret + } + return o.Tags +} + +// GetTagsOk returns a tuple with the Tags field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DistributionPointsSeries) GetTagsOk() (*[]string, bool) { + if o == nil || o.Tags == nil { + return nil, false + } + return &o.Tags, true +} + +// HasTags returns a boolean if a field has been set. +func (o *DistributionPointsSeries) HasTags() bool { + if o != nil && o.Tags != nil { + return true + } + + return false +} + +// SetTags gets a reference to the given []string and assigns it to the Tags field. +func (o *DistributionPointsSeries) SetTags(v []string) { + o.Tags = v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *DistributionPointsSeries) GetType() DistributionPointsType { + if o == nil || o.Type == nil { + var ret DistributionPointsType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DistributionPointsSeries) GetTypeOk() (*DistributionPointsType, bool) { + if o == nil || o.Type == nil { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *DistributionPointsSeries) HasType() bool { + if o != nil && o.Type != nil { + return true + } + + return false +} + +// SetType gets a reference to the given DistributionPointsType and assigns it to the Type field. +func (o *DistributionPointsSeries) SetType(v DistributionPointsType) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DistributionPointsSeries) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return json.Marshal(o.UnparsedObject) + } + if o.Host != nil { + toSerialize["host"] = o.Host + } + toSerialize["metric"] = o.Metric + toSerialize["points"] = o.Points + if o.Tags != nil { + toSerialize["tags"] = o.Tags + } + if o.Type != nil { + toSerialize["type"] = o.Type + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DistributionPointsSeries) UnmarshalJSON(bytes []byte) (err error) { + raw := map[string]interface{}{} + required := struct { + Metric *string `json:"metric"` + Points *[][]DistributionPointItem `json:"points"` + }{} + all := struct { + Host *string `json:"host,omitempty"` + Metric string `json:"metric"` + Points [][]DistributionPointItem `json:"points"` + Tags []string `json:"tags,omitempty"` + Type *DistributionPointsType `json:"type,omitempty"` + }{} + err = json.Unmarshal(bytes, &required) + if err != nil { + return err + } + if required.Metric == nil { + return fmt.Errorf("Required field metric missing") + } + if required.Points == nil { + return fmt.Errorf("Required field points missing") + } + err = json.Unmarshal(bytes, &all) + if err != nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + if v := all.Type; v != nil && !v.IsValid() { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + o.Host = all.Host + o.Metric = all.Metric + o.Points = all.Points + o.Tags = all.Tags + o.Type = all.Type + return nil +} diff --git a/api/v1/datadog/model_distribution_points_type.go b/api/v1/datadog/model_distribution_points_type.go new file mode 100644 index 00000000000..08ed0979b9d --- /dev/null +++ b/api/v1/datadog/model_distribution_points_type.go @@ -0,0 +1,107 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadog + +import ( + "encoding/json" + "fmt" +) + +// DistributionPointsType The type of the distribution point. +type DistributionPointsType string + +// List of DistributionPointsType. +const ( + DISTRIBUTIONPOINTSTYPE_DISTRIBUTION DistributionPointsType = "distribution" +) + +var allowedDistributionPointsTypeEnumValues = []DistributionPointsType{ + DISTRIBUTIONPOINTSTYPE_DISTRIBUTION, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *DistributionPointsType) GetAllowedValues() []DistributionPointsType { + return allowedDistributionPointsTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *DistributionPointsType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + *v = DistributionPointsType(value) + return nil +} + +// NewDistributionPointsTypeFromValue returns a pointer to a valid DistributionPointsType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewDistributionPointsTypeFromValue(v string) (*DistributionPointsType, error) { + ev := DistributionPointsType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for DistributionPointsType: valid values are %v", v, allowedDistributionPointsTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v DistributionPointsType) IsValid() bool { + for _, existing := range allowedDistributionPointsTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to DistributionPointsType value. +func (v DistributionPointsType) Ptr() *DistributionPointsType { + return &v +} + +// NullableDistributionPointsType handles when a null is used for DistributionPointsType. +type NullableDistributionPointsType struct { + value *DistributionPointsType + isSet bool +} + +// Get returns the associated value. +func (v NullableDistributionPointsType) Get() *DistributionPointsType { + return v.value +} + +// Set changes the value and indicates it's been called. +func (v *NullableDistributionPointsType) Set(val *DistributionPointsType) { + v.value = val + v.isSet = true +} + +// IsSet returns whether Set has been called. +func (v NullableDistributionPointsType) IsSet() bool { + return v.isSet +} + +// Unset sets the value to nil and resets the set flag. +func (v *NullableDistributionPointsType) Unset() { + v.value = nil + v.isSet = false +} + +// NewNullableDistributionPointsType initializes the struct as if Set has been called. +func NewNullableDistributionPointsType(val *DistributionPointsType) *NullableDistributionPointsType { + return &NullableDistributionPointsType{value: val, isSet: true} +} + +// MarshalJSON serializes the associated value. +func (v NullableDistributionPointsType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called. +func (v *NullableDistributionPointsType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/examples/v1/metrics/SubmitDistributionPoints.go b/examples/v1/metrics/SubmitDistributionPoints.go new file mode 100644 index 00000000000..6856608b724 --- /dev/null +++ b/examples/v1/metrics/SubmitDistributionPoints.go @@ -0,0 +1,47 @@ +// Submit distribution points returns "Payload accepted" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.DistributionPointsPayload{ + Series: []datadog.DistributionPointsSeries{ + { + Metric: "system.load.1.dist", + Points: [][]datadog.DistributionPointItem{ + { + { + + DistributionPointTimestamp: datadog.PtrFloat64(float64(time.Now().Unix())), + + DistributionPointData: &[]float64{ + 1.0, + 2.0, + }, + }}, + }, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.MetricsApi.SubmitDistributionPoints(ctx, body, *datadog.NewSubmitDistributionPointsOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MetricsApi.SubmitDistributionPoints`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MetricsApi.SubmitDistributionPoints`:\n%s\n", responseContent) +} diff --git a/examples/v1/metrics/SubmitDistributionPoints_3109558960.go b/examples/v1/metrics/SubmitDistributionPoints_3109558960.go new file mode 100644 index 00000000000..2127d3ac61c --- /dev/null +++ b/examples/v1/metrics/SubmitDistributionPoints_3109558960.go @@ -0,0 +1,47 @@ +// Submit deflate distribution points returns "Payload accepted" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.DistributionPointsPayload{ + Series: []datadog.DistributionPointsSeries{ + { + Metric: "system.load.1.dist", + Points: [][]datadog.DistributionPointItem{ + { + { + + DistributionPointTimestamp: datadog.PtrFloat64(float64(time.Now().Unix())), + + DistributionPointData: &[]float64{ + 1.0, + 2.0, + }, + }}, + }, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.MetricsApi.SubmitDistributionPoints(ctx, body, *datadog.NewSubmitDistributionPointsOptionalParameters().WithContentEncoding(datadog.DISTRIBUTIONPOINTSCONTENTENCODING_DEFLATE)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MetricsApi.SubmitDistributionPoints`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MetricsApi.SubmitDistributionPoints`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/features/v1/metrics.feature b/tests/scenarios/features/v1/metrics.feature index 83ce8b87d0f..c4ba8c3c458 100644 --- a/tests/scenarios/features/v1/metrics.feature +++ b/tests/scenarios/features/v1/metrics.feature @@ -108,6 +108,14 @@ Feature: Metrics When the request is sent Then the response status is 200 OK + @integration-only @skip-terraform-config @skip-validation @team:DataDog/metrics-aggregation + Scenario: Submit deflate distribution points returns "Payload accepted" response + Given new "SubmitDistributionPoints" request + And body with value {"series": [{"metric": "system.load.1.dist", "points": [[{{ timestamp("now") }}, [1.0, 2.0]]]}]} + And request contains "Content-Encoding" parameter with value "deflate" + When the request is sent + Then the response status is 202 Payload accepted + @integration-only @skip-terraform-config @skip-validation @team:DataDog/metrics-intake @team:DataDog/metrics-query Scenario: Submit deflate metrics returns "Payload accepted" response Given new "SubmitMetrics" request @@ -116,6 +124,34 @@ Feature: Metrics When the request is sent Then the response status is 202 Payload accepted + @integration-only @skip-terraform-config @skip-validation @team:DataDog/metrics-aggregation + Scenario: Submit distribution points returns "Bad Request" response + Given new "SubmitDistributionPoints" request + And body with value {"series": [{"metric": "system.load.1.dist", "points": [[1475317847.0, 1.0]]}]} + When the request is sent + Then the response status is 400 Bad Request + + @integration-only @skip-terraform-config @skip-validation @team:DataDog/metrics-aggregation + Scenario: Submit distribution points returns "Payload accepted" response + Given new "SubmitDistributionPoints" request + And body with value {"series": [{"metric": "system.load.1.dist", "points": [[{{ timestamp("now") }}, [1.0, 2.0]]]}]} + When the request is sent + Then the response status is 202 Payload accepted + + @generated @skip @team:DataDog/metrics-aggregation + Scenario: Submit distribution points returns "Payload too large" response + Given new "SubmitDistributionPoints" request + And body with value {"series": [{"metric": "system.load.1", "points": [[1475317847.0, [1.0, 2.0]]]}]} + When the request is sent + Then the response status is 413 Payload too large + + @generated @skip @team:DataDog/metrics-aggregation + Scenario: Submit distribution points returns "Request timeout" response + Given new "SubmitDistributionPoints" request + And body with value {"series": [{"metric": "system.load.1", "points": [[1475317847.0, [1.0, 2.0]]]}]} + When the request is sent + Then the response status is 408 Request timeout + @skip @team:DataDog/metrics-intake @team:DataDog/metrics-query Scenario: Submit metrics returns "Bad Request" response Given new "SubmitMetrics" request diff --git a/tests/scenarios/features/v1/undo.json b/tests/scenarios/features/v1/undo.json index 8beccafa24e..5395670714a 100644 --- a/tests/scenarios/features/v1/undo.json +++ b/tests/scenarios/features/v1/undo.json @@ -183,6 +183,12 @@ "type": "idempotent" } }, + "SubmitDistributionPoints": { + "tag": "Metrics", + "undo": { + "type": "safe" + } + }, "ListDowntimes": { "tag": "Downtimes", "undo": {