Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mvad update #23434

Merged
merged 5 commits into from
Apr 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ApiVersion": "v1.1",
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "{API key}",
"body": {
"options": {
"series": [
{
"timestamp": "2017-01-01T06:45:00Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "{API key}",
"modelId": "45aad126-aafd-11ea-b8fb-d89ef3400c5f",
"body": {
"options": {
"dataSource": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv",
"topContributorCount": 10,
"startTime": "2019-04-01T00:15:00Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ApiVersion": "v1.1",
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "{API key}",
"body": {
"options": {
"series": [
{
"timestamp": "1972-01-01T00:00:00Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ApiVersion": "v1.1",
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "{API key}",
"body": {
"options": {
"series": [
{
"timestamp": "1972-01-01T00:00:00Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "{API key}",
"modelId": "45aad126-aafd-11ea-b8fb-d89ef3400c5f",
"body": {
"options": {
"variables": [
{
"variable": "Variable_1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ApiVersion": "v1.1",
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "{API key}",
"body": {
"modelInfo": {
"slidingWindow": 20,
"alignPolicy": {
"alignMode": "Outer",
Expand Down
5 changes: 4 additions & 1 deletion specification/cognitiveservices/AnomalyDetector/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using TypeSpec.Versioning;

@versioned(APIVersion)
@service({title: "Anomaly Detector"})
@useAuth(ApiKeyAuth<ApiKeyLocation.header, "Ocp-Apim-Subscription-Key">)
@useAuth(AnomalyDetectorApiKeyAuth)
mikekistler marked this conversation as resolved.
Show resolved Hide resolved
@server(
"{Endpoint}/anomalydetector/{ApiVersion}",
"The Anomaly Detector API detects anomalies automatically in time series data. It supports two kinds of mode, one is for stateless using, another is for stateful using. In stateless mode, there are three functionalities. Entire Detect is for detecting the whole series with model trained by the time series, Last Detect is detecting last point with model trained by points before. ChangePoint Detect is for detecting trend changes in time series. In stateful mode, user can store time series, the stored time series will be used for detection anomalies. Under this mode, user can still use the above three functionalities by only giving a time range without preparing time series in client side. Besides the above three functionalities, stateful model also provide group based detection and labeling service. By leveraging labeling service user can provide labels for each detection result, these labels will be used for retuning or regenerating detection models. Inconsistency detection is a kind of group based detection, this detection will find inconsistency ones in a set of time series. By using anomaly detector service, business customers can discover incidents and establish a logic flow for root cause analysis.",
Expand Down Expand Up @@ -46,6 +46,9 @@ discover incidents and establish a logic flow for root cause analysis.
""")
namespace AnomalyDetector;

@doc("The secret key for your Azure Cognitive Services subscription.")
model AnomalyDetectorApiKeyAuth is ApiKeyAuth<ApiKeyLocation.header, "Ocp-Apim-Subscription-Key">;

enum APIVersion {
v1_1: "v1.1",
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum FillNAMethod {
"Fixed",
}

@fixed
enum MultivariateBatchDetectionStatus {
Created: "CREATED",
Running: "RUNNING",
Expand All @@ -33,13 +32,11 @@ enum DataSchema {
"MultiTable",
}

@fixed
enum AlignMode {
"Inner",
"Outer",
}

@fixed
enum ModelStatus {
Created: "CREATED",
Running: "RUNNING",
Expand All @@ -50,8 +47,8 @@ enum ModelStatus {
@doc("Detection results for the resultId value.")
@resource("multivariate/detect-batch")
model MultivariateDetectionResult {
#suppress "@azure-tools/typespec-azure-core/key-visibility-required" "Properties in response-only schemas should not be marked readOnly"
mikekistler marked this conversation as resolved.
Show resolved Hide resolved
@doc("Result identifier that's used to fetch the results of an inference call.")
@visibility("read")
@key
@format("uuid")
resultId: string;
Expand Down Expand Up @@ -96,6 +93,7 @@ model VariableState {
@doc("Variable name in variable states.")
variable?: string;

#suppress "@azure-tools/typespec-azure-core/casing-style" "Service uppercases common acronyms like NA."
@doc("Proportion of missing values that need to be filled by fillNAMethod.")
@minValue(0.0)
@maxValue(1.0)
Expand Down Expand Up @@ -245,13 +243,15 @@ detect whether the time stamp is an anomaly or not.
alignPolicy?: AlignPolicy;

@doc("Model status.")
@visibility("read")
status?: ModelStatus;

@visibility("read")
@doc("Error messages after failure to create a model.")
@visibility("read")
errors?: ErrorResponse[];

@doc("Diagnostics information to help inspect the states of a model or variable.")
@visibility("read")
diagnosticsInfo?: DiagnosticsInfo;
}

Expand All @@ -263,6 +263,7 @@ time range.
""")
alignMode?: AlignMode;

#suppress "@azure-tools/typespec-azure-core/casing-style" "Service uppercases common acronyms like NA."
@doc("""
Field that indicates how missing values will be filled.
""")
Expand Down Expand Up @@ -307,8 +308,8 @@ epoch.
@doc("Response of getting a model.")
@resource("multivariate/models")
model AnomalyDetectionModel {
#suppress "@azure-tools/typespec-azure-core/key-visibility-required" "Properties in response-only schemas should not be marked readOnly"
@doc("Model identifier.")
@visibility("read")
@key
@format("uuid")
modelId: string;
Expand Down Expand Up @@ -357,7 +358,7 @@ Number of top contributed
variables for one anomalous time stamp in the response. The default is
10.
""")
topContributorCount: int32;
topContributorCount?: int32 = 10;
}

@doc("Variable values.")
Expand All @@ -384,8 +385,8 @@ model MultivariateLastDetectionResult {
@doc("Error response.")
@error
model ResponseError {
@header
@header("x-ms-error-code")
@doc("Error code.")
"x-ms-error-code"?: string,
msErrorCode?: string,
...ErrorResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,36 @@ using Azure.Core;

namespace AnomalyDetector.Multivariate;

// Operation templates

@post
@doc("Operation template for multivariate anomaly detection service action.")
op MultivariateServiceAction<TParams, TResponse>(
...TParams
): TResponse | ResponseError;

// Operations

#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Does not fit any standard operation pattern"
// This operation does not fit any standard operation pattern.
// The closest match is probably GetResourceOperationStatus, but that can't be used because
// it does not support an api-version in the path defined in the @server decorator.
mikekistler marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/Azure/typespec-azure/issues/2798
@get
@route("/multivariate/detect-batch/{resultId}")
@summary("Get Multivariate Anomaly Detection Result")
@doc("""
For asynchronous inference, get a multivariate anomaly detection result based on the
resultId value that the BatchDetectAnomaly API returns.
""")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op GetMultivariateBatchDetectionResult(
@format("uuid")
@doc("ID of a batch detection result.")
@path resultId: string,
): MultivariateDetectionResult | ResponseError;


@post
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Azure core RpcOperation does not support custom error response"
// https://github.com/Azure/typespec-azure/issues/2795
@route("/multivariate/models")
@summary("Train a Multivariate Anomaly Detection Model")
@doc("""
Expand All @@ -35,38 +49,44 @@ Storage folder that contains multiple CSV files, where each CSV file has
two columns, time stamp and variable. Or the Blob Storage URI can point to a single blob that contains a CSV file that has all the variables and a
time stamp column.
""")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op TrainMultivariateModel(
@doc("Model information.")
@body modelInfo: ModelInfo,
): {
@statusCode statusCode: 201,
@doc("Location and ID of the model.")
@header Location: string,
@body result: AnomalyDetectionModel
} | ResponseError;
op TrainMultivariateModel is MultivariateServiceAction<
// TParams
{
@doc("Model information.")
@body modelInfo: ModelInfo,
mikekistler marked this conversation as resolved.
Show resolved Hide resolved
},
// TResponse
{
@statusCode statusCode: 201,
@doc("Location and ID of the model.")
@header location: string,
@body result: AnomalyDetectionModel
}>;

#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Does not fit any standard operation pattern"
// This operation does not fit any standard operation pattern.
// The closest match is probably ResourceList, but that can't be used because
// it does not support an api-version in the path defined in the @server decorator.
// https://github.com/Azure/typespec-azure/issues/2798
// and because the response uses "models" instead of "value" as the array property name.
@get
@route("/multivariate/models")
@summary("List Multivariate Models")
@doc("List models of a resource.")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op ListMultivariateModels(
@doc("Skip indicates how many models will be skipped.")
@query
skip?: int32 = 0;

@doc("Top indicates how many models will be fetched.")
@query
top?: int32;
...SkipQueryParameter,
...TopQueryParameter,
): ModelList | ResponseError;


#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Does not fit any standard operation pattern"
// This operation does not fit any standard operation pattern.
// The closest match is probably ResourceDelete, but that can't be used because
// it does not support an api-version in the path defined in the @server decorator.
@summary("Delete Multivariate Model")
@doc("Delete an existing multivariate model according to the modelId value.")
@delete
@route("/multivariate/models/{modelId}")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op DeleteMultivariateModel(
@doc("Model identifier.")
@path
Expand All @@ -77,20 +97,29 @@ op DeleteMultivariateModel(
statusCode: 204
} | ResponseError;


#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Does not fit any standard operation pattern"
// This operation does not fit any standard operation pattern.
// The closest match is probably ResourceGet, but that can't be used because
// it does not support an api-version in the path defined in the @server decorator.
@summary("Get Multivariate Model")
@doc("""
Get detailed information about the multivariate model, including the training status
and variables used in the model.
""")
@get
@route("/multivariate/models/{modelId}")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op GetMultivariateModel(
@doc("Model identifier.")
@path
modelId: string,
): AnomalyDetectionModel | ResponseError;

#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Does not fit any standard operation pattern"
// This operation does not fit any standard operation pattern.
// The closest match is probably LongRunningResourceAction, but that can't be used because
// it does not support an api-version in the path defined in the @server decorator.
@post
@route("/multivariate/models/{modelId}:detect-batch")
@summary("Detect Multivariate Anomaly")
@doc("""
Expand All @@ -101,7 +130,6 @@ query the detection result. The request should be a source link to indicate an
externally accessible Azure Storage URI that either points to an Azure Blob
Storage folder or points to a CSV file in Azure Blob Storage.
""")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op DetectMultivariateBatchAnomaly(
@doc("Model identifier.")
@path
Expand All @@ -111,12 +139,17 @@ op DetectMultivariateBatchAnomaly(
): {
@statusCode statusCode: 202,
@doc("ID of the detection result.")
@header "Operation-Id": string,
@header("Operation-Id") operationId: string,
@doc("Location of the detection result.")
@header "Operation-Location": string,
@header("Operation-Location") operationLocation: string,
@body result: MultivariateDetectionResult,
} | ResponseError;


#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Does not fit any standard operation pattern"
// This operation does not fit any standard operation pattern.
// The closest match is probably ResourceAction, but that can't be used because
// it does not support an api-version in the path defined in the @server decorator.
@route("/multivariate/models/{modelId}:detect-last")
@summary("Detect anomalies in the last point of the request body")
@doc("""
Expand All @@ -125,7 +158,6 @@ and inference data. The inference data should be put into the request body in
JSON format. The request will finish synchronously and return the detection
immediately in the response body.
""")
// To improve CADL implementation apply: https://github.com/Azure/azure-rest-api-specs/issues/21527
op DetectMultivariateLastAnomaly(
@doc("Model identifier.")
@path
Expand Down
10 changes: 4 additions & 6 deletions specification/cognitiveservices/AnomalyDetector/tspconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
emit: [
"@azure-tools/typespec-autorest",
"@azure-tools/typespec-python",
"@azure-tools/typespec-csharp",
]
options:
"@azure-tools/typespec-autorest":
"output-file": "openapi.json"
"examples-directory": ./examples
examples-directory: ./examples
omit-unreachable-types: true
output-file: openapi.json
emitter-output-dir: "{project-root}/../data-plane/AnomalyDetector/stable"
"@azure-tools/typespec-python":
"basic-setup-py": true
"package-version": 3.0.0b6
Expand All @@ -22,5 +22,3 @@ options:
clear-output-folder: true
namespace: Azure.AI.AnomalyDetector
model-namespace: false
# Uncomment this line and add "@azure-tools/typespec-typescript" to your package.json to generate Typescript code
# "@azure-tools/cadl-typescript": true
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ enum AnomalyDetectorErrorCodes {
"InvalidImputeFixedValue",
}

@fixed
enum TimeGranularity {
Yearly: "yearly",
Monthly: "monthly",
Expand Down Expand Up @@ -172,15 +171,15 @@ severe the anomaly is. For normal points, the severity is always 0.
@doc("Error information that the API returned.")
@error
model AnomalyDetectorError {
@header
@header("x-ms-error-code")
@doc("Error code.")
"x-ms-error-code"?: string,
msErrorCode: string,

@doc("Error code.")
code?: AnomalyDetectorErrorCodes;
code: AnomalyDetectorErrorCodes;

@doc("Message that explains the error that the service reported.")
message?: string;
message: string;
}

@doc("Response of the last anomaly detection.")
Expand Down
Loading