Creating a Policy
Function
This API is used to create a policy.
- The value must be 1 to 64 characters starting with a letter. Only digits, letters, underscores (_), and hyphens (-) are allowed.
- In an AS group, for the same metric (metric_name), the value of metric_threshold with metric_operation set to > must be greater than that with metric_operation set to <.
- In an AS group, the metric_operation for a metric must be unique.
- In a policy, the logic of conditions of metrics with the same metric_name cannot conflict.
- The year in the trigger time (launch_time) of a scheduled policy cannot be later than 2099.
- The year in the start time (start_time) and end time (end_time) of a periodic policy cannot be later than 2099.
- An AS group supports a maximum of 10 scheduled and periodic policies, and 10 alarm policies.
- In an AS group, alarm policies cannot affect each other.
URI
POST /v1/{project_id}/pe/policy
Request
Request headers
Table 1 describes the request headers.
Parameter |
Description |
Mandatory |
Example |
---|---|---|---|
Deployment-Name |
Application name. |
Yes |
- |
Content-Type |
Content type, which is application/json;charset=utf-8. |
Yes |
application/json;charset=utf-8 |
Cluster-Id |
Cluster ID. |
Yes |
- |
Namespace |
Namespace. |
Yes |
- |
X-Auth-Token |
User token obtained from IAM. |
Yes |
- |
Reserved-Info |
Custom parameter of the product. |
No |
- |
Request parameters
Table 2 describes the request parameters.
Parameter |
Mandatory |
Type |
Value Range |
Description |
---|---|---|---|---|
name |
Yes |
String |
The value must be 1 to 64 characters starting with a letter. Only digits, letters, underscores (_), and hyphens (-) are allowed. |
Policy name. |
policy_type |
Yes |
String |
|
Policy type. |
rule |
Yes |
See Table 3. |
- |
Policy trigger rule. |
Parameter |
Mandatory |
Type |
Value Range |
Description |
---|---|---|---|---|
conditions |
Yes |
See Table 4. |
Only one condition is allowed. |
Condition contents. When multiple alarm policies are used, their conditions cannot overlap. Example: You cannot set a metric greater than 10% in one condition and smaller than 20% in another condition. |
actions |
Yes |
See Table 5. |
Only one action is allowed. |
Action executed after a specified policy is successfully matched. |
Parameter |
Mandatory |
Type |
Value Range |
Description |
---|---|---|---|---|
launch_time |
Yes |
String |
- |
Trigger time, which must comply with ISO 8601 or UTC specifications.
|
recurrence_type |
Yes |
String |
Value: Daily, Weekly, or Monthly.
|
Trigger period. |
recurrence_value |
Yes |
String |
|
Number of tasks executed when a periodic policy is triggered. |
start_time |
Yes |
String |
- |
Time when periodic policy execution starts, which must comply with ISO 8601 or UTC specifications. Format: YYYY-MM-DDThh:mmZ. |
end_time |
Yes |
String |
- |
Time when periodic policy execution stops, which must comply with ISO 8601 or UTC specifications. Format: YYYY-MM-DDThh:mmZ. |
metric_namespace |
Yes |
String |
|
Namespace. |
metric_name |
Yes |
String |
The value must be 1 to 255 characters long and meet the [a-zA-Z_:][a-zA-Z0-9_:]* expression. That is, the value must start with a letter, underscore (_), or colon (:). Only letters, digits, underscores, and colons are allowed. |
Metric name. |
metric_unit |
Yes |
String |
- |
Unit. |
period |
Yes |
Integer |
20, 60, 300, 900, 1800, or 3600 |
Statistical period (unit: s). |
evaluation_periods |
Yes |
Integer |
1, 2, 3, 4, or 5 |
Number of consecutive periods. |
statistic |
Yes |
String |
Currently, only average is supported. |
Statistic. |
metric_operation |
Yes |
String |
> and <. For example, you can use > in a threshold criterion (when the value of a metric is greater than metric_thresholdUpdate) to trigger actions. |
Metric operator. |
metric_threshold |
Yes |
Float |
[0, 2147483647] |
Threshold criterion. |
"conditions": [{ "metric_namespace" : "PAAS.CONTAINER", "metric_name" : "cpuUsage", "metric_unit" : "Percent", "period" : 300, "evaluation_periods" : 2, "statistic" : "average", "metric_operation" : ">", "metric_threshold" : 70 }]
For cpuUsage (metric_name) in PAAS.CONTAINER (metric_namespace), when its average value (statistic) exceeds 70% (metric_threshold) for two (evaluation_periods) consecutive periods (with a duration of 300s), the policy is triggered.
Parameter |
Mandatory |
Type |
Value Range |
Description |
---|---|---|---|---|
type |
Yes |
String |
|
NOTE:
The value containing k8s indicates a container application and that containing vm indicates a process application. |
parameters |
Yes |
See Table 6. |
- |
Number of scale-in or -out instances. |
Parameter |
Mandatory |
Type |
Value Range |
Description |
---|---|---|---|---|
scale_unit |
Yes |
Integer |
Minimum number of instances to the maximum number of instances in a policy group. |
Number of scale-in or -out instances. |
Example request
- Example of a scheduled policy
{ "name" : "policy1", "policy_type" : "SCHEDULED", "rule" : { "conditions" : [{ "launch_time" : "2017-03-04T03:37Z", "recurrence_type" : null, "recurrence_value" : null, "start_time" : null, "end_time" : null } ], "actions" : [{ "type" : "scale_set_k8s", "parameters" : { "scale_unit" : 1 } } ] } }
- Example of a periodic policy
{ "name" : "policy_2", "policy_type" : "RECURRENCE", "rule" : { "conditions" : [{ "launch_time" : "13:45", "recurrence_type" : "Weekly", "recurrence_value" : "0,1,4", "start_time" : "2017-01-26T03:33Z", "end_time" : "2099-01-31T03:33Z" } ], "actions" : [{ "type" : "scale_set_k8s", "parameters" : { "scale_unit" : 1 } } ] } }
- Example of an alarm policy
{ "name" : "policy_1", "policy_type" : "ALARM", "rule" : { "conditions" : [{ "metric_namespace" : "PAAS.CONTAINER", "metric_name" : "cpuUsage", "metric_unit" : "Percent", "period" : 60, "evaluation_periods" : 1, "statistic" : "average", "metric_operation" : ">", "metric_threshold" : 70 } ], "actions" : [{ "type" : "scale_out_k8s", "parameters" : { "scale_unit" : 1 } } ] } }
Response
Response parameters
Table 7 describes the response parameters.
Parameter |
Type |
Description |
---|---|---|
errorCode |
String |
Error code. |
errorMessage |
String |
Error details. |
policy_id |
String |
Policy ID. |
Example response
{ "errorCode": 0, "errorMessage": "", "policy_id": "1b9994f0-847a-45e4-aeee-e8b604dddb34" }
Error Code
Error Code |
Message |
Solution |
---|---|---|
SVCSTG.PE.4001101 |
Invalid parameter. |
Check whether the parameter meets requirements. |
SVCSTG.PE.4031012 |
Failed to verify the project ID. |
Check whether the parameter meets requirements. |
SVCSTG.PE.5001201 |
Failed to insert or update data in the background. |
Contact technical support. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.