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
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export interface DataFeed {
// @public
export type DataFeedAccessMode = "Private" | "Public";

// @public
export type DataFeedDescriptor = Omit<DataFeed, "id" | "metricIds" | "isAdmin" | "status" | "creator" | "createdTime">;

// @public
export type DataFeedDetailStatus = "Active" | "Paused";

Expand Down Expand Up @@ -803,7 +806,7 @@ export type MetricPeriodFeedback = {
export class MetricsAdvisorAdministrationClient {
constructor(endpointUrl: string, credential: MetricsAdvisorKeyCredential, options?: MetricsAdvisorAdministrationClientOptions);
createAlertConfig(config: Omit<AnomalyAlertConfiguration, "id">, options?: OperationOptions): Promise<GetAnomalyAlertConfigurationResponse>;
createDataFeed(feed: Omit<DataFeed, "id" | "metricIds" | "isAdmin" | "status" | "creator" | "createdTime">, operationOptions?: OperationOptions): Promise<GetDataFeedResponse>;
createDataFeed(feed: DataFeedDescriptor, operationOptions?: OperationOptions): Promise<GetDataFeedResponse>;
createDetectionConfig(config: Omit<AnomalyDetectionConfiguration, "id">, options?: OperationOptions): Promise<GetAnomalyDetectionConfigurationResponse>;
createHook(hookInfo: EmailNotificationHook | WebNotificationHook, options?: OperationOptions): Promise<GetHookResponse>;
deleteAlertConfig(id: string, options?: OperationOptions): Promise<RestResponse>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,7 @@ async function queryAlerts(client, alertConfigId, startTime, endTime) {
// This shows how to use `for-await-of` syntax to list alerts
console.log(" using for-await-of syntax");
let alerts = [];
for await (const alert of client.listAlerts(
alertConfigId,
startTime,
endTime,
"AnomalyTime"
)) {
for await (const alert of client.listAlerts(alertConfigId, startTime, endTime, "AnomalyTime")) {
alerts.push(alert);
console.log(" Alert");
console.log(` id: ${alert.id}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dotenv.config();
import {
MetricsAdvisorKeyCredential,
MetricsAdvisorAdministrationClient,
MetricAlertConfiguration,
AnomalyAlertConfiguration
} from "@azure/ai-metrics-advisor";

Expand Down Expand Up @@ -51,7 +50,7 @@ async function createAlertConfig(
detectionConfigId: string
) {
console.log("Creating a new alerting configuration...");
const alertConfig = {
const alertConfig: Omit<AnomalyAlertConfiguration, "id"> = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? @jeremymeng

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the correct type, building samples would give errors like

error TS2345: Argument of type '{ name: string; crossMetricsOperator: string; metricAlertConfigurations: ({ detectionConfigurationId: string; alertScope: { scopeType: string; dimensionAnomalyScope?: undefined; }; } | { ...; })[]; hookIds: never[]; description: string; }' is not assignable to parameter of type 'Pick<AnomalyAlertConfiguration, "name" | "description" | "crossMetricsOperator" | "hookIds" | "metricAlertConfigurations">'.
  Types of property 'crossMetricsOperator' are incompatible.
    Type 'string' is not assignable to type '"AND" | "OR" | "XOR" | undefined'.

name: "js alerting config name " + new Date().getTime().toString(),
crossMetricsOperator: "AND",
metricAlertConfigurations: [
Expand Down Expand Up @@ -100,7 +99,10 @@ async function updateAlertConfig(
detectionConfigurationId: detectionConfigId,
alertScope: {
scopeType: "Dimension",
dimensionAnomalyScope: { city: "Kolkata", category: "Shoes Handbags & Sunglasses" }
dimensionAnomalyScope: {
city: "Kolkata",
category: "Shoes Handbags & Sunglasses"
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ dotenv.config();
import {
MetricsAdvisorKeyCredential,
MetricsAdvisorAdministrationClient,
DataFeedSchema,
DataFeedMetric,
DataFeedDimension,
DataFeedIngestionSettings,
DataFeedGranularity,
DataFeedSource,
DataFeedOptions,
GetDataFeedResponse,
DataFeedPatch
DataFeedPatch,
DataFeedDescriptor
} from "@azure/ai-metrics-advisor";

export async function main() {
Expand Down Expand Up @@ -77,7 +71,7 @@ async function createDataFeed(
client: MetricsAdvisorAdministrationClient
): Promise<GetDataFeedResponse> {
console.log("Creating Datafeed...");
const feed = {
const feed: DataFeedDescriptor = {
name: "test-datafeed-" + new Date().getTime().toString(),
source: {
dataSourceType: "AzureBlob",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnomalyAlert,
GetDataFeedResponse,
MetricsAdvisorClient,
WebNotificationHook
WebNotificationHook,
DataFeedDescriptor,
AnomalyAlertConfiguration,
AnomalyDetectionConfiguration
} from "@azure/ai-metrics-advisor";

export async function main() {
Expand Down Expand Up @@ -87,7 +90,7 @@ async function createDataFeed(
sqlServerQuery: string
): Promise<GetDataFeedResponse> {
console.log("Creating Datafeed...");
const dataFeed = {
const dataFeed: DataFeedDescriptor = {
name: "test_datafeed_" + new Date().getTime().toString(),
source: {
dataSourceType: "SqlServer",
Expand Down Expand Up @@ -165,7 +168,7 @@ async function configureAnomalyDetectionConfiguration(
metricId: string
) {
console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);
const anomalyConfig = {
const anomalyConfig: Omit<AnomalyDetectionConfiguration, "id"> = {
name: "test_detection_configuration" + new Date().getTime().toString(),
metricId,
wholeSeriesDetectionCondition: {
Expand Down Expand Up @@ -207,7 +210,7 @@ async function configureAlertConfiguration(
hookIds: string[]
) {
console.log("Creating a new alerting configuration...");
const anomalyAlert = {
const anomalyAlert: Omit<AnomalyAlertConfiguration, "id"> = {
name: "test_alert_config_" + new Date().getTime().toString(),
crossMetricsOperator: "AND",
metricAlertConfigurations: [
Expand Down Expand Up @@ -245,12 +248,7 @@ async function queryAlerts(
// This shows how to use `for-await-of` syntax to list alerts
console.log(" using for-await-of syntax");
let alerts: AnomalyAlert[] = [];
for await (const alert of client.listAlerts(
alertConfigId,
startTime,
endTime,
"AnomalyTime"
)) {
for await (const alert of client.listAlerts(alertConfigId, startTime, endTime, "AnomalyTime")) {
alerts.push(alert);
console.log(" Alert");
console.log(` id: ${alert.id}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export type ListDataFeedsOptions = {
};
} & OperationOptions;

/**
* describes the input to Create Data Feed operation
*/
export type DataFeedDescriptor = Omit<
DataFeed,
"id" | "metricIds" | "isAdmin" | "status" | "creator" | "createdTime"
>;

/**
* Options for creating data feed
*/
Expand Down Expand Up @@ -172,7 +180,7 @@ export class MetricsAdvisorAdministrationClient {
*/

public async createDataFeed(
feed: Omit<DataFeed, "id" | "metricIds" | "isAdmin" | "status" | "creator" | "createdTime">,
feed: DataFeedDescriptor,
operationOptions: OperationOptions = {}
): Promise<GetDataFeedResponse> {
const { span, updatedOptions: finalOptions } = createSpan(
Expand Down