Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
783 changes: 783 additions & 0 deletions .generator/schemas/v2/openapi.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Investigate a timeseries anomaly returns "OK" response
*/

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
configuration.unstableOperations["v2.createTimeseriesAnomalyInvestigation"] =
true;
const apiInstance = new v2.TimeseriesAnomalyInvestigationsApi(configuration);

const params: v2.TimeseriesAnomalyInvestigationsApiCreateTimeseriesAnomalyInvestigationRequest =
{
body: {
data: {
attributes: {
requests: [
{
formulas: [
{
formula: "anomalies(query1, 'agile', 3)",
},
],
from: 1754406000000,
queries: [
{
dataSource: "metrics",
name: "query1",
query: "avg:system.cpu.user{env:prod} by {service}",
},
],
to: 1754423940000,
},
],
},
type: "timeseries_anomaly_investigation",
},
},
};

apiInstance
.createTimeseriesAnomalyInvestigation(params)
.then((data: v2.TimeseriesAnomalyInvestigationResponse) => {
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
})
.catch((error: any) => console.error(error));
7 changes: 7 additions & 0 deletions features/support/scenarios_model_mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18837,6 +18837,13 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
},
"operationResponseType": "UserTeamsResponse",
},
"v2.CreateTimeseriesAnomalyInvestigation": {
"body": {
"type": "TimeseriesAnomalyInvestigationRequest",
"format": "",
},
"operationResponseType": "TimeseriesAnomalyInvestigationResponse",
},
"v2.ListUserAuthorizedClients": {
"pageSize": {
"type": "number",
Expand Down
32 changes: 32 additions & 0 deletions features/v2/timeseries_anomaly_investigations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@endpoint(timeseries-anomaly-investigations) @endpoint(timeseries-anomaly-investigations-v2)
Feature: Timeseries Anomaly Investigations
Investigate metrics timeseries anomalies and return deterministic
findings.

Background:
Given a valid "apiKeyAuth" key in the system
And a valid "appKeyAuth" key in the system
And an instance of "TimeseriesAnomalyInvestigations" API
And operation "CreateTimeseriesAnomalyInvestigation" enabled
And new "CreateTimeseriesAnomalyInvestigation" request
And body with value {"data": {"attributes": {"requests": [{"formulas": [{"formula": "anomalies(query1, 'agile', 3)"}], "from": 1754406000000, "queries": [{"data_source": "metrics", "name": "query1", "query": "avg:system.cpu.user{env:prod} by {service}"}], "to": 1754423940000}]}, "type": "timeseries_anomaly_investigation"}}

@generated @skip @team:DataDog/dataviz-backend-maintainers
Scenario: Investigate a timeseries anomaly returns "Bad Request" response
When the request is sent
Then the response status is 400 Bad Request

@generated @skip @team:DataDog/dataviz-backend-maintainers
Scenario: Investigate a timeseries anomaly returns "OK" response
When the request is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/dataviz-backend-maintainers
Scenario: Investigate a timeseries anomaly returns "Payload Too Large" response
When the request is sent
Then the response status is 413 Payload Too Large

@generated @skip @team:DataDog/dataviz-backend-maintainers
Scenario: Investigate a timeseries anomaly returns "Unprocessable Entity" response
When the request is sent
Then the response status is 422 Unprocessable Entity
6 changes: 6 additions & 0 deletions features/v2/undo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10259,6 +10259,12 @@
"type": "safe"
}
},
"CreateTimeseriesAnomalyInvestigation": {
"tag": "Timeseries Anomaly Investigations",
"undo": {
"type": "safe"
}
},
"GetTraceByID": {
"tag": "APM Trace",
"undo": {
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-api-client-common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ export function createConfiguration(
"v2.addMemberTeam": false,
"v2.listMemberTeams": false,
"v2.removeMemberTeam": false,
"v2.createTimeseriesAnomalyInvestigation": false,
"v2.createWebIntegrationAccount": false,
"v2.deleteWebIntegrationAccount": false,
"v2.getWebIntegrationAccount": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import {
BaseAPIRequestFactory,
RequiredError,
} from "../../datadog-api-client-common/baseapi";
import {
Configuration,
applySecurityAuthentication,
} from "../../datadog-api-client-common/configuration";
import {
RequestContext,
HttpMethod,
ResponseContext,
} from "../../datadog-api-client-common/http/http";

import { logger } from "../../../logger";
import { ObjectSerializer } from "../models/ObjectSerializer";
import { ApiException } from "../../datadog-api-client-common/exception";

import { APIErrorResponse } from "../models/APIErrorResponse";
import { JSONAPIErrorResponse } from "../models/JSONAPIErrorResponse";
import { TimeseriesAnomalyInvestigationRequest } from "../models/TimeseriesAnomalyInvestigationRequest";
import { TimeseriesAnomalyInvestigationResponse } from "../models/TimeseriesAnomalyInvestigationResponse";

export class TimeseriesAnomalyInvestigationsApiRequestFactory extends BaseAPIRequestFactory {
public async createTimeseriesAnomalyInvestigation(
body: TimeseriesAnomalyInvestigationRequest,
_options?: Configuration
): Promise<RequestContext> {
const _config = _options || this.configuration;

logger.warn(
"Using unstable operation 'createTimeseriesAnomalyInvestigation'"
);
if (
!_config.unstableOperations["v2.createTimeseriesAnomalyInvestigation"]
) {
throw new Error(
"Unstable operation 'createTimeseriesAnomalyInvestigation' is disabled"
);
}

// verify required parameter 'body' is not null or undefined
if (body === null || body === undefined) {
throw new RequiredError("body", "createTimeseriesAnomalyInvestigation");
}

// Path Params
const localVarPath = "/api/v2/timeseries-anomaly-investigations";

// Make Request Context
const requestContext = _config
.getServer(
"v2.TimeseriesAnomalyInvestigationsApi.createTimeseriesAnomalyInvestigation"
)
.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);

// Set IaC header
if (_config.isIaC) {
requestContext.setHeaderParam("X-Datadog-Managed-By", "iac");
}

// Body Params
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json",
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(
body,
"TimeseriesAnomalyInvestigationRequest",
""
),
contentType
);
requestContext.setBody(serializedBody);

// Apply auth methods
applySecurityAuthentication(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
"AuthZ",
]);

return requestContext;
}
}

export class TimeseriesAnomalyInvestigationsApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to createTimeseriesAnomalyInvestigation
* @throws ApiException if the response code was not in [200, 299]
*/
public async createTimeseriesAnomalyInvestigation(
response: ResponseContext
): Promise<TimeseriesAnomalyInvestigationResponse> {
const contentType = ObjectSerializer.normalizeMediaType(
response.headers["content-type"]
);
if (response.httpStatusCode === 200) {
const body: TimeseriesAnomalyInvestigationResponse =
ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"TimeseriesAnomalyInvestigationResponse"
) as TimeseriesAnomalyInvestigationResponse;
return body;
}
if (
response.httpStatusCode === 400 ||
response.httpStatusCode === 401 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 413 ||
response.httpStatusCode === 422
) {
const bodyText = ObjectSerializer.parse(
await response.body.text(),
contentType
);
let body: JSONAPIErrorResponse;
try {
body = ObjectSerializer.deserialize(
bodyText,
"JSONAPIErrorResponse"
) as JSONAPIErrorResponse;
} catch (error) {
logger.debug(`Got error deserializing error: ${error}`);
throw new ApiException<JSONAPIErrorResponse>(
response.httpStatusCode,
bodyText
);
}
throw new ApiException<JSONAPIErrorResponse>(
response.httpStatusCode,
body
);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer.parse(
await response.body.text(),
contentType
);
let body: APIErrorResponse;
try {
body = ObjectSerializer.deserialize(
bodyText,
"APIErrorResponse"
) as APIErrorResponse;
} catch (error) {
logger.debug(`Got error deserializing error: ${error}`);
throw new ApiException<APIErrorResponse>(
response.httpStatusCode,
bodyText
);
}
throw new ApiException<APIErrorResponse>(response.httpStatusCode, body);
}

// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: TimeseriesAnomalyInvestigationResponse =
ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"TimeseriesAnomalyInvestigationResponse",
""
) as TimeseriesAnomalyInvestigationResponse;
return body;
}

const body = (await response.body.text()) || "";
throw new ApiException<string>(
response.httpStatusCode,
'Unknown API Status Code!\nBody: "' + body + '"'
);
}
}

export interface TimeseriesAnomalyInvestigationsApiCreateTimeseriesAnomalyInvestigationRequest {
/**
* Metrics timeseries request to investigate. The request body must not exceed 2 MiB.
* @type TimeseriesAnomalyInvestigationRequest
*/
body: TimeseriesAnomalyInvestigationRequest;
}

export class TimeseriesAnomalyInvestigationsApi {
private requestFactory: TimeseriesAnomalyInvestigationsApiRequestFactory;
private responseProcessor: TimeseriesAnomalyInvestigationsApiResponseProcessor;
private configuration: Configuration;

public constructor(
configuration: Configuration,
requestFactory?: TimeseriesAnomalyInvestigationsApiRequestFactory,
responseProcessor?: TimeseriesAnomalyInvestigationsApiResponseProcessor
) {
this.configuration = configuration;
this.requestFactory =
requestFactory ||
new TimeseriesAnomalyInvestigationsApiRequestFactory(configuration);
this.responseProcessor =
responseProcessor ||
new TimeseriesAnomalyInvestigationsApiResponseProcessor();
}

/**
* Investigates a metrics timeseries request for its most significant anomaly and returns deterministic findings.
* Metrics queries with or without grouping are supported. This API version accepts exactly one request and returns at most one anomaly.
* @param param The request object
*/
public createTimeseriesAnomalyInvestigation(
param: TimeseriesAnomalyInvestigationsApiCreateTimeseriesAnomalyInvestigationRequest,
options?: Configuration
): Promise<TimeseriesAnomalyInvestigationResponse> {
const requestContextPromise =
this.requestFactory.createTimeseriesAnomalyInvestigation(
param.body,
options
);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.createTimeseriesAnomalyInvestigation(
responseContext
);
});
});
}
}
Loading
Loading