Skip to content

Commit 19f2838

Browse files
committed
feat: add aclp clone api and group_by field
1 parent 1e7add4 commit 19f2838

7 files changed

Lines changed: 876 additions & 136 deletions

monitor_alert_definitions.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type AlertDefinition struct {
6767
Scope AlertDefinitionScope `json:"scope"`
6868
Regions []string `json:"regions"`
6969
Entities AlertDefinitionEntities `json:"entities"`
70+
GroupBy []string `json:"group_by"`
7071
}
7172

7273
// TriggerConditions represents the trigger conditions for an alert.
@@ -167,6 +168,7 @@ type AlertDefinitionCreateOptions struct {
167168
Description *string `json:"description,omitzero"`
168169
Scope AlertDefinitionScope `json:"scope,omitzero"`
169170
Regions []string `json:"regions,omitzero"`
171+
GroupBy []string `json:"group_by,omitzero"`
170172
}
171173

172174
// AlertDefinitionUpdateOptions are the options used to update an alert definition.
@@ -180,6 +182,21 @@ type AlertDefinitionUpdateOptions struct {
180182
Description *string `json:"description,omitzero"`
181183
Status *AlertDefinitionStatus `json:"status,omitzero"`
182184
Regions []string `json:"regions,omitzero"`
185+
GroupBy []string `json:"group_by,omitzero"`
186+
}
187+
188+
// AlertDefinitionCloneOptions are the options used to clone an existing alert definition.
189+
type AlertDefinitionCloneOptions struct {
190+
Label string `json:"label"`
191+
Severity *int `json:"severity,omitzero"`
192+
ChannelIDs []int `json:"channel_ids,omitzero"`
193+
RuleCriteria *RuleCriteriaOptions `json:"rule_criteria,omitzero"`
194+
TriggerConditions *TriggerConditions `json:"trigger_conditions,omitzero"`
195+
EntityIDs []string `json:"entity_ids,omitzero"`
196+
Description *string `json:"description,omitzero"`
197+
Scope AlertDefinitionScope `json:"scope,omitzero"`
198+
Regions []string `json:"regions,omitzero"`
199+
GroupBy []string `json:"group_by,omitzero"`
183200
}
184201

185202
// UnmarshalJSON implements the json.Unmarshaler interface
@@ -307,3 +324,14 @@ func (c *Client) ListMonitorAlertDefinitionEntities(
307324
e := formatAPIPath("monitor/services/%s/alert-definitions/%d/entities", serviceType, alertID)
308325
return getPaginatedResults[AlertDefinitionEntity](ctx, c, e, opts)
309326
}
327+
328+
// CloneMonitorAlertDefinition clones an ACLP Monitor Alert Definition.
329+
func (c *Client) CloneMonitorAlertDefinition(
330+
ctx context.Context,
331+
serviceType string,
332+
alertID int,
333+
opts AlertDefinitionCloneOptions,
334+
) (*AlertDefinition, error) {
335+
e := formatAPIPath("monitor/services/%s/alert-definitions/%d/clone", serviceType, alertID)
336+
return doPOSTRequest[AlertDefinition](ctx, c, e, opts)
337+
}

test/integration/fixtures/TestMonitorAlertDefinition.yaml

