Skip to content

Commit 467a8c1

Browse files
welovejv-xutoChenxiJiang333v-jiaodipshao25
authored
Tyespec migration for alertsmanagement PrometheusRuleGroups (#39140)
* converted * could compile * update * Update PrometheusRuleGroupResource.tsp * Refactor folder * Update tspconfig.yaml * Create client.tsp * Update tspconfig.yaml --------- Co-authored-by: Tong Xu (MSFT) <v-xuto@microsoft.com> Co-authored-by: ChenxiJiang333 <119990644+ChenxiJiang333@users.noreply.github.com> Co-authored-by: Jiao Di (MSFT) <80496810+v-jiaodi@users.noreply.github.com> Co-authored-by: Pan Shao <97225342+pshao25@users.noreply.github.com>
1 parent 011192c commit 467a8c1

22 files changed

Lines changed: 1662 additions & 483 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import "@azure-tools/typespec-azure-core";
2+
import "@azure-tools/typespec-azure-resource-manager";
3+
import "@typespec/openapi";
4+
import "@typespec/rest";
5+
import "./models.tsp";
6+
7+
using TypeSpec.Rest;
8+
using Azure.ResourceManager;
9+
using TypeSpec.Http;
10+
using TypeSpec.OpenAPI;
11+
12+
namespace Microsoft.AlertsManagement;
13+
/**
14+
* The Prometheus rule group resource.
15+
*/
16+
model PrometheusRuleGroupResource
17+
is Azure.ResourceManager.TrackedResource<
18+
PrometheusRuleGroupProperties,
19+
false
20+
> {
21+
...ResourceNameParameter<
22+
Resource = PrometheusRuleGroupResource,
23+
KeyName = "ruleGroupName",
24+
SegmentName = "prometheusRuleGroups",
25+
NamePattern = "^[^:@/#{}%&+*<>?]+$"
26+
>;
27+
}
28+
29+
@armResourceOperations
30+
interface PrometheusRuleGroupResources {
31+
/**
32+
* Retrieve a Prometheus rule group definition.
33+
*/
34+
get is ArmResourceRead<PrometheusRuleGroupResource>;
35+
36+
/**
37+
* Create or update a Prometheus rule group definition.
38+
*/
39+
createOrUpdate is ArmResourceCreateOrReplaceSync<PrometheusRuleGroupResource>;
40+
41+
/**
42+
* Update an Prometheus rule group definition.
43+
*/
44+
@patch(#{ implicitOptionality: false })
45+
update is ArmCustomPatchSync<
46+
PrometheusRuleGroupResource,
47+
PatchModel = PrometheusRuleGroupResourcePatchParameters
48+
>;
49+
50+
/**
51+
* Delete a Prometheus rule group definition.
52+
*/
53+
delete is ArmResourceDeleteSync<PrometheusRuleGroupResource>;
54+
55+
/**
56+
* Retrieve Prometheus rule group definitions in a resource group.
57+
*/
58+
listByResourceGroup is ArmResourceListByParent<
59+
PrometheusRuleGroupResource,
60+
Response = ArmResponse<PrometheusRuleGroupResourceCollection>
61+
>;
62+
63+
/**
64+
* Retrieve Prometheus all rule group definitions in a subscription.
65+
*/
66+
listBySubscription is ArmListBySubscription<
67+
PrometheusRuleGroupResource,
68+
Response = ArmResponse<PrometheusRuleGroupResourceCollection>
69+
>;
70+
}
71+
72+
@@doc(PrometheusRuleGroupResource.name, "The name of the rule group.");
73+
@@doc(PrometheusRuleGroupResource.properties,
74+
"The Prometheus rule group properties of the resource."
75+
);
76+
@@doc(PrometheusRuleGroupResources.createOrUpdate::parameters.resource,
77+
"The parameters of the rule group to create or update."
78+
);
79+
@@doc(PrometheusRuleGroupResources.update::parameters.properties,
80+
"The parameters of the rule group to update."
81+
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import "@azure-tools/typespec-client-generator-core";
2+
3+
using Azure.ClientGenerator.Core;
4+
using Microsoft.AlertsManagement;
5+
6+
#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
7+
@@Legacy.flattenProperty(PrometheusRuleGroupResourcePatchParameters.properties);
8+
9+
@@clientLocation(PrometheusRuleGroupResources.get, "PrometheusRuleGroups");
10+
@@clientLocation(PrometheusRuleGroupResources.createOrUpdate,
11+
"PrometheusRuleGroups"
12+
);
13+
@@clientName(PrometheusRuleGroupResources.createOrUpdate::parameters.resource,
14+
"parameters"
15+
);
16+
@@clientLocation(PrometheusRuleGroupResources.update, "PrometheusRuleGroups");
17+
@@clientName(PrometheusRuleGroupResources.update::parameters.properties,
18+
"parameters"
19+
);
20+
@@clientLocation(PrometheusRuleGroupResources.delete, "PrometheusRuleGroups");
21+
@@clientLocation(PrometheusRuleGroupResources.listByResourceGroup,
22+
"PrometheusRuleGroups"
23+
);
24+
@@clientLocation(PrometheusRuleGroupResources.listBySubscription,
25+
"PrometheusRuleGroups"
26+
);
27+
#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
28+
@@Legacy.flattenProperty(PrometheusRuleGroupResource.properties);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "./main.tsp";
2+
import "@azure-tools/typespec-client-generator-core";
3+
4+
using Azure.ClientGenerator.Core;
5+
6+
@@clientName(Microsoft.AlertsManagement,
7+
"PrometheusRuleGroupsMgmtClient",
8+
"python"
9+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"parameters": {
3+
"api-version": "2023-03-01",
4+
"parameters": {
5+
"location": "East US",
6+
"properties": {
7+
"description": "This is a rule group with culster centric configuration",
8+
"clusterName": "myClusterName",
9+
"interval": "PT10M",
10+
"rules": [
11+
{
12+
"actions": [],
13+
"alert": "Billing_Processing_Very_Slow",
14+
"annotations": {
15+
"annotationName1": "annotationValue1"
16+
},
17+
"enabled": true,
18+
"expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
19+
"for": "PT5M",
20+
"labels": {
21+
"team": "prod"
22+
},
23+
"resolveConfiguration": {
24+
"autoResolved": true,
25+
"timeToResolve": "PT10M"
26+
},
27+
"severity": 2
28+
}
29+
],
30+
"scopes": [
31+
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace",
32+
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myClusterName"
33+
]
34+
}
35+
},
36+
"resourceGroupName": "promResourceGroup",
37+
"ruleGroupName": "myPrometheusRuleGroup",
38+
"subscriptionId": "ffffffff-ffff-ffff-ffff-ffffffffffff"
39+
},
40+
"responses": {
41+
"200": {
42+
"body": {
43+
"type": "Microsoft.AlertsManagement/prometheusRuleGroups",
44+
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup",
45+
"location": "East US",
46+
"properties": {
47+
"description": "This is a rule group with culster centric configuration",
48+
"clusterName": "myClusterName",
49+
"interval": "PT10M",
50+
"rules": [
51+
{
52+
"actions": [],
53+
"alert": "Billing_Processing_Very_Slow",
54+
"annotations": {
55+
"annotationName1": "annotationValue1"
56+
},
57+
"enabled": true,
58+
"expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
59+
"for": "PT5M",
60+
"labels": {
61+
"team": "prod"
62+
},
63+
"resolveConfiguration": {
64+
"autoResolved": true,
65+
"timeToResolve": "PT10M"
66+
},
67+
"severity": 2
68+
}
69+
],
70+
"scopes": [
71+
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace",
72+
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myClusterName"
73+
]
74+
}
75+
},
76+
"headers": {}
77+
},
78+
"201": {
79+
"body": {
80+
"type": "Microsoft.AlertsManagement/prometheusRuleGroups",
81+
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup",
82+
"location": "East US",
83+
"properties": {
84+
"description": "This is a rule group with culster centric configuration",
85+
"clusterName": "myClusterName",
86+
"interval": "PT10M",
87+
"rules": [
88+
{
89+
"actions": [],
90+
"alert": "Billing_Processing_Very_Slow",
91+
"annotations": {
92+
"annotationName1": "annotationValue1"
93+
},
94+
"enabled": true,
95+
"expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
96+
"for": "PT5M",
97+
"labels": {
98+
"team": "prod"
99+
},
100+
"resolveConfiguration": {
101+
"autoResolved": true,
102+
"timeToResolve": "PT10M"
103+
},
104+
"severity": 2
105+
}
106+
],
107+
"scopes": [
108+
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace",
109+
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myClusterName"
110+
]
111+
}
112+
},
113+
"headers": {}
114+
}
115+
},
116+
"operationId": "PrometheusRuleGroups_CreateOrUpdate",
117+
"title": "Create or Update a cluster centric PrometheusRuleGroup"
118+
}

0 commit comments

Comments
 (0)