Lines changed: 60 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,31 @@ interactions:
1414
url: https://api.linode.com/v4beta/monitor/alert-definitions?page=1
1515
method: GET
1616
response:
17-
body: '{"pages": 1, "page": 1, "results": 4, "data": [{"id": 10000, "label":
17+
body: '{"pages": 1, "page": 1, "results": 2, "data": [{"id": 10000, "label":
1818
"High Memory Usage Plan Dedicated", "description": "Alert triggers when dedicated
19-
plan nodes consistently reach critical memory usage, risking application performance
20-
degradation.", "service_type": "dbaas", "type": "system", "scope": "entity",
21-
"class": "dedicated", "regions": [], "status": "enabled", "severity":
22-
2, "rule_criteria": {"rules": [{"label": "Memory Usage", "metric": "memory_usage",
23-
"unit": "percent", "aggregate_function": "avg", "operator": "gt", "threshold":
24-
95, "dimension_filters": []}]}, "alert_channels": [{"id": 10000, "label": "Read-Write
25-
Channel", "url": "/monitor/alert-channels/10000", "type": "alert-channels"}],
26-
"trigger_conditions": {"criteria_condition": "ALL", "polling_interval_seconds":
27-
300, "evaluation_period_seconds": 300, "trigger_occurrences": 3}, "created":
28-
"2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by": "system",
29-
"updated_by": "system", "entities": {"url": "/monitor/services/dbaas/alert-definitions/10000/entities",
30-
"has_more_resources": false, "count": 5}}, {"id": 10001, "label": "High Memory
31-
Usage Plan Shared", "description": "Alert triggers when shared plan nodes consistently
32-
reach critical memory usage, risking application performance degradation.",
33-
"service_type": "dbaas", "type": "system", "scope": "entity", "class": "shared",
34-
"regions": [], "status": "enabled", "severity": 2, "rule_criteria": {"rules": [{"label": "Memory Usage",
19+
plan nodes consistently reach critical memory usage.", "service_type": "dbaas",
20+
"type": "system", "scope": "entity", "class": "dedicated", "regions": [], "status":
21+
"enabled", "severity": 2, "rule_criteria": {"rules": [{"label": "Memory Usage",
3522
"metric": "memory_usage", "unit": "percent", "aggregate_function": "avg", "operator":
36-
"gt", "threshold": 90, "dimension_filters": []}]}, "alert_channels": [{"id":
23+
"gt", "threshold": 95, "dimension_filters": []}]}, "alert_channels": [{"id":
3724
10000, "label": "Read-Write Channel", "url": "/monitor/alert-channels/10000",
3825
"type": "alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL",
3926
"polling_interval_seconds": 300, "evaluation_period_seconds": 300, "trigger_occurrences":
4027
3}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by":
41-
"system", "updated_by": "system", "entities": {"url": "/monitor/services/dbaas/alert-definitions/10001/entities",
42-
"has_more_resources": false, "count": 2}}, {"id": 11001, "label": "test_alert_logs_prod",
43-
"description": "some desc1", "service_type": "logs", "type": "user", "scope":
44-
"entity", "class": null, "regions": [], "status": "enabled", "severity": 2, "rule_criteria": {"rules": [{"label":
45-
"Successful Upload Count", "metric": "success_upload_count", "unit": "count",
46-
"aggregate_function": "sum", "operator": "lt", "threshold": 100000, "dimension_filters":
47-
[]}]}, "alert_channels": [{"id": 10004, "label": "Alert Channel", "url":
28+
"system", "updated_by": "system", "group_by": ["entity_id"], "entities": {"url":
29+
"/monitor/services/dbaas/alert-definitions/10000/entities", "has_more_resources":
30+
false, "count": 5}}, {"id": 11184, "label": "Test alert", "description":
31+
"Test alert", "service_type": "dbaas", "type": "user", "scope":
32+
"entity", "class": null, "regions": [], "status": "disabled", "severity": 3,
33+
"rule_criteria": {"rules": [{"label": "CPU Usage", "metric": "cpu_usage", "unit":
34+
"percent", "aggregate_function": "avg", "operator": "gt", "threshold": 0, "dimension_filters":
35+
[]}]}, "alert_channels": [{"id": 10004, "label": "Team Channel", "url":
4836
"/monitor/alert-channels/10004", "type": "alert-channels"}], "trigger_conditions":
4937
{"criteria_condition": "ALL", "polling_interval_seconds": 300, "evaluation_period_seconds":
5038
300, "trigger_occurrences": 1}, "created": "2018-01-02T03:04:05", "updated":
5139
"2018-01-02T03:04:05", "created_by": "tester", "updated_by":
52-
"tester", "entities": {"url": "/monitor/services/logs/alert-definitions/11001/entities",
53-
"has_more_resources": false, "count": 1}}, {"id": 11021, "label": "Test Alert", "description": "Test Alert", "service_type":
54-
"dbaas", "type": "user", "scope": "entity", "class": null, "regions": [], "status":
55-
"enabled", "severity": 1, "rule_criteria": {"rules": [{"label": "Memory Usage", "metric":
56-
"memory_usage", "unit": "percent", "aggregate_function": "sum", "operator":
57-
"gt", "threshold": 100, "dimension_filters": []}]}, "alert_channels": [{"id":
58-
10004, "label": "Alert Channel", "url": "/monitor/alert-channels/10004",
59-
"type": "alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL",
60-
"polling_interval_seconds": 1800, "evaluation_period_seconds": 900, "trigger_occurrences":
61-
10}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by":
62-
"tester", "updated_by": "tester", "entities":
63-
{"url": "/monitor/services/dbaas/alert-definitions/11021/entities", "has_more_resources":
64-
false, "count": 2}}]}'
40+
"tester", "group_by": ["entity_id"], "entities": {"url": "/monitor/services/dbaas/alert-definitions/11184/entities",
41+
"has_more_resources": false, "count": 1}}]}'
6542
headers:
6643
Access-Control-Allow-Credentials:
6744
- "true"
@@ -84,7 +61,7 @@ interactions:
8461
Content-Type:
8562
- application/json
8663
Expires:
87-
- Mon, 27 Apr 2026 12:32:17 GMT
64+
- Thu, 04 Jun 2026 10:41:16 GMT
8865
Pragma:
8966
- no-cache
9067
Strict-Transport-Security:
@@ -114,7 +91,7 @@ interactions:
11491
duration: ""
11592
- request:
11693
body: '{"label":"go-test-alert-definition-create","severity":2,"channel_ids":[10000],"rule_criteria":{"rules":[{"aggregate_function":"avg","dimension_filters":[{"dimension_label":"node_type","operator":"eq","value":"primary"}],"metric":"memory_usage","operator":"gt","threshold":90}]},"trigger_conditions":{"criteria_condition":"ALL","evaluation_period_seconds":300,"polling_interval_seconds":300,"trigger_occurrences":1},"description":"Test
117-
alert definition creation"}'
94+
alert definition creation","group_by":["entity_id"]}'
11895
form: {}
11996
headers:
12097
Accept:
@@ -126,18 +103,19 @@ interactions:
126103
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions
127104
method: POST
128105
response:
129-
body: '{"id": 11072, "label": "go-test-alert-definition-create", "description":
106+
body: '{"id": 11230, "label": "go-test-alert-definition-create", "description":
130107
"Test alert definition creation", "service_type": "dbaas", "type": "user", "scope":
131-
"entity", "class": null, "regions": [], "status": "provisioning", "severity": 2, "rule_criteria": {"rules": [{"label":
132-
"Memory Usage", "metric": "memory_usage", "unit": "percent", "aggregate_function":
133-
"avg", "operator": "gt", "threshold": 90, "dimension_filters": [{"label": "Node
134-
Type", "dimension_label": "node_type", "operator": "eq", "value": "primary"}]}]},
135-
"alert_channels": [{"id": 10000, "label": "Read-Write Channel", "url": "/monitor/alert-channels/10000",
136-
"type": "alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL",
137-
"polling_interval_seconds": 300, "evaluation_period_seconds": 300, "trigger_occurrences":
138-
1}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by":
139-
"tester", "updated_by": "tester", "entities":
140-
{"url": "/monitor/services/dbaas/alert-definitions/11072/entities", "has_more_resources":
108+
"entity", "class": null, "regions": [], "status": "provisioning", "severity":
109+
2, "rule_criteria": {"rules": [{"label": "Memory Usage", "metric": "memory_usage",
110+
"unit": "percent", "aggregate_function": "avg", "operator": "gt", "threshold":
111+
90, "dimension_filters": [{"label": "Node Type", "dimension_label": "node_type",
112+
"operator": "eq", "value": "primary"}]}]}, "alert_channels": [{"id": 10000,
113+
"label": "Read-Write Channel", "url": "/monitor/alert-channels/10000", "type":
114+
"alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL", "polling_interval_seconds":
115+
300, "evaluation_period_seconds": 300, "trigger_occurrences": 1}, "created":
116+
"2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by": "tester",
117+
"updated_by": "tester", "group_by": ["entity_id"], "entities":
118+
{"url": "/monitor/services/dbaas/alert-definitions/11230/entities", "has_more_resources":
141119
false, "count": 0}}'
142120
headers:
143121
Access-Control-Allow-Credentials:
@@ -161,7 +139,7 @@ interactions:
161139
Content-Type:
162140
- application/json
163141
Expires:
164-
- Mon, 27 Apr 2026 12:32:18 GMT
142+
- Thu, 04 Jun 2026 10:41:17 GMT
165143
Pragma:
166144
- no-cache
167145
Strict-Transport-Security:
@@ -198,21 +176,22 @@ interactions:
198176
- application/json
199177
User-Agent:
200178
- linodego/dev https://github.com/linode/linodego
201-
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions/11072
179+
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions/11230
202180
method: GET
203181
response:
204-
body: '{"id": 11072, "label": "go-test-alert-definition-create", "description":
182+
body: '{"id": 11230, "label": "go-test-alert-definition-create", "description":
205183
"Test alert definition creation", "service_type": "dbaas", "type": "user", "scope":
206-
"entity", "class": null, "regions": [], "status": "enabled", "severity": 2, "rule_criteria": {"rules": [{"label":
207-
"Memory Usage", "metric": "memory_usage", "unit": "percent", "aggregate_function":
208-
"avg", "operator": "gt", "threshold": 90, "dimension_filters": [{"label": "Node
209-
Type", "dimension_label": "node_type", "operator": "eq", "value": "primary"}]}]},
210-
"alert_channels": [{"id": 10000, "label": "Read-Write Channel", "url": "/monitor/alert-channels/10000",
211-
"type": "alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL",
212-
"polling_interval_seconds": 300, "evaluation_period_seconds": 300, "trigger_occurrences":
213-
1}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by":
214-
"tester", "updated_by": "tester", "entities":
215-
{"url": "/monitor/services/dbaas/alert-definitions/11072/entities", "has_more_resources":
184+
"entity", "class": null, "regions": [], "status": "enabled", "severity": 2,
185+
"rule_criteria": {"rules": [{"label": "Memory Usage", "metric": "memory_usage",
186+
"unit": "percent", "aggregate_function": "avg", "operator": "gt", "threshold":
187+
90, "dimension_filters": [{"label": "Node Type", "dimension_label": "node_type",
188+
"operator": "eq", "value": "primary"}]}]}, "alert_channels": [{"id": 10000,
189+
"label": "Read-Write Channel", "url": "/monitor/alert-channels/10000", "type":
190+
"alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL", "polling_interval_seconds":
191+
300, "evaluation_period_seconds": 300, "trigger_occurrences": 1}, "created":
192+
"2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by": "tester",
193+
"updated_by": "tester", "group_by": ["entity_id"], "entities":
194+
{"url": "/monitor/services/dbaas/alert-definitions/11230/entities", "has_more_resources":
216195
false, "count": 0}}'
217196
headers:
218197
Access-Control-Allow-Credentials:
@@ -236,7 +215,7 @@ interactions:
236215
Content-Type:
237216
- application/json
238217
Expires:
239-
- Mon, 27 Apr 2026 12:32:35 GMT
218+
- Thu, 04 Jun 2026 10:41:33 GMT
240219
Pragma:
241220
- no-cache
242221
Strict-Transport-Security:
@@ -275,21 +254,22 @@ interactions:
275254
- application/json
276255
User-Agent:
277256
- linodego/dev https://github.com/linode/linodego
278-
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions/11072
257+
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions/11230
279258
method: PUT
280259
response:
281-
body: '{"id": 11072, "label": "go-test-alert-definition-create-updated", "description":
260+
body: '{"id": 11230, "label": "go-test-alert-definition-create-updated", "description":
282261
"Test alert definition creation", "service_type": "dbaas", "type": "user", "scope":
283-
"entity", "class": null, "regions": [], "status": "enabled", "severity": 2, "rule_criteria": {"rules": [{"label":
284-
"Memory Usage", "metric": "memory_usage", "unit": "percent", "aggregate_function":
285-
"avg", "operator": "gt", "threshold": 90, "dimension_filters": [{"label": "Node
286-
Type", "dimension_label": "node_type", "operator": "eq", "value": "primary"}]}]},
287-
"alert_channels": [{"id": 10000, "label": "Read-Write Channel", "url": "/monitor/alert-channels/10000",
288-
"type": "alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL",
289-
"polling_interval_seconds": 300, "evaluation_period_seconds": 300, "trigger_occurrences":
290-
1}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by":
291-
"tester", "updated_by": "tester", "entities":
292-
{"url": "/monitor/services/dbaas/alert-definitions/11072/entities", "has_more_resources":
262+
"entity", "class": null, "regions": [], "status": "enabled", "severity": 2,
263+
"rule_criteria": {"rules": [{"label": "Memory Usage", "metric": "memory_usage",
264+
"unit": "percent", "aggregate_function": "avg", "operator": "gt", "threshold":
265+
90, "dimension_filters": [{"label": "Node Type", "dimension_label": "node_type",
266+
"operator": "eq", "value": "primary"}]}]}, "alert_channels": [{"id": 10000,
267+
"label": "Read-Write Channel", "url": "/monitor/alert-channels/10000", "type":
268+
"alert-channels"}], "trigger_conditions": {"criteria_condition": "ALL", "polling_interval_seconds":
269+
300, "evaluation_period_seconds": 300, "trigger_occurrences": 1}, "created":
270+
"2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "created_by": "tester",
271+
"updated_by": "tester", "group_by": ["entity_id"], "entities":
272+
{"url": "/monitor/services/dbaas/alert-definitions/11230/entities", "has_more_resources":
293273
false, "count": 0}}'
294274
headers:
295275
Access-Control-Allow-Credentials:
@@ -313,7 +293,7 @@ interactions:
313293
Content-Type:
314294
- application/json
315295
Expires:
316-
- Mon, 27 Apr 2026 12:32:36 GMT
296+
- Thu, 04 Jun 2026 10:41:35 GMT
317297
Pragma:
318298
- no-cache
319299
Strict-Transport-Security:
@@ -350,7 +330,7 @@ interactions:
350330
- application/json
351331
User-Agent:
352332
- linodego/dev https://github.com/linode/linodego
353-
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions/11072
333+
url: https://api.linode.com/v4beta/monitor/services/dbaas/alert-definitions/11230
354334
method: DELETE
355335
response:
356336
body: '{}'
@@ -378,7 +358,7 @@ interactions:
378358
Content-Type:
379359
- application/json
380360
Expires:
381-
- Mon, 27 Apr 2026 12:32:37 GMT
361+
- Thu, 04 Jun 2026 10:41:36 GMT
382362
Pragma:
383363
- no-cache
384364
Strict-Transport-Security:

0 commit comments

Comments
 (0)